动态参数化查询与like

时间:2016-02-12 08:38:21

标签: sql oracle plsql

Normal赋值运算符工作正常,但是在存储过程中操作不能使用下面的查询,你能纠正查询的错误吗?

在仅更改为LIKE运算符时,基于查询的过程会引发异常

AND APP_FRAMES.APP_EXT_CODE =:IN_APP_EXT_CODE%;      -- working

AND APP_FRAMES.APP_EXT_CODE LIKE %:IN_APP_EXT_CODE%; -- not working

工作代码:

QUERY_STR := 'select * from APP_FRAME_PROPERTIES,APP_FRAMES
Where APP_FRAME_PROPERTIES.APP_EXT_CODE = APP_FRAMES.APP_EXT_CODE
AND APP_FRAMES.APP_EXT_CODE =:IN_APP_EXT_CODE';

OPEN OUT_RESULT FOR QUERY_STR USING IN_APP_EXT_CODE;

1 个答案:

答案 0 :(得分:2)

您必须连接'%'文字:

AND APP_FRAMES.APP_EXT_CODE LIKE '%' || :IN_APP_EXT_CODE || '%'; 

整个查询将是:

QUERY_STR := 'select * from APP_FRAME_PROPERTIES,APP_FRAMES
Where APP_FRAME_PROPERTIES.APP_EXT_CODE = APP_FRAMES.APP_EXT_CODE
AND APP_FRAMES.APP_EXT_CODE LIKE ''%'' || :IN_APP_EXT_CODE || ''%'' ';