SQL 使用变量集以防万一
SQL Use variable set in case
我想在查询中使用输入变量。
输入变量应该是一个集合。
例如:
这是一个有效的查询:
select * from table_1
where key_1 in ('1', '2', '3')
但是我想用一个输入变量来替换集合
select * from table_1
where key_1 in (:input_set)
然后我将输入设置为::input_set = ('1, 2, 3')
但是我找不到使它工作的方法。
感谢老程序员。
我使用了部分答案来自:Oracle: using IN clause with text field?
select * from table_1
where key_1 in (
when pzgr_id in (
select regexp_substr(str, '[^,]+',1,level)
from (select :input_set str from dual)
connect by level <= regexp_count(str,'[^,]+')
)
使用输入集“1,2,3”。
重要的是不要在 1、2、3 之间使用空格。
我想在查询中使用输入变量。 输入变量应该是一个集合。
例如:
这是一个有效的查询:
select * from table_1
where key_1 in ('1', '2', '3')
但是我想用一个输入变量来替换集合
select * from table_1
where key_1 in (:input_set)
然后我将输入设置为::input_set = ('1, 2, 3')
但是我找不到使它工作的方法。
感谢老程序员。
我使用了部分答案来自:Oracle: using IN clause with text field?
select * from table_1
where key_1 in (
when pzgr_id in (
select regexp_substr(str, '[^,]+',1,level)
from (select :input_set str from dual)
connect by level <= regexp_count(str,'[^,]+')
)
使用输入集“1,2,3”。 重要的是不要在 1、2、3 之间使用空格。