Pass SQL string to oracle stored procedure and get results with execute immediate -


i trying pass in sql string stored procedure , using execute immediate return results. this:

create procedure p360_rct_count (sqlstring in varchar2) begin    execute immediate sqlstring; end; / 

i not sure how accomplish it. above, when execute sp using command below, error:

execute p360_rct_count 'select count(distinct entity_id),addr_county p360_v_rct_count group addr_county'; 

the error is: ora-06550: line 1, column 22:

pls-00103: encountered symbol "select count(entity_id),addr_county p360_v_rct_count group " when expecting 1 of following:

:= . ( @ % ; symbol ":=" substituted "select count(distinct entity_id),addr_county p360_v_rct_count group " continue.

basically building sql string in system , need pass in sp , results system. relatively new stored procedures in oracle.

the easiest way work result set sys_refcursor. can used quite jdbc or odbc.

your procedure this:

create procedure p360_rct_count (        sqlstring in varchar2        , p_result_set out sys_refcursor) begin    open p_result_set sqlstring; end; /  

obviously precise details of how call vary according client. in sql*plus be:

var rc refcursor exec p360_rct_count( 'select count(distinct entity_id),addr_county p360_v_rct_count group addr_county', :rc); print rc 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -