Home » SQL & PL/SQL » SQL & PL/SQL » Using DBMS_SQL to call dynamically Stored Procedure in Oracle 7
Using DBMS_SQL to call dynamically Stored Procedure in Oracle 7 [message #40040] Thu, 05 September 2002 03:53 Go to next message
Sofianito
Messages: 2
Registered: September 2002
Junior Member
Hi,

Is it possible to use the package DBMS_SQL to call dynamically STORED PROCEDURES? I got an exception in the DBMS_SQL.PARSE method when I execute the following in TOAD:

declare
sqlstr VARCHAR2(100);
cid INTEGER;

procedure myproc( value CHAR )
is
begin
dbms_output.put_line( ' Inside Out, boy u turn me !! - ' || value );
end myproc;

begin
cid := DBMS_SQL.OPEN_CURSOR;
sqlstr := 'myproc( :v )';
DBMS_SQL.PARSE( cid, sql_str, dbms_sql.v7 );
DBMS_SQL.BIND_VARIABLE_CHAR( cid, 'v', 'Hello World!' );
DBMS_SQL.EXECUTE( cid );
DBMS_SQL.CLOSE_CURSOR( cid );
end;

Any Idea?

By the way i'm using Oracle 7.3.3

Thanks
Re: Using DBMS_SQL to call dynamically Stored Procedure in Oracle 7 [message #40047 is a reply to message #40040] Thu, 05 September 2002 09:46 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
1) The procedure needs to be an actual 'stored' procedure (not just defined in the block);
2) Your sqlstr reference in the block was as sql_str.
3) The call to the procedure must be wrapped with a begin/end.
4) The execute has a return value.

sql>create or replace procedure myproc(p_value  in  varchar2)
  2  is 
  3  begin 
  4    dbms_output.put_line( 'Value: ' || p_value ); 
  5  end;
  6  /
 
Procedure created.
 
sql>declare 
  2    sqlstr  varchar2(100); 
  3    cid     pls_integer;
  4    r       pls_integer; 
  5  begin 
  6    cid := dbms_sql.open_cursor; 
  7    sqlstr := 'begin myproc(:v); end;'; 
  8    dbms_sql.parse(cid, sqlstr, dbms_sql.v7); 
  9    dbms_sql.bind_variable_char(cid, 'v', 'Hello World!');
 10    r := dbms_sql.execute(cid); 
 11    dbms_sql.close_cursor(cid); 
 12  end; 
 13  /
 
Value: Hello World!
 
PL/SQL procedure successfully completed.
Re: Using DBMS_SQL to call dynamically Stored Procedure in Oracle 7 [message #40137 is a reply to message #40047] Wed, 11 September 2002 04:32 Go to previous message
Sofianito
Messages: 2
Registered: September 2002
Junior Member
u're right, I forgot to put the call in an anonymous block... ;)

thanks

Sofianito
Previous Topic: Stumped on error defining function
Next Topic: How to delete a column from a table
Goto Forum:
  


Current Time: Thu May 02 13:41:15 CDT 2024