Passing parameter to a SQLPLUS script [message #636201] |
Sun, 19 April 2015 13:10 |
|
Asfakul
Messages: 43 Registered: July 2014
|
Member |
|
|
Hi all, My requirement is this.
I have two table. Product and Entity. I will call a sqlplus script like <@myscript product > and pass the table name. it will print the content of the table. Simple. I have made one Function which gives a Ref cursor as output.
Code as below.
CREATE OR REPLACE FUNCTION get_detail(p_table IN VARCHAR2,p_out out sys_refcursor)
RETURN boolean
AS
l_table VARCHAR2(20);
BEGIN
l_table:=p_table;
IF l_table ='product' THEN
OPEN p_out FOR
SELECT * FROM product;
elsif l_table ='entity' THEN
OPEN p_out FOR
SELECT * FROM entity;
END IF;
RETURN TRUE;
exception
WHEN others THEN
RETURN FALSE;
raise_application_error(-20001,substr(sqlerrm,1,100));
END;
SQLPLUS script :-
set serveroutput on
set echo off
set feedback off
variable var1 varchar2(20);
DECLARE
o_cursor sys_refcursor;
L_productrow product%ROWTYPE;
L_entityrow entity%ROWTYPE;
begin
:var1:=&1;
if :var1 = 'product' then
if get_detail('product',o_cursor) then
loop
fetch o_cursor into L_productrow;
exit when o_cursor%notfound;
dbms_output.put_line(L_productrow.product_id||','||L_productrow.CreateDate);
end loop;
end if;
elsif :var1='entity' then
if get_detail('entity',o_cursor) then
loop
fetch o_cursor into L_entityrow;
exit when o_cursor%notfound;
dbms_output.put_line(L_entityrow.entity_id||','||L_entityrow.CreateDate);
end loop;
end if;
end if;
exception
when others then
dbms_output.put_line(dbms_utility.format_error_backtrace);
dbms_output.put_line(sqlerrm);
end;
/
I am getting the error :
ORA-06550: line 7, column 12:
PLS-00357: Table,View Or Sequence reference 'PRODUCT' not allowed in this
context
ORA-06550: line 7, column 4:
PL/SQL: Statement ignored
I am not able to understand what I am doing wrong.
|
|
|
|
|
|
|
|