我无法弄清楚导致它的问题是什么。我已经尝试重命名“金额”我试图改变传输的数据类型,我尝试删除它,但后来它说,一旦我这样做,End_Date无效。这是代码。
INSERT INTO price
( price_id
, item_id
, price_type
, active_flag
, start_date
, end_date
, amount
, created_by
, creation_date
, last_updated_by
, last_updated)
(SELECT price_s1.nextval
, il.Item_ID
, il.Price_Type
, il.Active_Flag
, il.Start_Date
, il.End_Date
, il.amount
, 1
, SYSDATE
, 1
, SYSDATE
FROM (SELECT i.item_id AS "Item_ID"
, af.active_flag AS "Active_Flag"
, cl.common_lookup_id AS "Price_Type"
, cl.common_lookup_type AS "Price_Desc"
, CASE
WHEN (TRUNC(SYSDATE) - 30) > TRUNC(i.release_date) THEN TRUNC(i.release_date) + 31
ELSE TRUNC(i.release_date)
END AS "Start_Date"
, CASE
WHEN (TRUNC(SYSDATE)-30) > TRUNC(i.release_date) AND active_flag = 'N' THEN
TRUNC(i.release_date) + 30
ELSE
null
END AS "End_Date"
, CASE
WHEN active_flag = 'N' AND cl.common_lookup_type = '1-DAY RENTAL' THEN 3
WHEN active_flag = 'N' AND cl.common_lookup_type = '3-DAY RENTAL' THEN 10
WHEN active_flag = 'N' AND cl.common_lookup_type = '5-DAY RENTAL' THEN 15
WHEN i.release_date+1 > (SYSDATE-1) AND cl.common_lookup_type = '1-DAY RENTAL' THEN 3
WHEN i.release_date+1 > (SYSDATE-1) AND cl.common_lookup_type = '3-DAY RENTAL' THEN 10
WHEN i.release_date+1 > (SYSDATE-1) AND cl.common_lookup_type = '5-DAY RENTAL' THEN 15
WHEN active_flag = 'Y' AND i.release_date +1 < (SYSDATE-1) THEN cl.common_lookup_code
END AS "amount"
FROM item i CROSS JOIN
(SELECT 'Y' AS active_flag FROM dual
UNION ALL
SELECT 'N' AS active_flag FROM dual) af CROSS JOIN
(SELECT '1' AS rental_days FROM dual
UNION ALL
SELECT '3' AS rental_days FROM dual
UNION ALL
SELECT '5' AS rental_days FROM dual) dr INNER JOIN
common_lookup cl ON dr.rental_days = SUBSTR(cl.common_lookup_type,1,1)
WHERE cl.common_lookup_table = 'PRICE'
AND cl.common_lookup_column = 'PRICE_TYPE'
AND NOT (active_flag ='N' AND (TRUNC(SYSDATE)-30) < TRUNC(i.release_date))
ORDER BY 1, 2, 3) il);
我在
处收到错误, il.amount
这就是它所说的
Error report -
SQL Error: ORA-00904: "IL"."AMOUNT": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
任何帮助将不胜感激,如果您需要更多信息,请询问。感谢
答案 0 :(得分:2)
通过使用别名的引号,您可以指定particalur区分大小写的名称。
CASE ... END AS "amount"
以小写形式指定别名为"amount"
。如果要访问它,请使用相同的拼写。例如。 "Amount"
无效。
您正在尝试访问
il.amount
并且因为没有引号,你说:&#34;我不关心大/小写&#34;。这在直接访问表名和列名时或使用不带引号的别名时有效。但是,在您之前使用"amount"
之前,找不到amount
(如果可能的话,你很幸运;我猜它可以与所有上层字符的别名一起发生,就像Oracle一样在内部使用上面的字符作为其名称,但你不想依赖它。
我建议你删除引号。尽可能避免使用它们。使用不带引号的名称(您实际上已经在做的名称;您的别名都不包含任何空白,前导数字或其他任何名称)。