复制代码 代码如下:
MERGE [hint] INTO [schema .] table [t_alias] USING [schema .]
{ table | view | subquery } [t_alias] ON ( condition )
WHEN MATCHED THEN merge_update_clause
WHEN NOT MATCHED THEN merge_insert_clause;
复制代码 代码如下:
MERGE INTO TABLE TARGET
USING (SELECT '111111111' STORE_NO,
'2014-01' TARGET_YM,
'1' TARGET_D01,
'2' TARGET_D02,
'2' TARGET_D03,
'2' TARGET_D04,
'2' TARGET_D05,
'2' TARGET_D06,
'2' TARGET_D07,
'2' TARGET_D08,
'2' TARGET_D09,
'2' TARGET_D10,
'2' TARGET_D11,
'2' TARGET_D12,
'2' TARGET_D13,
'2' TARGET_D14,
'2' TARGET_D15,
'2' TARGET_D16,
'2' TARGET_D17,
'2' TARGET_D18,
'2' TARGET_D19,
'2' TARGET_D20,
'2' TARGET_D21,
'2' TARGET_D22,
'2' TARGET_D23,
'2' TARGET_D24,
'2' TARGET_D25,
'2' TARGET_D26,
'2' TARGET_D27,
'2' TARGET_D28,
'2' TARGET_D29,
'2' TARGET_D30,
'2' TARGET_D31,
1 USER_ID
FROM DUAL) TEMP
ON (TARGET.STORE_NO = TEMP.STORE_NO AND TARGET.TARGET_YM = TEMP.TARGET_YM)
WHEN MATCHED THEN
UPDATE
SET TARGET.TARGET_D01 = TEMP.TARGET_D01,
TARGET.TARGET_D02 = TEMP.TARGET_D02,
TARGET.TARGET_D03 = TEMP.TARGET_D03,
TARGET.TARGET_D04 = TEMP.TARGET_D04,
TARGET.TARGET_D05 = TEMP.TARGET_D05,
TARGET.TARGET_D06 = TEMP.TARGET_D06,
TARGET.TARGET_D07 = TEMP.TARGET_D07,
TARGET.TARGET_D08 = TEMP.TARGET_D08,
TARGET.TARGET_D09 = TEMP.TARGET_D09,
TARGET.TARGET_D10 = TEMP.TARGET_D10,
TARGET.TARGET_D11 = TEMP.TARGET_D11,
TARGET.TARGET_D12 = TEMP.TARGET_D12,
TARGET.TARGET_D13 = TEMP.TARGET_D13,
TARGET.TARGET_D14 = TEMP.TARGET_D14,
TARGET.TARGET_D15 = TEMP.TARGET_D15,
TARGET.TARGET_D16 = TEMP.TARGET_D16,
TARGET.TARGET_D17 = TEMP.TARGET_D17,
TARGET.TARGET_D18 = TEMP.TARGET_D18,
TARGET.TARGET_D19 = TEMP.TARGET_D19,
TARGET.TARGET_D20 = TEMP.TARGET_D20,
TARGET.TARGET_D21 = TEMP.TARGET_D21,
TARGET.TARGET_D22 = TEMP.TARGET_D22,
TARGET.TARGET_D23 = TEMP.TARGET_D23,
TARGET.TARGET_D24 = TEMP.TARGET_D24,
TARGET.TARGET_D25 = TEMP.TARGET_D25,
TARGET.TARGET_D26 = TEMP.TARGET_D26,
TARGET.TARGET_D27 = TEMP.TARGET_D27,
TARGET.TARGET_D28 = TEMP.TARGET_D28,
TARGET.TARGET_D29 = TEMP.TARGET_D29,
TARGET.TARGET_D30 = TEMP.TARGET_D30,
TARGET.TARGET_D31 = TEMP.TARGET_D31,
TARGET.OPT_COUNTER = TARGET.OPT_COUNTER + 1,
TARGET.UPDATE_BY = TEMP.USER_ID,
TARGET.UPDATE_DATE = SYSDATE
WHEN NOT MATCHED THEN
INSERT
VALUES
(SEQ.NEXTVAL,
TEMP.STORE_NO,
TEMP.TARGET_YM,
TEMP.TARGET_D01,
TEMP.TARGET_D02,
TEMP.TARGET_D03,
TEMP.TARGET_D04,
TEMP.TARGET_D05,
TEMP.TARGET_D06,
TEMP.TARGET_D07,
TEMP.TARGET_D08,
TEMP.TARGET_D09,
TEMP.TARGET_D10,
TEMP.TARGET_D11,
TEMP.TARGET_D12,
TEMP.TARGET_D13,
TEMP.TARGET_D14,
TEMP.TARGET_D15,
TEMP.TARGET_D16,
TEMP.TARGET_D17,
TEMP.TARGET_D18,
TEMP.TARGET_D19,
TEMP.TARGET_D20,
TEMP.TARGET_D21,
TEMP.TARGET_D22,
TEMP.TARGET_D23,
TEMP.TARGET_D24,
TEMP.TARGET_D25,
TEMP.TARGET_D26,
TEMP.TARGET_D27,
TEMP.TARGET_D28,
TEMP.TARGET_D29,
TEMP.TARGET_D30,
TEMP.TARGET_D31,
NULL,
DEFAULT,
DEFAULT,
NULL,
TEMP.USER_ID,
DEFAULT,
NULL,
NULL);
复制代码 代码如下:
SELECT COLUMN_ID,
COLUMN_NAME,
DATA_TYPE,
DATA_LENGTH,
DATA_PRECISION,
DATA_SCALE,
NULLABLE,
DATA_DEFAULT
FROM USER_TAB_COLUMNS
WHERE TABLE_NAME = 'TABLE'
ORDER BY COLUMN_ID
新闻热点
疑难解答