how to pass a dyanmic table name to a select statement for declaring a cursor in stored procedure.can any one help
.please if possible give a example
thanks darshu
here is an example (slightly modifed) from the Oracle Applications Developer's Guide:
DECLARE
TYPE EmpCurTyp IS REF CURSOR;
cur EmpCurTyp;
stmt_str VARCHAR2(200);
name VARCHAR2(20);
salary NUMBER;
table VARCHAR2 (30);
BEGIN
table := 'emp';
stmt_str := 'SELECT ename, sal FROM ' || table ||
' WHERE job = :1';
OPEN cur FOR stmt_str USING 'SALESMAN';
LOOP
FETCH cur INTO name, salary;
EXIT WHEN cur%NOTFOUND;
-- <process data>
END LOOP;
CLOSE cur;
END;
/
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.