开发者

Problem with dynamic SQL in Oracle

开发者 https://www.devze.com 2023-02-26 11:51 出处:网络
I have a stored procedure create or replaceprocedure GETFILE(TableName in VARCHAR2) is No_Rows Number :=0;

I have a stored procedure

create or replace  procedure GETFILE(TableName in VARCHAR2)
is
No_Rows Number :=0;
state varchar2(100);
begin
state :=' select    count(*)  into   :p_id     fro开发者_Go百科m   ' || inTableName;
EXECUTE IMMEDIATE state using out NO_ROWS;

end;
end;

Stored procedure is getting created successfully. But when i am running it using:

declare
begin
GETFILE('TABLE_NAME');
end;

It showing "ORA-01006: bind variable does not exist" error. Any idea?


Will this work for your requirement ( you may want to remove the put_line )...:

create or replace  procedure GETFILE(inTableName in VARCHAR2)
is
No_Rows Number :=0;
state varchar2(100);
begin
 state :=' select    count(*)   from   ' || inTableName;
dbms_output.put_line(state);
EXECUTE IMMEDIATE state into NO_ROWS;
dbms_output.put_line(no_rows);
end;
/

declare
begin
getfile('dual');
end;
/


I don't think there is any coding error here
so, I think you have to ensure that you are creating and executing your procedure
at the same data base or at the same schema

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号