1. Execute Immediate:
Example 1:
create or replace procedure xxhrs_local_sql
as
l_select varchar2(200);
begin
--for c1 in 1..10
--loop
l_select :=
'DECLARE '||
'L_NAME VARCHAR2(50); '||
'BEGIN '||
'select ENAME INTO L_NAME'||
' from'||' emp '|| 'where ename '||'like '||'''KING%'''||'; '
||'DBMS_OUTPUT.PUT_LINE(L_NAME); '||
'END;' ;
--DBMS_OUTPUT.PUT_LINE(l_select);
EXECUTE IMMEDIATE l_select;
--end loop;
end;
Example 2:
CREATE OR REPLACE PROCEDURE xxhrrs IS
CURSOR c1 IS
SELECT table_name
FROM user_tables
WHERE table_name in ('DEPT');
--
c1rec c1%ROWTYPE;
--
l_sql VARCHAR2(1000);
BEGIN
FOR r1 IN c1 LOOP
l_sql := 'DECLARE '||
' CURSOR c1 IS '||
' SELECT DEPTNO '||
' FROM '||r1.table_name||'; '||
' c1rec c1%ROWTYPE; '||
'BEGIN '||
' FOR r1 IN c1 LOOP '||
' dbms_output.put_line(''code here...DEPTNO''||r1.deptno); '||
' END LOOP; '||
'END; ';
--
-- DBMS_OUTPUT.PUT_LINE(L_SQL);
EXECUTE IMMEDIATE l_sql;
END LOOP;
END;
Compile the above mentioned Procedures.
Execute Process :
Example 1: exec xxhrrs;
Example 2: exec xxhrs_local_sql;
No comments:
Post a Comment