Oracle PL SQL 中使用: 與 & 變數
with qq as (select 'A' col1,1 col2 from dual
union all select 'A' col1,2 col2 from dual
union all select 'B' col1,1 col2 from dual
union all select 'B' col1,2 col2 from dual
union all select 'C' col1,1 col2 from dual
union all select 'C' col1,2 col2 from dual)
select * from qq where col1=:col1
單一變數放 字串A 時 select * from qq where col1=:col1 結果為
COL1,COL2
A,1
A,2
單一變數放數值 2 時 select * from qq where col2=:col2 結果為
COL1,COL2
A,2
B,2
C,2
當變數字串要在清單'A','B'時 select * from qq where col1 in (&col1)
COL1,COL2
A,1
A,2
B,1
B,2
當變數數值要在清單1,2時 select * from qq where col2 in (&col2)
COL1,COL2
A,1
A,2
B,1
B,2
C,1
C,2