在pl / sql中,我可以使用in
关键字和一组字符串:
select * from languages where language_tag in ('en','fr','es')
如何在脚本的('en','fr','es')
部分中定义DECLARE
的集合并再次使用它?
- 编辑:
一个非常讨厌的方法(这是我目前的方法!)是在声明部分中将项目定义为csv字符串并使用execute_immediate
:
DECLARE
v_csv_tags VARCHAR2(123) :='''en'',''es''';
BEGIN
execute immediate 'delete from config_supports_language where language_code not in ('||v_csv_tags||')';
execute immediate 'delete from languages where language_code not in ('||v_csv_tags||')';
END;
/
EXIT;
答案 0 :(得分:1)
您可以创建嵌套表或varray SQL类型(作为架构对象),然后在PL / SQL存储过程或匿名PL / SQL块中使用它,如下所示:
SQL类型
create type T_List as table of varchar2(123);
/
Type created
PL / SQ块:
declare
l_list T_List3 := T_List3('en','fr','es'); -- the l_list also can be initialized
begin -- in the BEGIN..END section
select <<columns list>>
into <<variables>>
from languages
where language_tag in (select column_values -- you can query table(l_list)
from table(l_list)) -- as many times as you like
exception
when no_data_found
then dbms_output.put_line('No data is found');
end;