我试图执行一个选择插入,我需要使用序列和一个不同的子句。
我知道我们不能使用不同的序列,所以我在FROM中嵌套了一个子查询,如下所示:
INSERT INTO SchemaName.XXSON_ST_B2B_CTR_PRICING
(SEQ_NO,SEEB_KEY,MESSAGE_ID,MESSAGE_TYPE,CREATE_DTIME,CHANGE_DTIME,STATUS)
SELECT
XXSON.XXSON_B2B_CTR_PRICING_SEQ.NEXTVAL AS SEQ_NO,
'SESS_NO' AS SEEB_KEY,
srp.ITEM AS MESSAGE_ID,
'MESSAGE_TYPE' AS MESSAGE_TYPE,
sysdate AS CREATE_DTIME,
sysdate AS CHANGE_DTIME,
'I' AS STATUS
FROM
(SELECT distinct srp.ITEM
FROM SchemaName.NB_PRICELIST_CTRL pctrl,
SchemaName.NB_PRICELIST_SRP srp
WHERE STATUS = 'W'
AND SOURCE_TABLE = 'NB_PRICELIST_SRP');
然而,有了这个,我无法将srp.ITEM作为MESSAGE_ID插入,因为我有一个无效的标识符( ORA-00904 ),这里不足为奇。有没有解决方法,所以我可以正确插入?
答案 0 :(得分:2)
要摆脱alias
,您必须将derived table
分配给FROM
,作为存储在内存中的普通表。在块内分配的INSERT INTO SchemaName.XXSON_ST_B2B_CTR_PRICING
(SEQ_NO,SEEB_KEY,MESSAGE_ID,MESSAGE_TYPE,CREATE_DTIME,CHANGE_DTIME,STATUS)
SELECT
XXSON.XXSON_B2B_CTR_PRICING_SEQ.NEXTVAL AS SEQ_NO,
'SESS_NO' AS SEEB_KEY,
alias.ITEM AS MESSAGE_ID,
'MESSAGE_TYPE' AS MESSAGE_TYPE,
sysdate AS CREATE_DTIME,
sysdate AS CHANGE_DTIME,
'I' AS STATUS
FROM
(SELECT distinct srp.ITEM
FROM SchemaName.NB_PRICELIST_CTRL pctrl,
SchemaName.NB_PRICELIST_SRP srp
WHERE STATUS = 'W'
AND SOURCE_TABLE = 'NB_PRICELIST_SRP') alias;
子句中的别名在外部不可见。
my $key = (keys %hash)[0]
答案 1 :(得分:0)
请尝试以下查询,这可能会对您有所帮助。
INSERT INTO SchemaName.XXSON_ST_B2B_CTR_PRICING (SEQ_NO,SEEB_KEY,MESSAGE_ID,MESSAGE_TYPE,CREATE_DTIME,CHANGE_DTIME,STATUS) SELECT XXSON.XXSON_B2B_CTR_PRICING_SEQ.NEXTVAL AS SEQ_NO, 'SESS_NO' AS SEEB_KEY, (SELECT distinct srp.ITEM FROM SchemaName.NB_PRICELIST_CTRL pctrl, SchemaName.NB_PRICELIST_SRP srp WHERE STATUS = 'W' AND SOURCE_TABLE = 'NB_PRICELIST_SRP') AS MESSAGE_ID, 'MESSAGE_TYPE' AS MESSAGE_TYPE, sysdate AS CREATE_DTIME, sysdate AS CHANGE_DTIME, 'I' AS STATUS;
问候。
答案 2 :(得分:0)
您提供的错误消息处理丢失或无效的列。我相信错误消息的具体问题是
中的srp别名srp.item as Message_ID
因为您没有在括号中对2个表的组合进行别名(您在内部对各个表进行别名,但这不会执行)。一个简单的解决方法是删除'srp'。从顶部陈述中“项目”的前面开始。
INSERT INTO SchemaName.XXSON_ST_B2B_CTR_PRICING
(SEQ_NO,SEEB_KEY,MESSAGE_ID,MESSAGE_TYPE,CREATE_DTIME,CHANGE_DTIME,STATUS)
SELECT
XXSON.XXSON_B2B_CTR_PRICING_SEQ.NEXTVAL AS SEQ_NO,
'SESS_NO' AS SEEB_KEY,
ITEM AS MESSAGE_ID,
'MESSAGE_TYPE' AS MESSAGE_TYPE,
sysdate AS CREATE_DTIME,
sysdate AS CHANGE_DTIME,
'I' AS STATUS
FROM
(SELECT distinct srp.ITEM
FROM SchemaName.NB_PRICELIST_CTRL pctrl,
SchemaName.NB_PRICELIST_SRP srp
WHERE STATUS = 'W'
AND SOURCE_TABLE = 'NB_PRICELIST_SRP')
另外,我不太了解包含pctrl。