在 SELECT 语句中使用声明的变量
我正在使用 Oracle 10g,需要在 SELECT 的 where 子句中使用变量;例如。
DECLARE
v_blah NUMBER;
BEGIN
v_blah := 13;
SELECT * FROM PEOPLE p WHERE p.LuckyNumber = v_blah;
END;
但收到错误消息
PLS-00428:此 SELECT 语句中应包含 INTO 子句
它似乎在 DELETE 或 INSERT 语句中工作正常,所以我不确定为什么它在这里不起作用。
I'm using Oracle 10g and need to use a variable in a where clause of a SELECT; eg.
DECLARE
v_blah NUMBER;
BEGIN
v_blah := 13;
SELECT * FROM PEOPLE p WHERE p.LuckyNumber = v_blah;
END;
but am getting an error saying
PLS-00428: an INTO clause is expected in this SELECT statement
It seems to work fine in a DELETE or INSERT statement, so I'm not sure why it wouldn't work here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正确的语法是:
PL/SQL 中的 select 语句< /a> 需要一个存储查询结果的地方。在此示例中,该位置是
v_people_rec
变量。上面的示例期望返回恰好一行。在其他情况下,它将抛出异常
NO_DATA_FOUND
或TOO_MANY_ROWS
。The correct syntax is:
The select statement in PL/SQL requires a place where store the query result. In this example the place is
v_people_rec
variable.The example above expects exactly one row to be returned. In other cases it will throw exceptions
NO_DATA_FOUND
orTOO_MANY_ROWS
.这与您的参数无关,这是因为您将代码作为程序代码块执行,因此它不允许您选择任何内容。
您想对查询结果做什么?显示到屏幕上?如果是这样,请将其选择到游标,迭代并使用 dbms_output。
That isn't anything to do with your parameter, it is because you're executing your code as a procedural block of code so it doesn't allow you to select to nothing.
What do you want to do with the result of the query? Display it to the screen? If so, select it to a cursor, iterate through and use dbms_output.