SQL - Oracle Functions using variables for schema names -


i writing oracle stored procedures have conditional logic effects schema working , not sure how in sql stored proc. if working prepared statements fine in scenario executing query populate variable dont know how this. example

procedure register (     incustomer_ref  in  varchar2,     incustomer_type in  varchar2,     outreturn_code  out varchar2 )     customer_schema varchar2(30);          record_exists number(1); begin     if incustomer_type='a'         customer_schema:='schemaa';     elsif incustomer_type='b'         customer_schema:='schemab';     end if;       --this type of command cant work     select count(*) record_exists **customer_schema**.customer_registration customer_ref=incustomer_ref      --but  statement know how     if record_exists = 0         execute immediate 'insert '||customer_schema||'.customer_registration            values ('||incustomer_ref||','y',sysdate)';     end if; 

can shine light on missing here.
cheers

you can use execute immediate select statment:

    execute immediate    'select count(*)  '|| customer_schema                        || '.customer_registration customer_ref= :b1'       record_exists using incustomer_ref; 

Comments