Package my_pkg
-----------------------
CREATE OR REPLACE PACKAGE my_pkg AS
PROCEDURE p;
END my_pkg;
CREATE OR REPLACE PACKAGE BODY my_pkg AS
PROCEDURE p IS
l_data NUMBER;
l_other_data NUMBER;
PROCEDURE p_inner(p_data IN OUT NUMBER) IS
BEGIN
l_data := l_data + 1;
p_data := p_data / 2;
END;
BEGIN
l_data := 42;
l_other_data := 84;
p_inner(l_other_data);
dbms_output.put_line('l_data = ' ||
l_data || ', l_other_data = ' ||
l_other_data);
END;
END my_pkg;
BEGIN
-- call the procedure
my_pkg.p;
END;
Output
------------
l_data = 43, l_other_data = 42
Procedure mytable
-----------------------
CREATE OR REPLACE PROCEDURE
mytable(ptable_name IN VARCHAR2,
pemp_name IN VARCHAR2,
pemp_age IN NUMBER) IS
PROCEDURE myvalues(pemp_name IN VARCHAR2, pemp_age IN NUMBER) IS
BEGIN
EXECUTE IMMEDIATE 'insert into ' ||
ptable_name ||
' values(:emp_name, :emp_age)'
USING pemp_name,
pemp_age;
dbms_output.put_line('Data Inserted');
END;
BEGIN
EXECUTE IMMEDIATE 'create table ' ||
ptable_name ||
' (sname varchar2(20), sage number(4))';
dbms_output.put_line('Table Ptable_name created');
myvalues(pemp_name, pemp_age);
END;
BEGIN
-- Call the procedure
mytable(ptable_name =>
:ptable_name,
pemp_name => :pemp_name,
pemp_age => :pemp_age);
END;
Output
------------------
Table Ptable_name created
Data Inserted
Procedure mytable1
-----------------------
CREATE OR REPLACE PROCEDURE mytable1 IS
PROCEDURE myvalues IS
BEGIN
dbms_output.put_line('Inside');
END;
BEGIN
myvalues;
dbms_output.put_line('Outside');
EXECUTE IMMEDIATE 'create or replace procedure mytable2 is
begin
dbms_output.put_line(' || '''' ||
'procedure mytable2 is created and called' || '''' || ');
end;';
dbms_output.put_line('procedure mytable2 is created');
--mytable2;
END;
begin
-- Call the procedure
mytable1;
end;
Output
------------------
Inside
Outside
procedure mytable2 is created
I hope you all have enjoyed reading this article. Comments are welcome....
No comments:
Post a Comment