Dynamic cursor

Dúvidas, dicas e truques de PL/SQL. Aqui também vão assuntos relacionados a pacotes, triggers, funções, Java-Stored Procedures, etc
Post Reply
alexsbraga
Rank: Estagiário Júnior
Rank: Estagiário Júnior
Posts: 1
Joined: Wed, 29 Aug 2012 11:44 am

Personal,

I have the following doubt / problem: I have two declared cursors C_SALDO1 and C_SALDO_2, but I will only use 1, depending on a particular parameter that my procedure will receive. I want to work with the cursor to be used implicitly, using for loop.
I tried to create a cursor stating as follows:

Select all

TYPE CursorLoop IS REF CURSOR
then assign to this cursorloop the C_SALDO1 or C_SALDO2 cursor, but it is not working.
Someone can give me a tip of how I can be doing this.
davidmeloboy
Rank: Programador Sênior
Rank: Programador Sênior
Posts: 54
Joined: Fri, 05 Sep 2008 1:53 pm
Location: Parobé - RS
Contact:
David.

If the two cursors bring the same columns, to make a cursor just and join the two queys with a Union.
and restrict the querys to run depending on what returns to your procedure.
Depending on the value, you only perform the query from UNION, or just the query below Union.
User avatar
fsitja
Rank: OraSauro
Rank: OraSauro
Posts: 611
Joined: Mon, 19 Jan 2009 4:29 pm
Location: Gaúcho no Rio de Janeiro - RJ
"The scars exist to remind us that the past was real"
Campanha: Como fazer uma pergunta e obter uma resposta.
http://tkyte.blogspot.com/2005/06/how-t ... tions.html

OCA & OCP Developer — OCE SQL Expert — OCS Data Warehousing Specialist

No source code to analyze, and the complete error message, there is no way to help ... It's like the famous question: "My car does not start, as a repair?" : D
LordElfo
Rank: Analista Pleno
Rank: Analista Pleno
Posts: 111
Joined: Thu, 22 Feb 2007 2:34 pm
Location: DF
________________
http://lordelfo.blogspot.com
Thiago Façanha

You can try something like to declare a variable varchar2 for example acao_sql the name.

Select all

   TYPE r_cursor IS REF CURSOR; 
    c_cursor          r_cursor; 
   sql_string               VARCHAR2 (10000);
Ai According to what you need you pass a string with the query for this variable

Select all

/*Condicao01*/ 
acao_sql := "select 1 from dual"; 
/*Condicao02*/ 
acao_sql := "select 2 from dual";
and then
opens the cursor you created.

Select all

 OPEN c_cursor_acao FOR acao_sql;
Does that help you?

vlw
LordElfo
Rank: Analista Pleno
Rank: Analista Pleno
Posts: 111
Joined: Thu, 22 Feb 2007 2:34 pm
Location: DF
________________
http://lordelfo.blogspot.com
Thiago Façanha

Correction ..
where it has acao_sql exchange by sql_string . It was to be the same variable.
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 3 guests