string Oracle sql - 存储过程 - 在字符串中连接一个变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12499512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle sql - stored procedure - concat a variable in a string
提问by user1683737
I have a stored procedure of this kind
我有一个这样的存储过程
create or replace
PROCEDURE AAA
(
p_BBB IN VARCHAR,
...
)
AS
T_QUERY varchar2(3000);
BEGIN
OPEN A_CUR FOR SELECT ... BBB like '%' || p_BBB || '%';
T_QUERY := 'SELECT BBB like %'|| p_BBB ||'% ';
END AAA;
The problem is that while the first query is correctly processed, the concat between the strings in T_QUERY
gives me error (invalid character).
问题是,虽然正确处理了第一个查询,但字符串之间的连接T_QUERY
给了我错误(无效字符)。
Neither using concat()
works, the T_QUERY
will be pass to another stored procedure that performs the query.
使用都concat()
不起作用,T_QUERY
将传递给另一个执行查询的存储过程。
Can anyone help me??
谁能帮我??
回答by Rapha?l Althaus
you may try
你可以试试
T_QUERY :='SELECT BBB like ''%'|| p_BBB ||'%''';
回答by Vishnu Gupta
Above solution is correct. You use it like this.
以上解决方案是正确的。你像这样使用它。
create or replace
PROCEDURE AAA
(
p_BBB IN VARCHAR,
...
)
AS
T_QUERY varchar2(3000);
BEGIN
T_QUERY :='SELECT BBB .. like ''%'|| p_BBB ||'%''';
OPEN A_CUR FOR T_QUERY ;
----
----
END AAA;