我正在编写一些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;
任何人都可以对我在这里失踪的东西有所启发 干杯
答案 0 :(得分:5)
你也可以使用execute immediate for select语句:
execute immediate 'select count(*) from '|| customer_schema
|| '.customer_registration where customer_ref= :b1'
into record_exists using incustomer_ref;