Re: Pro*C question

From: Thomas J. Kyte <tkyte_at_us.oracle.com>
Date: 1996/09/11
Message-ID: <32360b3f.1542467_at_dcsun4>#1/1


	sprintf( sqlstmt.arr, "begin %s; end;" );
        sqlstmt.len = strlen( sqlstmt.arr );
	
	EXEC SQL PREPARE S FROM :sqlstmt;
        EXEC SQL DECLARE C CURSOR FOR S;
        EXEC SQL OPEN C;

or, if you have bind variables:

	sprintf( sqlstmt.arr, "begin %s( :x1, :x2 ); end;" );
        sqlstmt.len = strlen( sqlstmt.arr );
	
	EXEC SQL PREPARE S FROM :sqlstmt;
        EXEC SQL DECLARE C CURSOR FOR S;
        EXEC SQL OPEN C USING :x1:x1_i, :x2:x2_i;

If you are going to re-execute the statement over and over, you can:

	sprintf( sqlstmt.arr, "begin %s( :x1 ); end;" );
        sqlstmt.len = strlen( sqlstmt.arr );
	
	EXEC SQL PREPARE S FROM :sqlstmt;
        EXEC SQL DECLARE C CURSOR FOR S;
  
        for( x1 = 0; x1 < 10; x1++ )
	{
        	EXEC SQL OPEN C USING :x1;
 	}



 

On Tue, 10 Sep 1996 19:25:07 GMT, Narasimha Kasibhatla <narasimha.kasibhatla_at_daytonoh.ncr.com> wrote:

>Problem:
>
> Want to call a stored procedure dynamically from Pro*C.
>
> Scenario:
>
> We have a set of stored procedure in the database called say proc1,
> proc2 etc (note names may not be known at compile time).
>
> Normally within Pro*C you would use
>
> EXEC SQL BEGIN EXECUTE
> BEGIN proc1 (.. args ..)
> END;
> END EXEC;
>
> to execute a procedure.
>
> But we want to call different procedures in Oracle based on what is
> happening in the C program. The names of the procedures would be
> determined at run-time. Therefore, we are looking for some way to
> dynamically prepare a statement that calls a stored procedure and
> execute it.
>
> Any pointers would be appreciated.
>
> Please e-mail to hvattyam_at_one.net.
>
> Thanks
>
> Hari Vattyam

Thomas Kyte
Oracle Government
tkyte_at_us.oracle.com                          

http://govt.us.oracle.com

  • Check out Oracle Governments web site! ----- Follow the link to "Tech Center" and then downloadable Utilities for some free software...

statements and opinions are mine and do not necessarily reflect the opinions of Oracle Corporation Received on Wed Sep 11 1996 - 00:00:00 CEST

Original text of this message