oracle存储过程关于 select …… in(变量) 的 问题求助!!

zq281660880 2012-08-16 09:33:43
创建了这样一个存储过程

create or replace procedure CS_SELKG
(
V_CONDTION VARCHAR2,
V_CURSOR OUT SYS_REFCURSOR
)
IS
BEGIN
open v_cursor for select a.s_txm,b.content from shuibiaoxx a
inner join (
select * from words where belongid='106'
) b on a.s_ztid=b.wordsid
where a.s_txm in(V_CONDTION);
END CS_SELKG

存储过程调试时发现
当 存储过程中 V_CONDTION 变量值为一个值 如 select………… in(123)
调试时候游标中有一条记录 。

但是当 V_CONDTION 变量值为2 个值或以上值 如 select………… in(123,456)
游标中的结果为空表

该问题应该是 给 V_CONDTION变量赋值 123,456 是 系统认为 123,456 是一个字符串 而不是以逗号分隔开的两个字符串


请问各位
我想在存储过程中实现类似如 select …… in(V_CONDTION ) 多个值


该怎么实现 ?特别说明 存储过程中V_CONDTION 变量值 是程序中窗体输入值 ,无法在存储过程中使用exists …
...全文
477 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
zq281660880 2012-08-16
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]

SQL code

--这是我写的个简单的例子,你看下
SQL> declare
2 type cur_type is ref cursor;
3 cur cur_type;
4 rec emp%rowtype;
5 str varchar2(50);
6 letter varchar2(50):= '7369,7566';……
[/Quote]

现在可以了,非常感谢你的帮助!
zq281660880 2012-08-16
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]

SQL code

--这是我写的个简单的例子,你看下
SQL> declare
2 type cur_type is ref cursor;
3 cur cur_type;
4 rec emp%rowtype;
5 str varchar2(50);
6 letter varchar2(50):= '7369,7566';……
[/Quote]
非常非常感谢!
人生无悔 2012-08-16
  • 打赏
  • 举报
回复

--先打印出sql语句,然后直接执行你打印的语句看有无记录
set serveroutput on;
declare
V_CONDTION varchar2(1000):= '1,2,3,4';--换成你的值
v_str varchar2(4000):='';
begin
v_str:= 'select a.s_txm,b.content from shuibiaoxx a
inner join (
select * from words where belongid=''106''
) b on a.s_ztid=b.wordsid
where a.s_txm in('||V_CONDTION||')';
dbms_output.put_line(v_str);
end;
/



--用这个语句看下有无记录
select a.s_txm,b.content from shuibiaoxx a
inner join (
select * from words
where belongid='106'
) b on a.s_ztid=b.wordsid
where a.s_txm in(1,2,3,4); --1,2,3,4,换成你的值
人生无悔 2012-08-16
  • 打赏
  • 举报
回复

--这是我写的个简单的例子,你看下
SQL> declare
2 type cur_type is ref cursor;
3 cur cur_type;
4 rec emp%rowtype;
5 str varchar2(50);
6 letter varchar2(50):= '7369,7566';
7 begin
8 str:= 'select ename from emp where empno in ('||letter||')';
9 open cur for str;
10 loop
11 fetch cur into rec.ename;
12 exit when cur%notfound;
13 dbms_output.put_line(rec.ename);
14 end loop;
15 end;
16 /
SMITH
JONES


--源码
declare
type cur_type is ref cursor;
cur cur_type;
rec emp%rowtype;
str varchar2(50);
letter varchar2(50):= '7369,7566';
begin
str:= 'select ename from emp where empno in ('||letter||')';
open cur for str;
loop
fetch cur into rec.ename;
exit when cur%notfound;
dbms_output.put_line(rec.ename);
end loop;
end;
/
zq281660880 2012-08-16
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]

SQL code

open v_cursor for 'select a.s_txm,b.content from shuibiaoxx a
inner join (
select * from words where belongid=''106''--此处我写错了也可以去掉''直接106,毕竟是数字
) b on a.s_ztid=b.wordsid
where a.……
[/Quote]

好像还是不行哦,结果为空,
大侠救命!
zq281660880 2012-08-16
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]

SQL code

open v_cursor for 'select a.s_txm,b.content from shuibiaoxx a
inner join (
select * from words where belongid=''106''--此处我写错了也可以去掉''直接106,毕竟是数字
) b on a.s_ztid=b.wordsid
where a.……
[/Quote]

这个貌似还是不行,结果还是为空的 ,
大侠救命!
人生无悔 2012-08-16
  • 打赏
  • 举报
回复

open v_cursor for 'select a.s_txm,b.content from shuibiaoxx a
inner join (
select * from words where belongid=''106''--此处我写错了也可以去掉''直接106,毕竟是数字
) b on a.s_ztid=b.wordsid
where a.s_txm in('||V_CONDTION||')';
zq281660880 2012-08-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

SQL code

--改成下面这种试下
open v_cursor for 'select a.s_txm,b.content from shuibiaoxx a
inner join (
select * from words where belongid='106'
) b on a.s_ztid=b.wordsid
where a.s_txm in('||V_CON……
[/Quote]

这个好像也不行的 结果还是为空的,该怎么处理呢?
zq281660880 2012-08-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

SQL code

--改成下面这种试下
open v_cursor for 'select a.s_txm,b.content from shuibiaoxx a
inner join (
select * from words where belongid='106'
) b on a.s_ztid=b.wordsid
where a.s_txm in('||V_CON……
[/Quote]


这样还是不行的 结果还是为空
zq281660880 2012-08-16
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
创建了这样一个存储过程

create or replace procedure CS_SELKG
(
V_CONDTION VARCHAR2,
V_CURSOR OUT SYS_REFCURSOR
)
IS
BEGIN
open v_cursor for select a.s_txm,b.content from shuibiaoxx ……
[/Quote]

能不能麻烦给个实例学习一下?
人生无悔 2012-08-16
  • 打赏
  • 举报
回复

--改成下面这种试下
open v_cursor for 'select a.s_txm,b.content from shuibiaoxx a
inner join (
select * from words where belongid='106'
) b on a.s_ztid=b.wordsid
where a.s_txm in('||V_CONDTION||')';
人生无悔 2012-08-16
  • 打赏
  • 举报
回复
改成execute immediate执行
因V_CONDTION你这个是一个字符串,并不是一个数字的集合,不能这样用的

17,082

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧