Home » RDBMS Server » Server Administration » How to execute select query in procedure with table name as parameter
How to execute select query in procedure with table name as parameter [message #371883] Mon, 18 December 2000 05:24 Go to next message
sagar
Messages: 11
Registered: December 2000
Junior Member
How to execute select query in procude with table name as parameter.
This parameterised table name is given in select query
So how to view names from multiple tables by passing table name as parameter to a procedure.
Need urgently!!

Example below gives an error for tabname
e.g-
create or replace procedure TempDisp(tabname in varchar2)
mname varchar2(20);
as
begin
select name into mname from tabname;
end TempDisp;
Re: How to execute select query in procedure ... Me Too. [message #371898 is a reply to message #371883] Mon, 18 December 2000 17:17 Go to previous messageGo to next message
Bob Barry
Messages: 1
Registered: December 2000
Junior Member
Right there with you on that question...
Re: How to execute select query in procedure with table name as parameter--I have got the solution f [message #371902 is a reply to message #371883] Tue, 19 December 2000 01:14 Go to previous message
sagar
Messages: 11
Registered: December 2000
Junior Member
Before any one reply to this questions,I would like to give an answer to this.
I have got the solution for this.
This is the way you should implement dynamic SQL -

create or replace procedure GetPointBal (tabname in varchar2,bal out number)
as
pointbal number(10);
cursor_name integer;
rows_processed integer;
BEGIN
cursor_name := dbms_sql.open_cursor;
DBMS_SQL.PARSE(cursor_name,'select sum(cr_points)-sum(dr_points) into pointbal from :x',dbms_sql.native);
DBMS_SQL.BIND_VARIABLE(cursor_name,':x',tabname);
rows_processed := dbms_sql.execute(cursor_name);
bal := DBMS_SQL.VARIABLE_VALUE;
DBMS_SQL.close_cursor(cursor_name);

EXCEPTION
WHEN OTHERS THEN
DBMS_SQL.CLOSE_CURSOR(cursor_name);
end GetPointBal;
Previous Topic: how to learn sql
Next Topic: Re: Error PLS-00452 - but why?! Can anybody explain this to me?
Goto Forum:
  


Current Time: Sat May 04 06:39:19 CDT 2024