Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL-使用模式名称变量的Oracle函数_Sql_Oracle_Plsql - Fatal编程技术网

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

SQL-使用模式名称变量的Oracle函数,sql,oracle,plsql,Sql,Oracle,Plsql,我正在编写一些oracle存储过程,其中的条件逻辑会影响我们使用的模式,我不知道如何在存储过程的sql中实现这一点。如果我使用准备好的语句,那么这很好,但是在我只是执行一个查询来填充另一个变量的情况下,我不知道如何做。比如说 PROCEDURE register ( incustomer_ref in VARCHAR2, incustomer_type in VARCHAR2, outreturn_code out VARCHAR2 ) IS custom

我正在编写一些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;
谁能帮我解释一下我在这里错过了什么。

干杯

您也可以使用execute immediate来选择状态:

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

您也可以将execute immediate用于选择状态:

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

+1-不知道使用
executeimmediate
子句将
转换为
。谢谢我也不知道你能做到。感谢您的帮助。+1-不知道使用
executeimmediate
子句将
转换为
。谢谢我也不知道你能做到。谢谢你的帮助。