传递参数为in('','','') 不定数据时
来源:互联网 发布:电商将被淘汰 知乎 编辑:程序博客网 时间:2024/05/16 08:22
Thomas -- Thanks for the question regarding "How can I do a variable "in list"", version 8.1.5
Submitted on 2-May-2000 15:57 Central time zoneTom's latest followup | Bookmark | BottomLast updated 15-Jul-2009 16:57
You Asked
I have a simple stored procedure, that I would like to have a passed in string(varchar2)
for used in select from where col1 in (var1) in a stored procedure. I've tried
everything but doesn't work. Followed is my proc.
Thanks
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);
End;
and we said...
it works -- the above is the same as
where sectno = pSectNos
though, not what you want. You want it to be:
where sectno in ( 'abc', 'xyz', '012' )
NOT:
where sectno in ( '''abc'', ''xyz'', ''012''' )
which 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
012
ops$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
- 传递参数为in('','','') 不定数据时
- 传递不定个数的参数
- C#函数传递不定参数
- 函数传递不定参数理解-c语言
- Js动态传递不定数目的参数
- 不定长度参数传递的探讨
- 为不定参数Object...objects传数组
- 在VB中实现向函数传递不定个数参数
- 在VB中实现向函数传递不定个数参数
- VC不定参数的传递和自定义异常的抛出
- <Python进阶读书笔记>之(一) 函数不定参数传递
- Python给函数传递不定个数的参数
- Python给函数传递不定关键字的参数
- 不定参数
- 不定参数
- 不定参数
- 不定参数
- as3 apply() 不定参数(…rest parameters)的二次不定传递
- Windows 下安装 S60_3rd_sdk_fp1,并在 eclipse 上搭建 Nokia 的 J2ME 开发环境
- VNC实现远程桌面控制
- vc++学习日记 1.30 为程序添加快捷菜单
- Getting to know ISO 15926
- Visual Studio 2008 中创建和调用Static Library静态链接库文件
- 传递参数为in('','','') 不定数据时
- 关于Java中BorderLayout布局的一个纠结问题,求教
- jQuery中的end()方法的详解
- WINCE代码的目录组织
- 于丹教授很棒的话
- 沦落了么?中国武术,您还是死去吧P武术文化
- [转]富人的28个理财习惯
- 韩寒--
- 个人网站赚钱经营解密