带有变量帮助的 PLSQL select 语句
您好,我正在尝试执行这个简单的语句,但我想添加一个来自选择的变量。这是我所拥有的。
userEmail varChar(50) := SELECT user_id FROM users WHERE email = '[email protected]';
SELECT *
FROM iphone_alerts
WHERE user_id = userEmail
AND date_added = (SELECT MAX(date_added) FROM iphone_alerts WHERE user_id = userEmail
我需要使用类似于“声明”和“开始”的东西吗?我对 sql 很陌生,很难找到答案。
Hello i am trying to do this simple statement but i want to add a variable that comes from a select. Here is what i have.
userEmail varChar(50) := SELECT user_id FROM users WHERE email = '[email protected]';
SELECT *
FROM iphone_alerts
WHERE user_id = userEmail
AND date_added = (SELECT MAX(date_added) FROM iphone_alerts WHERE user_id = userEmail
Do i need to use something along the lines of Declare and Begins? I am new to the sql stuff and am having trouble finding answers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要:
在注释后编辑:
如果 select 只返回一行,则不需要游标,但需要一个
into
子句将每个检索到的值存储到变量中。像这样的东西:You need:
Edit after comment:
If select should return only ONE row, you don't need a cursor, but you need an
into
clause to store each retrieved value into a variable. Something like:如果你想在 SQL 中执行此操作,你会想要类似这样的东西
,也许更有效的是这样的东西,让我们只访问 IPHONE_ALERTS 表一次。
If you want to do this in SQL, you'd want something like
Probably more efficient would be something like this that lets us hit the IPHONE_ALERTS table just once.
我不确定您要做什么,但我认为您可能需要
select into
http://download.oracle.com/docs/cd/B13789_01/appdev.101/b10807/13_elems045.htm
I'm not sure what you're trying to do, but I think you might need
select into
http://download.oracle.com/docs/cd/B13789_01/appdev.101/b10807/13_elems045.htm