我有一个存储过程,我需要在两个模式名称之间“切换”。这是一个例子:
宣布 schema1 varchar2(16):=‘left’; schema2 varchar2(16):=‘right’;开始 如果(有些……
如果你想使用变量进行模式引用,你将不得不使用动态sql,这将是这样的:
declare schema1 varchar2(16) := 'left'; schema2 varchar2(16) := 'right'; myVar varchar2(100); begin if (some condition) then execute immediate 'select * from ' || schema1 || '.tbl1 where id = 1' into myVar; else execute immediate 'select * from ' || schema2 || '.tbl1 where id = 1' into myVar; end if; end;