在Oracle SQL开发人员中声明绑定变量
我想尝试通过Oracle SQL开发人员执行此查询,但是我总是收到错误消息,该消息是
ORA-01722: invalid number
01722. 00000 - "invalid number"
*Cause: The specified number was invalid.
*Action: Specify a valid number.
DEFINE po_header_ids VARCHAR(1000) := '1,2,3';
SELECT
PHA.SEGMENT1
FROM
PO.PO_HEADERS_ALL PHA
WHERE 1=1
AND (
:po_header_ids = 0 OR
:po_header_ids IS NULL OR
PHA.PO_HEADER_ID IN (
SELECT regexp_substr(:po_header_ids,'[^,]+',1,level)
FROM dual CONNECT BY
regexp_substr(:po_header_ids ,'[^,]+',1,level) IS NOT NULL
)
)
有人可以告诉我哪个部分是错误的?
谢谢。
这是我成功执行的查询,以及po_header_id
DEFINE po_header_ids varchar(1000);
SELECT regexp_substr(:po_header_ids,'[^,]+',1,level)
FROM dual CONNECT BY
regexp_substr(:po_header_ids,'[^,]+',1,level) IS NOT NULL
I'd like to try to execute this query via Oracle SQL Developer, but I always got the error message which is
ORA-01722: invalid number
01722. 00000 - "invalid number"
*Cause: The specified number was invalid.
*Action: Specify a valid number.
DEFINE po_header_ids VARCHAR(1000) := '1,2,3';
SELECT
PHA.SEGMENT1
FROM
PO.PO_HEADERS_ALL PHA
WHERE 1=1
AND (
:po_header_ids = 0 OR
:po_header_ids IS NULL OR
PHA.PO_HEADER_ID IN (
SELECT regexp_substr(:po_header_ids,'[^,]+',1,level)
FROM dual CONNECT BY
regexp_substr(:po_header_ids ,'[^,]+',1,level) IS NOT NULL
)
)
parameters which are entered in the oracle sql deverloper
Can someone tell me which part is wrong?
Thank you.
Here's the query that I executed successfully and the data type of the PO_HEADER_ID
DEFINE po_header_ids varchar(1000);
SELECT regexp_substr(:po_header_ids,'[^,]+',1,level)
FROM dual CONNECT BY
regexp_substr(:po_header_ids,'[^,]+',1,level) IS NOT NULL
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
定义
声明一个替代变量,该变量将在代码中的&
前缀,并在客户端应用程序(IE IE SQL Developer)中处理,就好像发现了一个find-Replace在声明。变量
声明一个绑定变量,该变量将在代码中以:
的前缀为前缀,并由服务器上的SQL引擎处理。您还需要更改:
:po_header_ids = 0
to:po_header_ids ='0'
,因为绑定变量是字符串而不是数字。因此,您想要:
db<
DEFINE
declares a substituition variable which will be prefixed by&
in the code and is processed in the client application (i.e. in SQL Developer) as if a find-replace occurs on the statement.VARIABLE
declares a bind-variable which will be prefixed by:
in the code and is processed by the SQL engine on the server.You also need to change:
:po_header_ids = 0
to:po_header_ids = '0'
as the bind variable is a string and not a number.So you want:
db<>fiddle here