Autor Tema: Duda Sobre Query Dinamico  (Leído 3763 veces)

0 Usuarios y 3 Visitantes están viendo este tema.

alexandervalladares

  • Visitante
Duda Sobre Query Dinamico
« : abril 09, 2009, 08:15:32 pm »
SET SERVEROUTPUT ON;
DECLARE
    TYPE EMPLOYEES_C IS REF CURSOR;
    CURSOREMPLOYEES EMPLOYEES_C; 
    --RECORDEMPLOYEES CURSOREMPLOYEES%ROWTYPE;
    V_FIRST_NAME VARCHAR2(30);         
BEGIN
   OPEN CURSOREMPLOYEES FOR 'SELECT FIRST_NAME FROM EMPLOYEES WHERE EMPLOYEE_ID IN :PARAMETRO1' USING '100'||','||'101';
    LOOP
        FETCH CURSOREMPLOYEES INTO V_FIRST_NAME;
        EXIT  WHEN CURSOREMPLOYEES%NOTFOUND OR CURSOREMPLOYEES%NOTFOUND IS NULL;
        DBMS_OUTPUT.PUT_LINE(V_FIRST_NAME);
    END LOOP;       
END;

quisiera que me indicaran por que me da una excepcion ORA-00922: falta la opción o no es válida, no se que tengo de malo, si al final entiendo que le paso in(100,101);

Desconectado Camus de Acuario

  • The Communiter-
  • *
  • Mensajes: 8455
  • Ōrora Ekusukyūshon!
Re: Duda Sobre Query Dinamico
« Respuesta #1 : abril 09, 2009, 10:40:35 pm »
pues lo unico malo que veo es cuando creas el cursor, al darle for en lugar de colocar '', mete el select en ( ), tambien el IN, ahora lo de using no estoy muy seguro pero yo nunca lo he oido y menos ocupado, si queres ocupar 100 y 101 en el IN, solamente queda asi:

ademas, cuando pongas codigo, ponelo enmedio de estos tag:
[ code]sin el espacio[ /code] para que se te vea asi:

Código: [Seleccionar]
SET SERVEROUTPUT ON;
DECLARE
    TYPE EMPLOYEES_C IS REF CURSOR;
    CURSOREMPLOYEES EMPLOYEES_C;
    --RECORDEMPLOYEES CURSOREMPLOYEES%ROWTYPE;
    V_FIRST_NAME VARCHAR2(30);         
BEGIN
   OPEN CURSOREMPLOYEES FOR (SELECT FIRST_NAME FROM EMPLOYEES WHERE EMPLOYEE_ID IN (100,101))
    LOOP
        FETCH CURSOREMPLOYEES INTO V_FIRST_NAME;
        EXIT  WHEN CURSOREMPLOYEES%NOTFOUND OR CURSOREMPLOYEES%NOTFOUND IS NULL;
        DBMS_OUTPUT.PUT_LINE(V_FIRST_NAME);
    END LOOP;       
END;