SELECT * FROM DIM_TRANS_TYPE WHERE TRANSACTION_TYPE='ILAU';
我想在这里完成的是在上述记录中将ILAU
更改为IFAU
和Instant Loan Authorization Request
更改为Instant Finance Authorization Request
。
表架构:
Name Null Type
--------------------- -------- ------------------
TRANSACTION_TYPE NOT NULL VARCHAR2(4 CHAR) --> PRIMARY KEY
TRANSACTION_TYPE_DESC VARCHAR2(256 CHAR)
工作!!!
MERGE INTO DIM_TRANS_TYPE a
USING (SELECT 'ILAU' TRANSACTION_TYPE, 'Instant Loan Authorization Request' TRANSACTION_TYPE_DESC FROM DUAL) b
ON (a.TRANSACTION_TYPE = b.TRANSACTION_TYPE)
WHEN MATCHED THEN UPDATE
SET
a.TRANSACTION_TYPE_DESC = 'Instant Finance Authorization Request'
WHEN NOT MATCHED THEN
INSERT(a.TRANSACTION_TYPE, a.TRANSACTION_TYPE_DESC)
VALUES(b.TRANSACTION_TYPE, b.TRANSACTION_TYPE_DESC);
不工作!!! (如下所示)
MERGE INTO DIM_TRANS_TYPE a
USING (SELECT 'ILAU' TRANSACTION_TYPE, 'Instant Loan Authorization Request' TRANSACTION_TYPE_DESC FROM DUAL) b
ON (a.TRANSACTION_TYPE = b.TRANSACTION_TYPE)
WHEN MATCHED THEN UPDATE
SET
a.TRANSACTION_TYPE = 'IFAU',
a.TRANSACTION_TYPE_DESC = 'Instant Finance Authorization Request'
WHEN NOT MATCHED THEN
INSERT(a.TRANSACTION_TYPE, a.TRANSACTION_TYPE_DESC)
VALUES(b.TRANSACTION_TYPE, b.TRANSACTION_TYPE_DESC);
错误:
Error at Command Line : 5 Column : 9
Error report -
SQL Error: ORA-38104: Columns referenced in the ON Clause cannot be updated: "A"."TRANSACTION_TYPE"
38104. 00000 - "Columns referenced in the ON Clause cannot be updated: %s"
*Cause: LHS of UPDATE SET contains the columns referenced in the ON Clause
*Action:
答案 0 :(得分:1)
如错误消息所示,无法更新on
子句中使用的字段。
您必须在单独的声明中进行此类更新。像这样:
UPDATE DIM_TRANS_TYPE
SET TRANSACTION_TYPE = 'IFAU',
TRANSACTION_TYPE_DESC = 'Instant Finance Authorization Request'
WHERE TRANSACTION_TYPE IN (
SELECT TRANSATION_TYPE
FROM (SELECT 'ILAU' TRANSACTION_TYPE,
'Instant Loan Authorization Request' TRANSACTION_TYPE_DESC
FROM DUAL)
);
MERGE INTO DIM_TRANS_TYPE a
USING (SELECT 'ILAU' TRANSACTION_TYPE,
'Instant Loan Authorization Request' TRANSACTION_TYPE_DESC
FROM DUAL) b
ON (a.TRANSACTION_TYPE = b.TRANSACTION_TYPE)
WHEN NOT MATCHED THEN
INSERT(TRANSACTION_TYPE, TRANSACTION_TYPE_DESC)
VALUES(b.TRANSACTION_TYPE, b.TRANSACTION_TYPE_DESC);
您可能希望在事务中执行此操作,以便提交这两个语句中的两个或两个都不会发生更改。
当然,IN
子句看起来有点夸张,因为值可以简单地与ILAU
进行比较,但我假设你简化了问题,实际上你有一个更大的数据集来获取{ {1}}来自。
答案 1 :(得分:0)
也许我错过了一些东西......看来你正在寻找所有transaction_type = 'ILAU'
(无论1>}的)的行,以及那些行将transaction_type_desc
更新为transaction_type
,将'IFAU'
更新为transaction_type_desc
。正确?
如果是这样,为什么除了简单的'Instant Finance Authorization Request'
声明之外还需要其他任何内容?
UPDATE
在您的尝试中还有一个update dim_trans_type
set transaction_type = 'IFAU',
transaction_type_desc = 'Instant Finance Authorization Request'
where transaction_type = 'ILAU'
;
子句 - 如果现有行都没有when not matched
,则插入一行。这与您的要求有何关系?你说我想在这里完成的只是改变[.....] - 没有提到插入任何东西。问题陈述,用简单的英语,是不完整的?或者你是否插入了不需要插入的东西?