Update using Merge
Hi all
I'm using Oracle 11.2.0.3.
I am trying to run this code:
MERGE INTO prop p USING ad a ON (a.prop_id = p.id) WHEN MATCHED THEN UPDATE SET p.description = a.description;
But I get this error.
ORA-30926: failed to get a stable set of rows in the source tables.
How can I perform this update taking into account the reason for that error is the relationship of 1 m between PROP and AD picture.
Where each Prop story line has 1 or more child table AD that have the same Description
Create Table PROP (ID number PRIMARY KEY, description varchar2 (4000))
Create Table AD (ID number PRIMARY KEY , PROP_ID NUMBER , description varchar2 (4000)) ALTER TABLE "AD" ADD CONSTRAINT "AD_PROP_FK" FOREIGN KEY ("PROP_ID") REFERENCES "PROP" ("ID").
Kind regards
Hello
Similar to the solution of Paul:
MERGE INTO prop p
WITH THE HELP OF)
SELECT prop_id
MIN (description) AS min_description
From ad
GROUP BY prod_id
) a
WE (a.prop_id = p.id)
WHEN MATCHED THEN UPDATE
SET a.min_description = p.description
;
The difference is that this statement does not raise an error if the description is not unique for each value of prod_id in ad. (Maybe it's a good or a bad feature.)
Instead of MIN, you can use MAX, STATS_MODE or, with a few adjustments, LISTAGG.
Tags: Database
Similar Questions
-
I have a problem with my keyboard after the update using drivercanner
Original title: my keyboard stopped working after the last updae
OTEVA here
Hi I have a problem with my keyboard after update using drivercanner I need help fixing this cause I tried looking for the installation of the upate that cause, but I don't have where to look.
try a system restore to a date preceding the update.
-
Windows Mail is not refreshing since 09/02/2012. When I try to update using the F5 key, I get the error messages. The only way I can see me new emails is to sign on the web page of my Internet service provider, which I don't like.
original title: windows mail is NOT refreshingIt would be useful that Microsoft has put a notice to have several products access our email accounts so that us non-technical people could avoid these problems.
Maybe it's something that Apple should warn the consumer. I have three e-mail accounts and I receive and send all the accounts on three different computers at the same time and have never had this problem. Your case is the first.
-
ILÇE a7 firmware update using mac 10.11.1
Enyone installed upgrading firmaware ILÇE v. a7 1.2 to 2.0 using Mac OS 10.11.1 v.. El Capitan? So far I've seen only updates using Mac OS 10.10 Yosemite.
Thanks for a quick response
Jiriep
Hi Jiriep,
Welcome to the community of Sony!
From now to the ILCE7 firmware update is available for Mac OS v 7 - 10.10. I recommend using a computer that meets these BONES to update your camera. You can download the firmware here.
For more assistance, we recommend that you visit our Sony Global Web site for more information on contacting Sony's Support Center in your area at http://www.sony.net/SonyInfo/Support/.
If my post answered your question, please mark it as "accept as a Solution. Thanks_Mitch
-
I have just reactivated Dreamweaver on a new computer. How can I get the files FROM my website ON my computer so I can edit/update using Dreamweaver?
If your old machine still works, export your definition of original site to a portable player, copy in your new machine and then import the site definition to the new machine. The definition file will have the extension .ste
Create an empty folder on your new machine.
Define a 'new' web site on your new machine to point to the new local root folder.
Log your server and download all of the subfolders and files in the folder root from the server to the new local root folder.
-
Where can I get the Adobe Camera RAW Nikon D7100 update using Bridge CS5?
Where can I get the Adobe Camera RAW Nikon D7100 update using Bridge CS5?
Currently using:
Adobe Bridge CS5 v. 4.1.0.54
Adobe Camera RAW c. 6.7.0.339
Thank you!
The D7100 was added to the list of devices supported in Camera Raw version 7.4, which is compatible with Photoshop CS6. There is no Camera Raw plugin for Photoshop CS5 that will support this camera. You will need to choose another software, or use the free DNG Converter to create negative digital copies of your NEF files. Then you can open these files DNG using Camera Raw, you have now.
-
Goodmorning,
I have a little trouble trying to update using lead/rank.
Summary of the issue: My table contains duplicate data (only difference being 2 fields reason viewer_org & interest) and rather than the operation/processing multuple lines I want to assign the org of duplicate records Viewer and then I can hold 1 row, which has a list of org that can consult them.
I took a few of the fields of interest here: -.
Samples: -.create table copy_test ( OWNER_ORG varchar(10), GEN_REC NUMBER(10), VIEWER_ORG varchar(10), INTEREST_REASON varchar(10), col_1 varchar(10), col_2 varchar(10), col_3 varchar(10), col_4 varchar(10) );
Data looks like this: -.INSERT INTO COPY_TEST (OWNER_ORG ,GEN_REC ,VIEWER_ORG ,INTEREST_REASON ,COL_1 ,COL_2 ,COL_3 ,COL_4 ) VALUES ('5AA' ,12345 ,'5AA' ,'6543' ,'' ,'' ,'' ,'' ); INSERT INTO COPY_TEST (OWNER_ORG ,GEN_REC ,VIEWER_ORG ,INTEREST_REASON ,COL_1 ,COL_2 ,COL_3 ,COL_4 ) VALUES ('5AA' ,12345 ,'5BB' ,'5430' ,'' ,'' ,'' ,'' ); INSERT INTO COPY_TEST (OWNER_ORG ,GEN_REC ,VIEWER_ORG ,INTEREST_REASON ,COL_1 ,COL_2 ,COL_3 ,COL_4 ) VALUES ('5BB' ,32165 ,'5CC' ,'430' ,'' ,'' ,'' ,'' ); INSERT INTO COPY_TEST (OWNER_ORG ,GEN_REC ,VIEWER_ORG ,INTEREST_REASON ,COL_1 ,COL_2 ,COL_3 ,COL_4 ) VALUES ('5BB' ,32165 ,'5AA' ,'5430' ,'' ,'' ,'' ,'' ); INSERT INTO COPY_TEST (OWNER_ORG ,GEN_REC ,VIEWER_ORG ,INTEREST_REASON ,COL_1 ,COL_2 ,COL_3 ,COL_4 ) VALUES ('5BB' ,32165 ,'5BB' ,'6543' ,'' ,'' ,'' ,'' ); INSERT INTO COPY_TEST (OWNER_ORG ,GEN_REC ,VIEWER_ORG ,INTEREST_REASON ,COL_1 ,COL_2 ,COL_3 ,COL_4 ) VALUES ('YAA' ,98765 ,'5AA' ,'0' ,'' ,'' ,'' ,'' ); INSERT INTO COPY_TEST (OWNER_ORG ,GEN_REC ,VIEWER_ORG ,INTEREST_REASON ,COL_1 ,COL_2 ,COL_3 ,COL_4 ) VALUES ('YAA' ,98765 ,'5BB' ,'543' ,'' ,'' ,'' ,'' );
Essential, we have 3 examples above (claim on gen_rec). The 1st example 5AA owner is a record that the Organization 5AA and 5BB are allowed to see. That's why he existing twice, viewer_org 5AA on 1 row and 5BB on the other. Then I need to assign these two organizations against one of the lines. I stated thise who strives to identify (a little): -.select * from copy_test; OWNER_ORG GEN_REC VIEWER_ORG INTEREST_R COL_1 COL_2 COL_3 COL_4 ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 5AA 12345 5AA 6543 5AA 12345 5BB 5430 5BB 32165 5CC 430 5BB 32165 5AA 5430 5BB 32165 5BB 6543 YAA 98765 5AA 0 YAA 98765 5BB 543
Gives these results:--SET LINESIZE 250; select GEN_REC ,VIEWER_ORG ,INTEREST_REASON,OWNER_ORG,VIEWER_ORG CL_1, LEAD (VIEWER_ORG,1,0) OVER (PARTITION BY GEN_REC ORDER BY GEN_REC ,VIEWER_ORG ,INTEREST_REASON,OWNER_ORG) as CL_2, LEAD (VIEWER_ORG,2,0) OVER (PARTITION BY GEN_REC ORDER BY GEN_REC ,VIEWER_ORG ,INTEREST_REASON,OWNER_ORG) as CL_3, LEAD (VIEWER_ORG,3,0) OVER (PARTITION BY GEN_REC ORDER BY GEN_REC ,VIEWER_ORG ,INTEREST_REASON,OWNER_ORG) as CL_4, RANK() OVER (PARTITION BY GEN_REC ORDER BY GEN_REC ,VIEWER_ORG ,INTEREST_REASON,OWNER_ORG) rank from COPY_TEST order by GEN_REC ,VIEWER_ORG ,INTEREST_REASON,OWNER_ORG;
This is the result, I need: -.GEN_REC VIEWER_ORG INTEREST_R OWNER_ORG CL_1 CL_2 CL_3 CL_4 RANK ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 12345 5AA 6543 5AA 5AA 5BB 0 0 1 12345 5BB 5430 5AA 5BB 0 0 0 2 32165 5AA 5430 5BB 5AA 5BB 5CC 0 1 32165 5BB 6543 5BB 5BB 5CC 0 0 2 32165 5CC 430 5BB 5CC 0 0 0 3 98765 5AA 0 YAA 5AA 5BB 0 0 1 98765 5BB 543 YAA 5BB 0 0 0 2
I need the information in the viewer_org field to be placed in depeneding CL_1 CL_2, CL_3 or CL_04 the number of duplicate rows it y a. (is never more than 4) the hierarchy of what line I want to update would be pitched what was the Interest_reason above, even if this isn't a body of numbers It may be that '0' is important.GEN_REC VIEWER_ORG INTEREST_R OWNER_ORG CL_1 CL_2 CL_3 CL_4 12345 5AA 6543 5AA 5AA 5BB 12345 5BB 5430 5AA 32165 5AA 5430 5BB 32165 5BB 6543 5BB 5BB 5AA 5CC 32165 5CC 430 5BB 98765 5AA 0 YAA 98765 5BB 543 YAA 5AA 5BB
Any ideas guys?One way would be to use Polish CASE in SELECT
with t_data as ( SELECT GEN_REC , VIEWER_ORG , INTEREST_REASON, MAX(INTEREST_REASON) OVER (PARTITION BY GEN_REC) as max_int_reason, OWNER_ORG, VIEWER_ORG CL_1, LEAD (VIEWER_ORG,1,0) OVER (PARTITION BY GEN_REC ORDER BY GEN_REC ,VIEWER_ORG ,INTEREST_REASON,OWNER_ORG) AS CL_2, LEAD (VIEWER_ORG,2,0) OVER (PARTITION BY GEN_REC ORDER BY GEN_REC ,VIEWER_ORG ,INTEREST_REASON,OWNER_ORG) AS CL_3, LEAD (VIEWER_ORG,3,0) OVER (PARTITION BY GEN_REC ORDER BY GEN_REC ,VIEWER_ORG ,INTEREST_REASON,OWNER_ORG) AS CL_4, RANK() OVER (PARTITION BY GEN_REC ORDER BY GEN_REC ,VIEWER_ORG ,INTEREST_REASON,OWNER_ORG) rank FROM COPY_TEST ORDER BY GEN_REC , VIEWER_ORG , INTEREST_REASON, OWNER_ORG ) SELECT t1.GEN_REC, VIEWER_ORG , INTEREST_REASON, CASE WHEN INTEREST_REASON = max_int_reason THEN (SELECT decode(cl_1,'0',null,cl_1) FROM t_data t2 WHERE rank = 1 AND t1.gen_rec = t2.gen_rec) ELSE null END cl_1, CASE WHEN INTEREST_REASON = max_int_reason THEN (SELECT decode(cl_2,'0',null,cl_2) FROM t_data t2 WHERE rank = 1 AND t1.gen_rec = t2.gen_rec) ELSE null END cl_2, CASE WHEN INTEREST_REASON = max_int_reason THEN (SELECT decode(cl_3,'0',null,cl_3) FROM t_data t2 WHERE rank = 1 AND t1.gen_rec = t2.gen_rec) ELSE null END cl_3, CASE WHEN INTEREST_REASON = max_int_reason THEN (SELECT decode(cl_4,'0',null,cl_4) FROM t_data t2 WHERE rank = 1 AND t1.gen_rec = t2.gen_rec) ELSE null END cl_4 FROM t_data t1 ; GEN_REC VIEWER_ORG INTEREST_REASON CL_1 CL_2 CL_3 CL_4 ---------------------- ---------- --------------- ---------- ---------- ---------- ---------- 12345 5AA 6543 5AA 5BB 12345 5BB 5430 32165 5AA 5430 32165 5BB 6543 5AA 5BB 5CC 32165 5CC 430 98765 5AA 0 98765 5BB 543 5AA 5BB 7 rows selected
-
Must use MERGE, COPY or UPDATE to restore data
Database:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64 bit Production
PL/SQL Release 9.2.0.4.0 - Production
CORE Production 9.2.0.3.0
Problem:
I messed up a field incorrectly updating a subset of records that should not be touched. We can not easily restore the domain, due to the backup procedure we use.
Another way to solve the problem, I want to copy the values of the Master Routing Table and place on the work order routing table.
So, theoretically, we can have 100 separate masters who serve to up to 1,000 records to date in the other table.
I can't use the standard update to do this, and I couldn't properly queries using nested in an update statement. I also have problems with the help of a merger.
This problem is not unique (I'm sure) so I need to know what I'm doing wrong.
Help, please.
Fusion:
I tried WITHOUT the unmatched WHEN & clauses insertion and the transaction does not work.MERGE INTO wo_rtg USING ( select wo_rtg.ccn, wo_rtg.mas_loc, wo_rtg.wo_num, wo.item, wo.revision, wo_rtg.wo_line, wo_rtg.operation, wo_rtg.oper_type, wo_rtg.op_fix_lt from (( wo inner join wo_rtg on ( wo.ccn = '1' and wo.mas_loc = '1' and wo.ccn = wo_rtg.ccn and wo.mas_loc = wo_rtg.mas_loc and wo.wo_num = wo_rtg.wo_num and wo.wo_line = wo_rtg.wo_line and (wo.status = 'R' or wo.status = 'I') and wo_rtg.oper_type = 'O' and wo_rtg.op_fix_lt = 5 --and wo.item = '114R2050-35' --and wo.revision = 'AD' ) ) --1 inner join routing rt on ( wo.item = rt.item and wo.revision = rt.revision and wo.ccn = rt.ccn and rt.bcr_type = 'CUR' and wo_rtg.operation = rt.operation and trim(rt.bcr_alt) is null ) ) --2 ) e ON ( wo_rtg.ccn = e.ccn and wo_rtg.mas_loc = e.mas_loc and wo_rtg.wo_num = e.wo_num and wo_rtg.wo_line = e.wo_line and wo_rtg.operation = e.operation and wo_rtg.oper_type = e.oper_type ) WHEN MATCHED THEN UPDATE SET r.op_fix_lt = e.op_fix_lt WHEN NOT MATCHED THEN insert into reason VALUES ('1','test', 'test test test','test','test','test',1,1,1,sysdate,1,sysdate,'id'); WHERE r.oper_type = 'O' and r.op_fix_lt = 5
__________________________________________________________
Update syntax:
{color: #ff0000} ORA-01427: einreihig subquery returns multiple rowsupdate wo_rtg set wo_rtg.op_fix_lt = ( select rt.op_fix_lt from (( wo inner join wo_rtg on ( wo.ccn = '1' and wo.mas_loc = '1' and wo.ccn = wo_rtg.ccn and wo.mas_loc = wo_rtg.mas_loc and wo.wo_num = wo_rtg.wo_num and wo.wo_line = wo_rtg.wo_line and (wo.status = 'R' or wo.status = 'I') and wo_rtg.oper_type = 'O' and wo_rtg.op_fix_lt = 5 --and wo.item = '114R2050-35' --and wo.revision = 'AD' ) ) --1 inner join routing rt on ( wo.item = rt.item and wo.revision = rt.revision and wo.ccn = rt.ccn and rt.bcr_type = 'CUR' and wo_rtg.operation = rt.operation and trim(rt.bcr_alt) is null ) ) --2 ) -- nested select Where (wo_rtg.ccn, wo_rtg.mas_loc, wo_rtg.wo_num, wo_rtg.wo_line, wo_rtg.operation, wo_rtg.oper_type) in ( select wo_rtg.ccn, wo_rtg.mas_loc, wo_rtg.wo_num, wo.item, wo.revision, wo_rtg.wo_line, wo_rtg.operation, wo_rtg.oper_type, wo_rtg.op_fix_lt, rt.op_fix_lt as rtlt from (( wo inner join wo_rtg on ( wo.ccn = '1' and wo.mas_loc = '1' and wo.ccn = wo_rtg.ccn and wo.mas_loc = wo_rtg.mas_loc and wo.wo_num = wo_rtg.wo_num and wo.wo_line = wo_rtg.wo_line and (wo.status = 'R' or wo.status = 'I') and wo_rtg.oper_type = 'O' and wo_rtg.op_fix_lt = 5 --and wo.item = '114R2050-35' --and wo.revision = 'AD' ) ) --1 inner join routing rt on ( wo.item = rt.item and wo.revision = rt.revision and wo.ccn = rt.ccn and rt.bcr_type = 'CUR' and wo_rtg.operation = rt.operation and trim(rt.bcr_alt) is null ) ) --2 )
{color} {color:#000000}__________________________________________________
* Just to show you an idea of what I {color: #00ff00} + really + want. * {color}
Please help! {color}update wo_rtg set wo_rtg.op_fix_lt = rt.op_fix_lt from (( wo inner join wo_rtg on ( wo.ccn = '1' and wo.mas_loc = '1' and wo.ccn = wo_rtg.ccn and wo.mas_loc = wo_rtg.mas_loc and wo.wo_num = wo_rtg.wo_num and wo.wo_line = wo_rtg.wo_line and (wo.status = 'R' or wo.status = 'I') and wo_rtg.oper_type = 'O' ) ) --1 inner join routing rt on ( wo.item = rt.item and wo.revision = rt.revision and wo.ccn = rt.ccn and rt.bcr_type = 'CUR' and wo_rtg.operation = rt.operation ) ) --2 Where wo_rtg.ccn = wo.ccn and wo_rtg.mas_loc = wo.mas_loc and wo_rtg.wo_num = wo_rtg.wo_num and wo_rtg.wo_line = wo_rtg.wo_line and wo_rtg.operation = rt.operation
I believe that the only difference in 9i (I'm on 10g) is that WHEN WITHOUT MATCHING clause is mandatory and not optional.
This is why you want to code as follows:
drop table RMT; drop table WORT; create table RMT as select 101 rout_key, 20 val from dual UNION ALL select 102 rout_key, 10 val from dual UNION ALL select 103 rout_key, -30 val from dual UNION ALL select 104 rout_key, 80 val from dual; create table WORT as select 1 pk_id, 101 rout_key, 0 val from dual UNION ALL select 2 pk_id, 101 rout_key, 0 val from dual UNION ALL select 3 pk_id, 102 rout_key, 0 val from dual UNION ALL select 4 pk_id, 102 rout_key, 0 val from dual UNION ALL select 5 pk_id, 103 rout_key, 0 val from dual UNION ALL select 6 pk_id, 103 rout_key, 0 val from dual UNION ALL select 7 pk_id, 105 rout_key, 0 val from dual; alter table WORT modify pk_id NOT NULL; merge into WORT USING (select WORT.pk_id, RMT.val from RMT, WORT where RMT.rout_key = WORT.rout_key) tmp on (WORT.pk_id = tmp.pk_id) when matched then update set WORT.val = tmp.val when not matched then insert (WORT.pk_id, WORT.rout_key, WORT.val) values (NULL, NULL, NULL); select * from WORT; drop table RMT succeeded. drop table WORT succeeded. create table succeeded. create table succeeded. alter table WORT succeeded. 6 rows merged PK_ID ROUT_KEY VAL ---------------------- ---------------------- ---------------------- 1 101 20 2 101 20 3 102 10 4 102 10 5 103 -30 6 103 -30 7 105 0 7 rows selected
Because our USING clause represents a join between the tables, it will never be a WHEN NOT MATCHED in terms. So put us in a dummy INSERT with all NULL values. I added some data to show that even with the lines without correspondence nothing will be inserted and a NOT NULL constraint on pk_id just to show that it is not checked.
-
Using Merge and collection of update/insert a table
See any problem with this, or does anyone have a better solution? I am trying to insert or update a table using the values in the collection:
I get the following fake error message:BEGIN MERGE INTO TBL d USING (select c001, c002, c003, c004,c005 from htmldb_collections where collection_name='P77_COLLECTION') s ON (d.login_id = s.c001) WHEN MATCHED THEN UPDATE SET d.case = s.c002 WHERE d.collection_type = 'Exchange' WHEN NOT MATCHED THEN INSERT TBL (d.login_id, d.case, d.work_order, d.status, d.wo_close_date, d.collection_type) VALUES (s.c001, s.c002, s.c003, s.c004, s.c005,'Exchange'); END;
ORA-06550: line 12, column 8: PL/SQL: ORA-00926: lack of keyword VALUES ORA-06550: line 4, column 1: PL/SQL: statement ignored
Thank you
-AbeYou don't have to INTO or the name of the table, just WHEN NOT MATCHED THEN INSERT (col1, col2,...) VALUES (val1, val2,...)
-
Using Merge procedure done to run forever... Guys please guide me!
I recently updated my procedure to use the merger was intended to insert the record if it is new and do nothing if the record does not exist - I want just include deltas sending us to a flat file on daily basis... .Please help below is what I wrote... but this procedure is TAKING FOR EVER to RUN
PROCEDURE INSERT_RATES_INFO (o_count NUMBER)
IS
-Variables for Procedure_log
v_proc_name VARCHAR2 (60);
v_Name VARCHAR2 (60): = ' MWATCH_SUMMARY_NCIS. INSERT_RATES_INFO';
v_action VARCHAR2 (200);
v_errors VARCHAR2 (500);
d_end_time DATE;
v_comment VARCHAR2 (40);
CURSOR rate_cur
IS
SELECT DECODE (TRIM (RATE_CODE),
"PF", "KVARH"
"ESMBM', 'ESMB."
"EMDSI", "ELECTROMUSCULAIRE."
TRIM (RATE_CODE))
RATE_CODE,
TRIM (USAGE_CODE) usage_code,
Mwatch_Common_NCIS. Season (TRUNC (FROM_DATE)) SEASON_CODE, - must be derived for our purpose
TRIM (PEAK_CODE) peak_code,
TRIM (FROM_DATE) from_date,
To__date NULL,
TO_NUMBER (TRIM (REPLACE (RATE, CHR (13)))-rate)
-"BCC."
-sysdate
OF RATES_ext
UNION
SELECT DECODE (TRIM (RATE_CODE),
"EMDB."
"PMDB.
"MCCD"
"PMDC.
"BLU"
"PREMENSTRUAL DYSPHORIC DISORDER."
"EMDE.
"B.P.ED/M.P.ED,"
"EMDH."
"PMDH."
"ELECTROMUSCULAIRE,"
"MSDP"
"EMDT."
"CDT"
"ESMB."
"PS,"
"CMHTS."
"PSMC,
"ESMD."
"PSMD."
"ESME,"
"MAWP"
"ESMH,"
"PSMH."
"SIMULATION."
"MPS."
'ESMT ',.
"MTSP")
RATE_CODE,
TRIM (USAGE_CODE) usage_code,
Mwatch_Common_NCIS. Season (TRUNC (FROM_DATE)) SEASON_CODE, - must be derived for our purpose
TRIM (PEAK_CODE) peak_code,
TRIM (FROM_DATE) fron_date,
To__date NULL,
TO_NUMBER (TRIM (REPLACE (RATE, CHR (13)))-rate)
-"BCC."
-sysdate
OF RATES_ext
WHERE TO CUT (RATE_CODE) IN
("EMDB',
"MCCD"
"BLU"
"EMDE.
"EMDH."
"ELECTROMUSCULAIRE,"
"EMDT."
"ESMB."
"CMHTS."
"ESMD."
"ESME,"
"ESMH,"
"SIMULATION."
'ESMT');
BEGIN
v_proc_name: = v_name;
v_action: = ' MWATCH_SUMMARY_NCIS refreshing. MWATCH_RATES_NCIS';
-- ******
-* REMOVE MWATCH_RATES_NCIS TABLE
-- ******
-DELETE FROM MWATCH_RATES_NCIS;
-VALIDATION;
FOR c1 IN rate_cur
LOOP
Mwatch_rates_ncis of MERGE IN one
With the HELP of mwatch_rates_ncis b
WE (a.rate_code = b.rate_code
AND a.usage_code = b.usage_code
AND a.season_code = b.season_code
AND a.from_date = b.from_date
AND a.peak_code = b.peak_code
AND a.rate = b.rate)
WHEN NOT MATCHED
THEN
INSERT (RATE_CODE,
USAGE_CODE,
SEASON_CODE, - must be derived for our purpose
PEAK_CODE,
FROM_DATE,
TO__DATE,
RATE,
FROM_SYSTEM,
CREATION_DATE)
VALUES (c1. RATE_CODE,
C1. USAGE_CODE,
C1. SEASON_CODE, - must be derived for our purpose
C1. PEAK_CODE,
C1. FROM_DATE,
C1. TO__DATE,
C1. RATE,
"BCC",
SYSDATE);
END LOOP;
COMMIT;
SELECT COUNT (*) IN O_COUNT OF MWATCH_RATES_NCIS;
EXCEPTION
WHILE OTHERS
THEN
v_action: = ' * failure * ' | v_action;
v_errors: =.
"Sql error code: '.
|| SQLCODE
|| "Sql error message: ' '.
|| SQLERRM;
mwatch_common_ncis.mwatch_log_error (v_proc_name,
v_action,
v_errors);
END INSERT_RATES_INFO;
Use the selection from the cursor instead of the B table.
Mwatch_rates_ncis of MERGE IN one
USING (select...) B
(Comparison LOGIC)
...
-
whenever I run this code I get this error
SQL Error: ORA-30926: failed to get a stable set of rows in the source tables
30926 00000 - "impossible to get a stable set of rows in the source tables.
* Cause: A stable set of rows could not be achieved due to the large dml
activity or one not deterministic where clause.
* Action: Remove any non deterministic of the clauses and reissue of the dml.
Don't know wht goes wrong!
SQL:
MERGE IN VENDORS_ACTIVE_DATE s
USING (nvl (d.VENDOR, s.VENDOR) selection of the SELLER,
NVL (d.COMPANY_CODE, s.COMPANY_CODE) COMPANY_CODE.
(case when ((d.VENDOR = s.VENDOR) and (d.COMPANY_CODE = s.COMPANY_CODE)))
)
then "MATCH".
When d.COMPANY_CODE is null
then 'DELETE '.
When s.COMPANY_CODE is null
then "INSERT."
else 'UPDATE '.
chck end)
from (select * from VENDORS_ACTIVE_DATE where COMPANY_CODE = 2) s
full outer join (select * provider where COMPANY_CODE = 2) d
on (d.COMPANY_CODE = s.COMPANY_CODE AND s.COMPANY_CODE = 2)
) d
WE (d.COMPANY_CODE = s.COMPANY_CODE AND d.chck in ('UPDATE', 'GAME', 'DELETE'))
WHEN MATCHED THEN
UPDATE SET s.VENDOR = d.VENDOR
WHERE d.chck in ('UPDATE', 'DELETE')
DELETE WHERE d.chck = 'DELETE '.
WHEN NOT MATCHED THEN
INSERT (SELLER, COMPANY_CODE)
VALUES (d.VENDOR, d.COMPANY_CODE)
Work request: (deleted the duplicate data in tables (source and target))
MERGE IN VENDORS_ACTIVE_DATE s
USING (nvl (d.VENDOR, s.VENDOR) selection of the SELLER,
NVL (d.ACTIVEDATE, s.ACTIVEDATE) ACTIVEDATE.
NVL (d.COMPANY_CODE, s.COMPANY_CODE) COMPANY_CODE.
(case when ((d.VENDOR = s.VENDOR))
- AND D.ACTIVEDATE = S.ACTIVEDATE
and NVL (d.ACTIVEDATE, trunc (sysdate)) = NVL (s.ACTIVEDATE, trunc (sysdate))
and (d.COMPANY_CODE = s.COMPANY_CODE)
)
then "MATCH".
When d.COMPANY_CODE is null
then 'DELETE '.
When s.COMPANY_CODE is null
then "INSERT."
else 'UPDATE '.
chck end)
from (select * from suppliers where COMPANY_CODE = 2) d
full outer join (select * from vendors_active_date where COMPANY_CODE = 2) s
on (d.COMPANY_CODE = s.COMPANY_CODE and s.vendor = d.vendor)
) d
WE (d.COMPANY_CODE = s.COMPANY_CODE AND d.VENDOR = s.VENDOR AND d.chck in ('UPDATE', 'GAME', 'DELETE'))
WHEN MATCHED THEN
S.ACTIVEDATE = UPDATE SET d.ACTIVEDATE
WHERE d.chck in ('UPDATE', 'DELETE')
DELETE WHERE d.chck = 'DELETE '.
WHEN NOT MATCHED THEN
INSERT (VENDOR, ACTIVEDATE, COMPANY_CODE)
VALUES (d.VENDOR, d.ACTIVEDATE, d.COMPANY_CODE)
-
Update or merge it with the return data
Hello, I want to do an update in a single statement, and select (I want to get the data and update a field in one of the tables involved with a timestamp), I tried this:
merge into table t
using (SELECT ... a long and complex select...) e
on (e.ID = t.ID)
When matched then
update the value t.ts = systimestamp
e return
It does not work because his return does not seem possible with the merger, he did the update but I get no data...
With an update, I tried:
Update
(
SELECT...) e
Aliens set = systimestamp
And I get ORA-01779: cannont change a column that maps to a table of key-preserver nonkey.
The select is complex with many paintings and selects involved and more than 20 KB of text only select... and this isn't mine so I want a solution that does not need to change the internal selection if possible.
Any ideas? Sorry for my limited knowledge of sql :-(
No, you did not read what I said. The RETURNING clause allows you to capture the details of the update table. You may not have the details of the complex query that you use to determine the return lines. There is no way in SQL to a single statement that updates a table and queries data from other tables at the same time.
The best you're going to manage is to update the data, turning the ID (or regardless of the primary key is appropriate) and then query the query data complex where once again the ID in your collection. However, it's really messy. What US the real purpose of all this?
-
Sequence using merge or other alternative
Hello
I have the following table, wherein a SUBS_ID is unique but INDEX_ID is not and REQUEST_ID is initially null for all records.
The table can be large (~ 1 M lines) and even though there might be several SUBS_ID with INDEX_ID even - most of the records have 1 to 1 relationship.
CREATE GLOBAL TEMPORARY TABLE SUBS_HIERARCHY_TEMP ( SUBS_ID NUMBER(10) NOT NULL, INDEX_ID NUMBER(10) NOT NULL, REQUEST_ID NUMBER(10) ) ON COMMIT DELETE ROWS;
I have the code which assigns a unique number (REQUEST_ID) to each separate INDEX_ID using a sequence (this code can run in parallel and I REQUEST_ID must be unique in the world):
... cursor Request_id_cur is select distinct INDEX_ID from SUBS_HIERARCHY_TEMP; ... begin ... -- fill SUBS_HIERARCHY_TEMP with records, doesn't matter how, REQUEST_ID remains NULL -- populate REQUEST_ID with a sequence for SUB in Request_id_cur LOOP v_UniqeIndex := SEQ_REQUEST_ID.nextval; Update SUBS_HIERARCHY_TEMP set REQUEST_ID = v_UniqeIndex where INDEX_ID = SUB.INDEX_ID; END LOOP; ... end;
It works - but obviously not very efficient. If all the records are 1-1 going to run updates of 1 M, but I can't use a simple update in case somewhere SUBS_ID INDEX_ID even therefore need to have the same REQUEST_ID.
I tried to do it in one go using a merge statement, but apparently the sequences are not allowed in the USING clause of the merger:
merge into SUBS_HIERARCHY_TEMP tab using (select INDEX_ID, SEQ_REQUEST_ID.nextval as REQUEST_ID from (select distinct INDEX_ID from SUBS_HIERARCHY_TEMP) )tmp on (tab.INDEX_ID=tmp.INDEX_ID) when matched then update set REQUEST_ID=tmp.REQUEST_ID;
ORA-02287: sequence number not allowed here
Any ideas how to make in a single statement and avoid the loop?
I'm on 11.2.0.3 RHEL6 64bits.
Thanks in advance.
drop table SUBS_HIERARCHY_TEMP purge; CREATE GLOBAL TEMPORARY TABLE SUBS_HIERARCHY_TEMP ( SUBS_ID NUMBER(10) NOT NULL, INDEX_ID NUMBER(10) NOT NULL, REQUEST_ID NUMBER(10) ) ON COMMIT DELETE ROWS; drop sequence seq; create sequence seq; drop type tt_subs_rec / create or replace type t_subs_rec as object( SUBS_ID NUMBER(10), INDEX_ID NUMBER(10), REQUEST_ID NUMBER(10) ) / create type tt_subs_rec as table of t_subs_rec / create or replace function sub_hierarchy_update return tt_subs_rec pipelined as l_subs_rec t_subs_rec := t_subs_rec(null,null,null); prev_INDEX_ID SUBS_HIERARCHY_TEMP.INDEX_ID%type := -9999999; l_request_id SUBS_HIERARCHY_TEMP.REQUEST_ID%type; begin for rec in ( select subs_id, index_id, request_id from SUBS_HIERARCHY_TEMP order by index_id ) loop if prev_INDEX_ID < rec.index_id then prev_INDEX_ID := rec.index_id; l_request_id := seq.nextval; end if; l_subs_rec.subs_id := rec.subs_id; l_subs_rec.INDEX_ID := rec.INDEX_ID; l_subs_rec.request_id := l_request_id; pipe row(l_subs_rec); end loop; return; end sub_hierarchy_update; / insert into SUBS_HIERARCHY_TEMP select level, mod(level-1,3)+1, null from dual connect by level <= 9; select * from subs_hierarchy_temp;
SUBS_ID INDEX_ID REQUEST_ID 1 1 2 2 3 3 4 1 5 2 6 3 7 1 8 2 9 3 select * from table(sub_hierarchy_update);
SUBS_ID INDEX_ID REQUEST_ID 4 1 1 1 1 1 7 1 1 2 2 2 5 2 2 8 2 2 3 3 3 6 3 3 9 3 3 -
Update using sub query behavior
I have two table with parents relationship child
script for the same are:-
create table pt (number);
create table pt_ch (number b, a);
Insert into pt values (1);
insert into pt_ch values (2,1).
insert into pt_ch values (3,1);
insert into pt_ch values (4.2);
When I execute the below the update statement, it is showing three line Update where as a condition based on I expect two rows to get the update.
in this case for the third row that does not it updates with null, can you please tell me, why this behaves like that
Update pt_ch set b = (select one of pt
where pt.a = pt_ch.a);
Select * from pt_ch;
If there is no WHERE clause in an UPDATE statement, the update occurs on all lines. No matching rows are updated with the value NULL. This is the reason why you must always include the WHERE clause in an UPDATE STATEMENT. Try this
Update pt_ch
b the value = (select one of pt where pt.a = pt_ch.a)
where exists (select null from pt where pt.a = pt_ch.a);
or
merge into pt_ch
using pt
on (pt.a = pt_ch.a)
When matched then
update set pt_ch.b = pt.a;
-
IKM oracle additional update (plsql), (merge)
Hi Experts,
When I was loading the data in the target that I used kms free of charge but I cannot parse the difference
between IKM INCREMENTAL UPDATE (PLSQL) ORACLE, IKM ORACLE ADDITIONAL UPDATE (MERGE)
When and which scenario we're going for the km of, please guide me
Concerning
clarriiza
Hi clarriiza,
best KM of data transfer from the Oracle table to Oracle table
CKM Oracle
LKM Oracle to Oracle (DBLink)
IKM Oracle additional Update (MERGE)
in this merger IKM we merge statement that will make both a single statement (insert/update) activity.
No idea about Oracle IKM update (PLSQL) incremental km because I never used this KM
Kind regards
Phanikanth
Maybe you are looking for
-
NB200-10z heated at high temperature
See screenshot:https://i.tinyuploads.com/REgsQ7.jpg Temperature is really high. My fan is also STOPPED. I use an external fan on the cushion. I'm living in Pakistan, there are no Toshiba service center. So advise me what I have to do?
-
Satellite 1410-303-the s key is blocked
Hello, I have a * Toshiba Satellite 1410 303 * and the "s" key is annoying me a lot. It does not work either, it keeps on himself. I must + ESC + to stop it. Should I clean under the keyboard? And how there? Please answer 4!
-
Double Win XP and Win 7 boot system__
How to install a dual boot xp and win 7 installation
-
using photoshop 5 after leaving creative cloud
I currently use LR4 and PS5. I just bought a Fujifilm XT1 which has a format of the RAF, which is not supported in my versions of LR4 or PS5. I've probably subscribe to creative cloud. My new images are saved in the cloud where I can store them local
-
What is the available method to create db using dbca in exadata?
I would like your advice.