title: SQL - Oracle Functions using variables for schema names
body: <p>I am writing some oracle stored procedures where we have conditional logic which effects which schema we are working from and I am not sure how to do this in the sql for the stored proc.  If I am working with prepared statements then its fine but in the scenario where I am just executing a query to say populate another variable then I dont know how to do this.  For example</p>
  
  <pre><code>PROCEDURE register (
      incustomer_ref  in  VARCHAR2,
      incustomer_type in  VARCHAR2,
      outreturn_code  out VARCHAR2
  )
  IS
      customer_schema varchar2(30);
           record_exists number(1);
  BEGIN
      if incustomer_type='a' then
          customer_schema:='schemaA';
      elsif incustomer_type='b' then
          customer_schema:='schemaB';
      end if;
  
  
      --This type of command I cant get to work
      select count(*) into record_exists from **customer_schema**.customer_registration where customer_ref=incustomer_ref
  
      --but a  statement like this i know how to do
      if record_exists = 0 then
          execute immediate 'insert into '||customer_schema||'.customer_registration   
          values ('||incustomer_ref||','Y',sysdate)';
      end if;
  </code></pre>
  
  <p>Can anyone shine some light on what I am missing here.<br>
  Cheers</p>