SQL - Oracle函数使用模式名称的变量

Ban*_*Orc 1 sql oracle plsql

我正在编写一些oracle存储过程,其中我们有条件逻辑,它影响我们正在使用哪个模式,我不知道如何在sql中为存储过程执行此操作.如果我正在使用预处理语句,那么它很好,但在我只是执行查询以填充另一个变量的情况下,我不知道如何做到这一点.例如

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;
Run Code Online (Sandbox Code Playgroud)

谁能照亮我在这里失踪的东西.
干杯

sch*_*rik 5

你也可以使用execute immediate for select statment:

    execute immediate    'select count(*)  from '|| customer_schema 
                      || '.customer_registration where customer_ref= :b1' 
     into record_exists using incustomer_ref;
Run Code Online (Sandbox Code Playgroud)