国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

PL/SQL中如何傳遞字符串變量給in

2024-07-21 02:33:22
字體:
來源:轉載
供稿:網友
    一個簡單的存儲過程,傳遞字符串變量作為參數,傳遞給過程中的in 子句;但似乎不起作用 。 代碼如下 CREATE OR REPLACE PROCEDURE WSREVSECT_5
pSectNos varchar2,
pRetCode OUT varchar2
) AS
nCount number;
BEGIN
SELECT count(fksrev) into nCount FROM SREVSECT
WHERE sectno IN (pSectNos ) /* as in 'abc', 'xyz', '012' */;
pRetCode:=to_char(ncount);
Endit works -- the above is the same aswhere sectno = pSectNosthough, not what you want. You want it to be:where sectno in ( 'abc', 'xyz', '012' )NOT:where sectno in ( '''abc'', ''xyz'', ''012''' )    當直接使用select count(*) into .. from .. where sectno in (pSectNos) 的時候,相當于where sectno = pSectNoswhich is effectively is (else you could never search on a string with commas and
quotes and so on -- it is doing the only logical thing right now).You can do this:SQL> create or replace type myTableType as table
of varchar2 (255);
2 /Type created.ops$tkyte@dev8i> create or replace
function in_list( p_string in varchar2 ) return myTableType
2 as
3 l_string long default p_string ',';
4 l_data myTableType := myTableType();
5 n number;
6 begin
7 loop
8 exit when l_string is null;
9 n := instr( l_string, ',' );
10 l_data.extend;
11 l_data(l_data.count) :=
ltrim( rtrim( substr( l_string, 1, n-1 ) ) );
12 l_string := substr( l_string, n+1 );
13 end loop;
14
15 return l_data;
16 end;
17 /Function created.ops$tkyte@dev8i> select *
2 from THE
( select cast( in_list('abc, xyz, 012') as
mytableType ) from dual ) a
3 /COLUMN_VALUE
------------------------
abc
xyz
012ops$tkyte@dev8i> select * from all_users where username in
2 ( select *
3 from THE ( select cast( in_list('OPS$TKYTE, SYS, SYSTEM')
as mytableType ) from dual ) )
4 /USERNAME USER_ID CREATED
------------------------------ ---------- ---------
OPS$TKYTE 23761 02-MAY-00
SYS 0 20-APR-99
SYSTEM 5 20-APR-99    使用array如上綁定變量in-list的時候,要注重sql語句的執行計劃;因為在有的版本下,cbo無法估計in-list virtual table的行數,產生不正確的執行計劃。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新野县| 肥城市| 历史| 榆林市| 吉水县| 灵武市| 万盛区| 毕节市| 东兴市| 昭平县| 东方市| 公安县| 吉林市| 定西市| 社旗县| 黎川县| 昭苏县| 罗平县| 正蓝旗| 盐亭县| 福鼎市| 浙江省| 庆元县| 宾阳县| 临武县| 罗田县| 英德市| 青州市| 霍山县| 光泽县| 临猗县| 荣昌县| 辽源市| 卢氏县| 开原市| 新津县| 十堰市| 泾川县| 新化县| 星子县| 漳平市|