我在执行 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/