oracle存储过程无效字符_Oracle存储过程查询无法使用游标

I am new to oracle and trying to create a stored procedure with the following pl/sql code.

What is wrong with the code?when i replace the searchString with hard code value of '1605%' then the query is executed but not with the variable.

create or replace PACKAGE BODY MAT_INFO AS

PROCEDURE mat_details(mat_id IN varchar, mat_cur OUT SYS_REFCURSOR) AS

searchString varchar2(700);

BEGIN

searchString := ''''||mat_id||'%''';

OPEN mat_cur FOR SELECT mi.* FROM S_JAMM_MAT_INFO mi WHERE mi.MAT_ID LIKE searchString;

END mat_details;

END MAT_INFO;

Can anyone help me what am i doing wrong here?

Thanks

解决方案

You are using unnecessary quotes:

SQL> declare

2 mat_id varchar2(100) := 'X';

3 searchString varchar2(100) := ''''||mat_id||'%''';

4 searchString2 varchar2(100) := ''||mat_id||'%';

5 num number;

6 begin

7 select count(1)

8 into num

9 from dual

10 where 'X' like searchString;

11 --

12 dbms_output.put_line('1. num= ' || num);

13 --

14 select count(1)

15 into num

16 from dual

17 where 'X' like searchString2;

18 --

19 dbms_output.put_line('2. num= ' || num);

20 end;

21 /

1. num= 0

2. num= 1

PL/SQL procedure successfully completed.

SQL>

Your double quoting could be useful if you would use a dynamic SQL, but in your static query it means that you are looking for a pattern containing quotes as part of the string to look for.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值