Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: Dynamic SQL
To summarise and clarify previous advice, here's how to make the anonymous block work. I've changed the table and column names to work with tables in the HR schema that comes with SQL*Developer (or was it JDeveloper...) but you can easily change it to fit your requirements once you've understood the concepts
Regards Nigel
DECLARE
m_output VARCHAR2(4000);
TYPE curtype IS REF CURSOR;
m_cursor curtype;
BEGIN
FOR r IN
(SELECT owner
FROM all_tables WHERE TABLE_NAME = UPPER('JOBS') ORDER BY owner)
OPEN m_cursor FOR
'SELECT JOB_ID||'':''||JOB_TITLE||'':''||MAX_SALARY FROM ' || r.owner || '.JOBS where min_salary = 4000'; LOOP
FETCH m_cursor INTO m_output; EXIT WHEN m_cursor % NOTFOUND; -- dbms_output.put_line takes a single parameter DBMS_OUTPUT.PUT_LINE(m_output);
anonymous block completed
Start:
Owner = HR
IT_PROG:Programmer:10000 MK_REP:Marketing Representative:9000 HR_REP:Human Resources Representative:9000
-- http://www.freelists.org/webpage/oracle-lReceived on Thu Apr 06 2006 - 13:52:03 CDT
![]() |
![]() |