如何使用 FOR 光标循环访问记录中的串联列
尝试将记录与游标和后来的按表索引混合使用。
DECLARE CURSOR emp_cur IS
SELECT employee_id, first_name||' '|| last_name "name"
FROM employees
ORDER BY salary desc;
emp_rec emp_cur%ROWTYPE;
BEGIN
FOR emp_rec IN emp_cur
LOOP
DBMS_OUTPUT.PUT_LINE('Employee ID:'||emp_rec.employee_id||CHR(10)||
'Employee Name:'||emp_rec.name);
EXIT WHEN emp_cur%ROWCOUNT = 10;
END LOOP;
END;
当我运行上面的代码时,我得到了
ERROR at line 13, "NAME" must be declared.
How can I access the columns first_name||' '||For 循环内的last_name?或者我只需要执行传统的 OPEN、简单循环、FETCH 和关闭?
Trying to use records with the cursor and later index by table in the mix.
DECLARE CURSOR emp_cur IS
SELECT employee_id, first_name||' '|| last_name "name"
FROM employees
ORDER BY salary desc;
emp_rec emp_cur%ROWTYPE;
BEGIN
FOR emp_rec IN emp_cur
LOOP
DBMS_OUTPUT.PUT_LINE('Employee ID:'||emp_rec.employee_id||CHR(10)||
'Employee Name:'||emp_rec.name);
EXIT WHEN emp_cur%ROWCOUNT = 10;
END LOOP;
END;
When I run above code I get
ERROR at line 13, "NAME" must be declared.
How can I access the column first_name||' '||last_name inside the For loop? or do I just have to do traditional OPEN, simple loop, FETCH and close?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你们非常接近;问题在于,不在双引号中的标识符会转换为大写,而在双引号中的标识符不会转换为大写。所以
name
、NAME
和"NAME"
是等价的,并且都与"name"< /代码>。要么将 this: 更改
为:,
或者,如果您愿意,也可以将 this: 更改
为:
You're very close; the problem is just that identifiers that are not in double-quotes get converted to uppercase, while identifiers that are in double-quotes do not. So
name
,NAME
, and"NAME"
are equivalent to each other, and all of them are different from"name"
. Either change this:to this:
or else, if you prefer, change this:
to this: