Skip to content

Instantly share code, notes, and snippets.

@hackvan
Created July 22, 2016 17:30
Show Gist options
  • Save hackvan/39f382c1c965edd9b9957356c42239b2 to your computer and use it in GitHub Desktop.
Save hackvan/39f382c1c965edd9b9957356c42239b2 to your computer and use it in GitHub Desktop.
PL/SQL Oracle: Ejemplo de ciclos con consultas dinamicas
Declare
Type type_cursor Is Ref Cursor;
cu_query type_cursor;
lc_query Varchar2(500);
lc_codindic SFPS020T.codindic%Type;
lc_valindic SFPS020T.valindic%Type;
lc_desindic SFPS020T.desindic%Type;
Begin
lc_query := 'Select codindic, valindic, desindic';
lc_query := lc_query||' From SFPS020T';
lc_query := lc_query||' Where codindic = ''CATEPROY''';
Open cu_query For lc_query;
Loop
lc_codindic := Null;
lc_valindic := Null;
lc_desindic := Null;
Fetch cu_query Into lc_codindic, lc_valindic, lc_desindic;
Exit When cu_query%NotFound;
dbms_output.put_line(lc_codindic||' - '||lc_valindic||' - '||lc_desindic);
End Loop;
End;
@axconsultores
Copy link

Hello.
this part "Fetch cu_query Into lc_codindic, lc_valindic, lc_desindic;", Can I change dinamic?

@hackvan
Copy link
Author

hackvan commented Mar 10, 2021

Hi,
With OPEN and FETCH actually is no posible, for your particular case, you will must to use DBMS_SQL.TO_REFCURSOR.

Example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment