Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: ODTUG-DEV2K-L Digest -- Volume 2001, Number 301
Consider using OPEN FOR stmt.
E.g.:
declare
strcode varchar2(200) := '(10, 20)';
l_deptno number;
l_ename varchar2(200);
type ref_emp is ref cursor;
c_emp ref_emp;
begin
open c_emp for
'select deptno, ename
from amemp
where deptno in ' || strcode;
loop
fetch c_emp into l_deptno, l_ename;
exit when c_emp%notfound;
dbms_output.put_line(l_deptno || '/' || l_ename);
end loop;
close c_emp;
end;
rgds
amar
-----Original Message-----
From: Raymond Lee Meng Hong [mailto:RAYMOND_at_infopro.com.my]
Sent: Monday, October 29, 2001 5:40 AM
To: Multiple recipients of list ORACLE-L
Subject: FW: ODTUG-DEV2K-L Digest -- Volume 2001, Number 301
If you want to try dynamic sql..
here is some of my advice...you form
ASSIGN THIS STATEMENT A VARCHAR2 STRING VARIABLE
'SELECT EMPNO FROM EMP WHERE TO_CHAR(DEPTNO) IN '||'('||STRCODE||')';
Then it will work..as a concatenation method instead of bind method.
try and see.
From: Abdul Karim Khan <abdul.karim_at_almarai.com>
Date: Sat, 27 Oct 2001 16:21:36 +0300
Subject: how to set cursor parameter
Hi
Guru I am passing value dynamically to cursor , but it gives error .
Example:
DECLARE
STRCODE VARCHAR2(1000) :='10,20'; -- this value assign dynamically by
function which returns in string.
A1 NUMBER;
Cursor c1 is select empno from emp
Where to_char(deptno) in (strcode);
BEGIN
Open c1;
Loop
Fetch c1 into a1 ;
Insert into a (no) values(a1);
If c1%notfound then
exit;
End if;
End loop;
Close c1;
END;
But it is working well when apply only one value
Example STRCODE VARCHAR2(1000) :='10'; -- this value assign dynamic
A1 NUMBER;
Cursor c1 is select empno from emp
Where to_char(deptno) in (strcode);
BEGIN
Open c1;
Loop
Fetch c1 into a1 ;
Insert into a (no) values(a1);
If c1%notfound then
exit;
End if;
End loop;
Close c1;
END;
Any help is highly appreciated.
Thanks in advanced
karim
-- Please see the official ORACLE-L FAQ: http://www.orafaq.com -- Author: Raymond Lee Meng HongReceived on Sun Oct 28 2001 - 22:18:00 CST
INET: RAYMOND_at_infopro.com.my
Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 San Diego, California -- Public Internet access / Mailing Lists -------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).
![]() |
![]() |