oracle绑定变量 java,Oracle 11g“绑定变量不存在”

I am getting an "ORA01006 Bind variable does not exist at line 15 "error in the following code:

DECLARE

v_search_string varchar2(4000) := 'OK';

v_query_str VARCHAR2(4000);

match_count integer;

BEGIN

FOR t IN (SELECT owner,

table_name,

column_name

FROM all_tab_columns

WHERE data_type in ('CHAR', 'VARCHAR2', 'NCHAR', 'NVARCHAR2') And TABLE_NAME = 'T1' And OWNER = 'O1')

LOOP

Begin

v_query_str := 'SELECT COUNT(*) FROM '|| t.table_name || ' WHERE ' || t.column_name || ' Like ''' || '%:1%' || '''';

dbms_output.put_line(v_query_str);

EXECUTE Immediate v_query_str

INTO match_count

USING v_search_string;

IF match_count >= 0 THEN

dbms_output.put_line( t.owner || '.' || t.table_name ||' '||t.column_name||' '||match_count );

END IF;

END;

END LOOP;

END;

I'm just trying to loop through all the character columns in the table and count how many values in each match the v_search_string value.

The line "dbms_output.put_line(v_query_str);" prints one line:

SELECT COUNT(*) FROM T1 WHERE Col1 Like '%:1%'

There are 10 columns in the table that are the specified types.

There is obviously a bind variable there (%1), so I can't figure out what's going on.

解决方案

Form the string like this below.

t.column_name || ' Like ''%''||:1||''%'''

Bind variable should not be included within single quotes, as it would be treated as a String literal instead. So when you used USING it ended up with this excpetion.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值