SQL-使用模式名称变量的Oracle函数
我正在编写一些oracle存储过程,其中的条件逻辑会影响我们使用的模式,我不知道如何在存储过程的sql中实现这一点。如果我使用准备好的语句,那么这很好,但是在我只是执行一个查询来填充另一个变量的情况下,我不知道如何做。比如说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
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
的子句将转换为或。谢谢我也不知道你能做到。谢谢你的帮助。