sql - 游标的 SELECT 列表中需要别名以避免重复的列名

标签 sql plsql

我在执行 plsql 命令时遇到问题。这个想法是显示 express 、位置以及是否超过 20。

DECLARE 
 yesnobool VARCHAR(3); 

 CURSOR orders_list IS 
 SELECT shipping.ship_courier, 
 shipping.weightpership,
  shipping.shipping#,
  purchaseorder.shipping#,
  storelocation.location#,
  STORELOCATION.LOC_CITY,
  purchaseorder.location#
 FROM shipping, 
 purchaseorder, 
 storelocation
 WHERE purchaseorder.shipping# = shipping.shipping# 
 and storelocation.location# = purchaseorder.location#;
BEGIN 
 dbms_output.Put_line('Courier || Location || Too Heavy for 1 person lift?'); 
 dbms_output.Put_line('------ -------- -----------------------------------'); 

 FOR an_order IN orders_list LOOP 
 IF SHIPPING.WEIGHTPERSHIP > 20 THEN 
 yesnobool := 'YES'; 
 ELSE 
 yesnobool := 'NO'; 
 END IF; 

 dbms_output.Put_line(Rpad(an_order.ship_courier, 6) || ' ' || 
 Rpad(an_order.loc_city, 8) || ' ' || 
 Rpad(yesnobool, 19)); 
 END LOOP; 
END; 

我收到的错误消息是:

Error report - ORA-06550: line 21, column 2: PLS-00402: alias required in SELECT list of cursor to avoid duplicate column names ORA-06550: line 21, column 2: PL/SQL: Statement ignored 06550. 00000 - "line %s, column %s:\n%s" *Cause: Usually a PL/SQL compilation error. *Action:

我不太擅长 plsql,所以我真的不知道如何确定问题。预先感谢您提供的任何建议。

最佳答案

shipping#location# 在您的选择字段列表中重复。

shipping.shipping#
purchaseorder.shipping#

storelocation.location#,
purchaseorder.location#

光标无法区分其应该使用哪个运输或位置。

解决方案是为字段添加别名。像这样的事情:

shipping.shipping# as shipping,
purchaseorder.shipping# as poshipping

还有:

storelocation.location# as storeLocation,
purchaseorder.location# as poLocation

关于sql - 游标的 SELECT 列表中需要别名以避免重复的列名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23502595/

相关文章:

php - Codeigniter 更新查询不起作用

sql - 在 PL/SQL 变量名称中使用下划线或大写

oracle - PLSQL绑定(bind)变量和主机变量有什么区别

sql - 在 SQL 中遇到异常后如何继续运行我的程序?

sql - 如何计算这些列中有多少列在 SQL 中具有值?

mysql - sql 子查询返回 "Every derived table must have its own alias"

php - Where 子句在 tinyint 上不起作用

sql - SQL Azure 上的查询性能极差

Oracle存储过程-根据可选参数动态生成选择语句

oracle - 无法访问 plsql 函数返回的对象类型