我正在编写一些 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;
任何人都可以对我在这里缺少的东西有所了解。
干杯