Problem in the Merge statement
Hi allI use the merge updated statement 30000 records of tables having 55 records of Lakes.
But it takes a lot of time as I kill the session after 12 hours, as it was still ongoing.
So, the same day I m using cursors, it will end in less than 3 hours.
I used merge is: -.
MERGE IN Table1 a
USING (SELECT MAX (TO_DATE (TO_CHAR (contact_date, "dd/mm/yyyy")
|| contact_time,
"jj/mm/aaaa HH24:Mi:SS".
)
) m_condate,.
appl_id
FROM Table2 b,.
(SELECT DISTINCT acc_no acc_no
IN table 3, Table1
WHERE acc_no = appl_id AND delinquent_flag = 'Y '.
AND financier_id = 'NEWACLOS') d
WHERE d.acc_no = b.appl_id
AND (contacted_by IS NOT NULL
OR followup_branch_code IS NOT NULL
)
GROUP BY appl_id) c
WE (a.appl_id = c.appl_id AND a.delinquent_flag = 'Y')
WHEN MATCHED THEN
UPDATE
SET last_contact_date = c.m_condate;
In this query, table 1 has 30000 documents and table 2 and table 3 have records 3670955 and 555674 respectively.
Please suggest, what I'm doing wrong with merger, because according to my understanding merge statement is much better than the updates or updates using cursors.
Required info is as follows:
SQL > show the user_dump_dest parameter
VALUE OF TYPE NAME
------------------------------------ ----------- ------------------------------
user_dump_dest string/opt/oracle/admin/FINCLUAT/udu
MP
SQL > show parameter optimizer
VALUE OF TYPE NAME
------------------------------------ ----------- ------------------------------
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 10.2.0.4
optimizer_index_caching integer 0
OPTIMIZER_INDEX_COST_ADJ integer 100
the string ALL_ROWS optimizer_mode
optimizer_secure_view_merging Boolean TRUE
SQL > show parameter db_file_multi
VALUE OF TYPE NAME
------------------------------------ ----------- ------------------------------
db_file_multiblock_read_count integer 16
SQL > show parameter db_block_size
VALUE OF TYPE NAME
------------------------------------ ----------- ------------------------------
Whole DB_BLOCK_SIZE 8192
SQL > column sname format a20
SQL > column pname format a20
SQL > column pval2 format a20
SQL > select
2 sname,
3 pname,
pval1 4,.
5 pval2
6 of
7 sys.aux_stats$;
sys.aux_stats$
*
ERROR on line 7:
ORA-00942: table or view does not exist
Elapsed time: 00:00:00.05
SQL > explain the plan for
2 - Put your statement here
3 MERGE IN one cs_case_info
4 USE (SELECT MAX (TO_DATE (TO_CHAR (contact_date, "dd/mm/yyyy")
5 || contact_time,
6 'dd/mm/yyyy HH24:Mi:SS.
7 )
(8) m_condate,
9 appl_id
CS_CASE_DETAILS_ACLOS 10 b,
11 (SELECT DISTINCT acc_no acc_no
12 OF NEWACLOS_RESEARCH_HIST_AYLA, cs_case_info
13 WHERE acc_no = appl_id AND delinquent_flag = 'Y '.
14 AND financier_id = "NEWACLOS") d
15 WHERE d.acc_no = b.appl_id
16 AND (contacted_by IS NOT NULL
17 GOLD followup_branch_code IS NOT NULL
18 )
C 19 GROUP BY appl_id)
20. WE (a.appl_id = c.appl_id AND a.delinquent_flag = 'Y')
21. WHEN MATCHED THEN
UPDATE 22
23 SET last_contact_date = c.m_condate
24;
He explained.
Elapsed time: 00:00:00.08
SQL > select * from table (dbms_xplan.display);
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | TempSpc | Cost (% CPU).
--------------------------------------------------------------------------------------------------
| 2 > MERGE STATEMENT | 47156 | 874K | 128K (1) |
| 1. MERGE | CS_CASE_INFO |
| 2. VIEW |
| 3. HASH JOIN | 47156 | 36 M | 5672K | 128K (1) |
| 4. VIEW | 47156 | 5111K | 82339 (1) |
| 5. GROUP SORT BY | 47156 | 4236K | 298 M | 82339 (1) |
| 6. HASH JOIN | 2820K | 247 M | 10 M | 60621 (1) |
| 7. HASH JOIN | 216K | 7830K | 6985 (1) |
| 8. VIEW | the index $ _join$ _012 | 11033. 258K | 1583 (1) |
| 9. HASH JOIN |
| 10. INDEX RANGE SCAN | IDX_CCI_DEL | 11033. 258K | 768 (1) |
| 11. INDEX RANGE SCAN | CS_CASE_INFO_UK | 11033. 258K | 821 (1) |
| 12. FULL RESTRICTED INDEX SCAN FAST | IDX_NACL_RSH_ACC_NO | 5539K | 68 M | 5382 (1) |
| 13. TABLE ACCESS FULL | CS_CASE_DETAILS_ACLOS | 3670K | 192 M | 41477 (1) |
| 14. TABLE ACCESS FULL | CS_CASE_INFO | 304K | 205 M | 35975 (1) |
--------------------------------------------------------------------------------------------------
Note
-----
-"PLAN_TABLE' is old version
24 selected lines.
Elapsed time: 00:00:01.04
SQL > rollback;
Complete restoration.
Elapsed time: 00:00:00.03
SQL > set autotrace traceonly arraysize 100
SQL > alter session set events 10046 name context forever, trace level 8';
ERROR:
ORA-01031: insufficient privileges
Elapsed time: 00:00:00.04
SQL > disconnect
Disconnected from the database to Oracle 10 g Enterprise Edition Release 10.2.0.4.0 - Production 64-bit
With partitioning, OLAP, Data Mining and Real Application Testing options
SQL > spool off
Published by: user4528984 on May 5, 2009 22:37
Create indexes for tables. CS_CASE_DETAILS_ACLOS, CS_CASE_INFO
also try to use the underside of suspicion
(SELECT / * + no_merge * / SEPARATE acc_no acc_no)
IN table 3, Table1
HTH
Tags: Database
Similar Questions
-
Problem with the MERGE statement
Hi all
We'll cover the following:
create table xx_test1 (invoice_id number, line_group_number number, LINE_TYPE_LOOKUP_CODE VARCHAR2(25) ,LINE_NUMBER NUMBER(15) );
Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,1,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,1,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,2,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,2,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,3,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,3,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,4,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,4,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,5,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,5,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,12,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,12,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,7,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,7,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,8,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,8,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,9,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,9,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,10,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,10,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,11,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,11,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,12,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,12,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,13,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,13,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,14,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,14,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,15,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,15,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,16,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,16,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,17,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,17,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,18,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,18,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,19,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,19,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,20,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,20,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,21,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,21,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,22,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,22,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,23,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,23,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,24,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,24,'TAX',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,25,'ITEM',null); Insert into XX_TEST1 (INVOICE_ID,LINE_GROUP_NUMBER,LINE_TYPE_LOOKUP_CODE,LINE_NUMBER) values (131549,25,'TAX',null);
So, if we want to MERGE this table and update the lines with below:
merge into xx_test1 DST USING (SELECT LINE_GROUP_NUMBER, LINE_TYPE_LOOKUP_CODE, ROW_NUMBER() over(order by LINE_TYPE_LOOKUP_CODE, LINE_GROUP_NUMBER) as LINE_NUM from xx_test1 where INVOICE_ID = 131549 ) SRC ON (DST.LINE_GROUP_NUMBER = SRC.LINE_GROUP_NUMBER AND dst.LINE_TYPE_LOOKUP_CODE = src.LINE_TYPE_LOOKUP_CODE AND dst.invoice_id = 131549 ) WHEN MATCHED THEN update set DST.LINE_NUMBER = SRC.LINE_NUM ;
I get an error message: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.
I don't know why I'm getting this. Any ideas?
Version: 11g
Kind regards
Alex
whenever I have this error I convert my fusion in a select to see what is duplication
select dst.LINE_GROUP_NUMBER, dst.LINE_TYPE_LOOKUP_CODE, count(*) from xx_test1 DST join (SELECT LINE_GROUP_NUMBER, LINE_TYPE_LOOKUP_CODE, ROW_NUMBER() over(order by LINE_TYPE_LOOKUP_CODE, LINE_GROUP_NUMBER) as LINE_NUM from xx_test1 where INVOICE_ID = 131549 ) SRC ON (DST.LINE_GROUP_NUMBER = SRC.LINE_GROUP_NUMBER AND dst.LINE_TYPE_LOOKUP_CODE = src.LINE_TYPE_LOOKUP_CODE AND dst.invoice_id = 131549 ) group by dst.LINE_GROUP_NUMBER, dst.LINE_TYPE_LOOKUP_CODE having count(*) > 1
you have 2 dst. LINE_GROUP_NUMBER, summer time. Combination of LINE_TYPE_LOOKUP_CODE this duplication.
-
Error in the Merge statement using dblink
Hello
I am facing the following error when you use the merge statement using the dblink.
ORA-02069: global_names must be set to true for this operation parameter.
I can use the same dblink in my select insert and update statements but when I try to use merge then he invites the error said, is also not any syntax error as same statement can be used on the same tables of database instead of dblink.
Please suggest any help will be much appreciated.
Thanks in advance
Hi Aqeel
If insert and update statements work well through links db, then it should not be a problem with the merge statement. But if you are faced with the question, so please check the entire sql statement with tnsnames on both sides. Please share the tnsnames for the two dbs with dblink ddl.
Concerning
Jihane Narain Sylca
-
Different result by using the MERGE statement
I have 2 SQL statements:
MERGE INTO PT_CQS_AGGR APC
With the HELP of PT_CQS_AGGR_TEMP Lady
WE (concat (concat(pca.from_city_id,pca.to_city_id), pca.query_timestamp_hh) = concat (concat(pcah.from_city_id,pcah.to_city_id), pcah.query_timestamp_hh))
WHEN MATCHED THEN
Setting a DAY SET pca.search_count = pca.search_count + pcah.search_count
WHEN NOT MATCHED THEN
VALUES of INSERTION (to_city_id, query_timestamp_hh, from_city_id, search_count) (pcah.from_city_id, pcah.to_city_id, pcah.query_timestamp_hh, pcah.search_count);
AND
MERGE INTO PT_CQS_AGGR APC
With the HELP of PT_CQS_AGGR_TEMP Lady
WE (pca.from_city_id = pcah.from_city_id AND pca.to_city_id = pcah.to_city_id AND pca.query_timestamp_hh = pcah.query_timestamp_hh)
WHEN MATCHED THEN
Setting a DAY SET pca.search_count = pca.search_count + pcah.search_count
WHEN NOT MATCHED THEN
VALUES of INSERTION (to_city_id, query_timestamp_hh, from_city_id, search_count) (pcah.from_city_id, pcah.to_city_id, pcah.query_timestamp_hh, pcah.search_count);
First statement correctly the merged data, but use FULL TABLE SCANS, so it's rather slow. Second statement using a UNIQUE INDEX on the columns from_city_id, to_city_id, and query_timestamp_hh on the MAP of EXPLAIN, but during the execution of I've got ORA-00001: unique constraint (PODOWNER. IDX_CQS_AGGR_3COL) violated. What is the problem with the second statement - especially with this line:
WE (pca.from_city_id = pcah.from_city_id AND pca.to_city_id = pcah.to_city_id AND pca.query_timestamp_hh = pcah.query_timestamp_hh) Can I use a more complex condition in the MERGE statement? Because it seems that not all the conditions have been taken...
???
Select pcah.from_city_id, pcah.to_city_id, PT_CQS_AGGR_TEMP Lady pcah.query_timestamp_hh
less
Select pca.from_city_id, pca.to_city_id, pca.query_timestamp_hh PT_CQS_AGGR pca
somewhere the conditions limiting the time.
(or whatever the columns make up the stress of failing)
In addition, select for each column in the constraint of failure where the column is null. If one of these columns is null, equality fails, even if both are null, because null <> null. So you will get a "no match" if all values are the same and it is set to null.
Edit: Oh, slap forehead, that is why one works and the complete analysis. As SomeoneElse said, it normalizes the type of data and concatenates, comparison null to no effect and refusing all usual index.
-
problem compiling with MERGE statement
What is the problem with this merge statement?
When I compile I get the message
met symbol IN when one of the following expected
*:= . (@ %; < a SQL > *)
MERGE INTO PF_REP_TEMP HAS
WITH THE HELP OF PF_REP_SKS B
WE (a. pf_userid = "FINP' AND B.pfbatch = 'F99' and B.pfstfno = A.pf_staffno
and B.pfcc = "7" and B.pftransmy = A.mmyy and B.slno = A.s_no)
When matched then
game update
a.pfwdrlm = b.pfwdrlm,
a.PFRC = b.PFRC;
Help, please
(version of the form is 10g, 11g database version)How to perform a merge into forms button pressed trigger command
-
Get error in the merge statement
Version of Oracle, Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production
Hi gurusI am trying to perform the merge statement using the clause, but I get the error message, see below my sample data:
Examples of data
DROP TABLE OF BILLING;
DROP TABLE GROUP_MST;
DROP TABLE age_max;
CREATE ARRAY OF BILLING
(
BILLING_ID NUMBER (5),
RATE NUMBER (5),
MAXIMUM_AGE NUMBER (5),
package_id NUMBER (5)
);
INSERT
IN BILLING
(SELECT 11,1,10,100 FROM DUAL
UNION ALL
SELECT 12,2,15,100 FROM DUAL
UNION ALL
SELECT 13,3,20,100 FROM DUAL
);
CREATE TABLE GROUP_MST
(group_number NUMBER (5), package_id NUMBER (5))
);
INSERT INTO GROUP_MST
(SELECT DOUBLE 5 000 100
);
-------
CREATE TABLE AGE_MAX
(group_number NUMBER (5), max_age NUMBER (5))
);
INSERT
IN AGE_MAX
(SELECT 5000,60 FROM DUAL
);
Merge statement
MERGE INTO DRC USING billing
(WITH datum1 AS
(SELECT A.group_number,
b.billing_id,
b.rate,
b.maximum_age,
b.package_id
OF group_mst A,.
b billing
WHERE A.package_id = b.package_id
),
datum2 AS
(SELECT max_age, group_number FROM age_max
)
SELECT * FROM A, b WHERE A.group_number = b.group_number datum2 datum1
)
CBC ON (drc.billing_id = src.billing_id)
WHEN MATCHED THEN
UPDATE SET drc.maximum_age = src.max_age - 1;
Error
Error from the 33 in the command line:
MERGE INTO DRC USING billing
(WITH datum1 AS
(SELECT A.group_number,
b.billing_id,
b.rate,
b.maximum_age,
b.package_id
OF group_mst A,.
b billing
WHERE A.package_id = b.package_id
),
datum2 AS
(SELECT max_age, group_number FROM age_max
)
SELECT * FROM A, b WHERE A.group_number = b.group_number datum2 datum1
)
CBC ON (drc.billing_id = src.billing_id)
WHEN MATCHED THEN
UPDATE SET drc.maximum_age = src.max_age - 1
Error in the command line: 50 column: 1
Error report:
SQL error: ORA-00918: column ambiguously defined
00918 00000 - "ambiguously defined column.
* Cause:
* Action:
Thanks in advance
Concerning
Shu
WITH datum1 AS (SELECT A.group_number,
b.billing_id,
b.rate,
b.maximum_age,
b.package_id
OF group_mst A, b billing
WHERE A.package_id = b.package_id),
datum2 AS (SELECT max_age, group_number FROM age_max)
SELECT A.*, b.max_age, b.group_number as group_number_b - ERROR HERE
OF datum1 A, b datum2
WHERE A.group_number = b.group_number
-
Return in the MERGE statement clause
Hello
I use Oracle 10 g Version
I tried the code using UPDATE with return Clause & MERGER with return below Clause.
I have not found ANY error while working with the UPDATE statement. Here is the code with the UPDATE statement
DECLARE TYPE empno_list IS TABLE OF emp.empno%TYPE; vempno_list empno_list; BEGIN UPDATE emp SET comm = 11 WHERE deptno IN (SELECT deptno FROM dept) RETURNING empno BULK COLLECT INTO vempno_list; FOR i IN vempno_list.FIRST .. vempno_list.LAST LOOP DBMS_OUTPUT.put_line ('Values of EMP ' || vempno_list (i)); END LOOP; END;
But PL/SQL error: ORA-00933: SQL not correctly completed command when you work with the MERGE statement
declare type empno_list is table of emp.empno%type; vempno_list empno_list; begin merge into emp tgt using dept src on (src.deptno =tgt.deptno) when matched then update set tgt.comm=12 returning tgt.empno bulk collect into vempno_list ; for i in vempno_list.first .. vempno_list.last loop dbms_output.put_line('Values of EMP '||vempno_list(i) ) ; end loop; end;
Please suggest me
Probably because BACK IN clause does not belong to the MERGE statement. It is available only for INSERT, UPDATE, and DELETE. Here's the quote from Oracle Documentation:
The static method
RETURNING
INTO
article belongs to aDELETE
,INSERT
, orUPDATE
statement. The dynamicRETURNING
INTO
article belongs to aEXECUTE
IMMEDIATE
statement.And here is the link.
It will be useful.
Ishan
-
Question about the MERGE statement
Hi all
I have a small question... I can post code, table creation, etc... but I think this question can be able to be simply answered, if I explain it. If you want me to zip codes, etc... then just ask and I'll do it.
Here it goes:
I have a set up merge statement, and I have two columns. One is named ADD_DT, and the other is called LST_UPD_DT.
Update in the merge statement, the LST_UPD_DT column is updated with the SYSDATE.
When it is inserted in the merge statement, the ADD_DT column is updated with the SYSDATE.
So, here is my question:
Regardless of whether or not the information is updated, the LST_UPD_DT updates the SYSDATE every time. Any advice on how to update the LST_UPD_DT column only if information is changed/updated, so that the information is not changed would be not updated by the SYSDATE? I hope that this question was not too complicated.
Thank you all and if you want to see the code or examples of table... Please ask and I'll post one. I just thought that this may be able to meet without it.Hello
991769 wrote:
OK, here's what the table looks like:Thank you.
CREATE TABLE TBL_SUPPLIERS ( SUPP_CD VARCHAR2(40 CHAR), SUPP_NM VARCHAR2(255 CHAR), ADD_DT VARCHAR2(50 CHAR), LST_UPD_DT VARCHAR2(50 CHAR))
Do not use a VARCHAR2 column for date information. Use a DATE column.
CREATE TABLE D_SUPPLIERS ( SUPP_CD VARCHAR2(40 CHAR), SUPP_NM VARCHAR2(255 CHAR))
INSERT INTO TBL_SUPPLIERS VALUES (1234, MINING, '03-26-2013 3:33:49 PM', '04-02-2013 9:04:52 AM'); INSERT INTO TBL_SUPPLIERS VALUES (2345, ELECTRIC, '03-26-2013 3:33:49 PM', '04-02-2013 9:04:52 AM'); INSERT INTO TBL_SUPPLIERS VALUES (3456, COAL, '03-26-2013 3:33:49 PM', '04-02-2013 9:04:52 AM');
You want people to view the solutions that actually work? Please make sure that your own instructions will actually work. Test and fix your code before posting.
All INSERT statements you posted fail; You seem to be missing single quotes around string literals. I think you meant:INSERT INTO TBL_SUPPLIERS VALUES (1234, 'MINING', '03-26-2013 3:33:49 PM', '04-02-2013 9:04:52 AM'); ...
Here's one way:
MERGE INTO tbl_suppliers sm USING ( SELECT d.* FROM d_suppliers d LEFT OUTER JOIN tbl_suppliers t ON t.supp_cd = d.supp_cd WHERE t.supp_cd IS NULL OR DECODE (t.supp_nm, d.supp_nm, 0, 1) = 1 ) ds ON (sm.supp_cd = ds.supp_cd) WHEN MATCHED THEN UPDATE SET sm.supp_nm = ds.supp_nm, sm.lst_upd_dt = SYSDATE WHEN NOT MATCHED THEN INSERT (sm.supp_cd, sm.supp_nm, sm.add_dt) VALUES (ds.supp_cd, ds.supp_nm, SYSDATE); SELECT * FROM tbl_suppliers ORDER BY SUPP_CD;
This can be more efficient, because it does not generate redo, or triggers, when two tables have exactly the same line.
-
Person registering in the Merge statement error!
Is it possible to save indivudual error in the MERGE statement (Update / Insert).
I'm unable to save these error. instead of MERGING, if I update the table in the cursor loop then I am able to record the individual error but the process takes time.
Thanks in advance.
DebaHi Deba,
Logging of DML errors:
SQL> create table tab1 (x number(1)); Table created. SQL> exec dbms_errlog.create_error_log('tab1') PL/SQL procedure successfully completed. SQL> SQL> merge into tab1 t 2 using (select 1 x from dual union all 3 select 112 x from dual) s 4 on (t.x = s.x) 5 when not matched 6 then insert (x) values (s.x) 7 log errors into err$_tab1 reject limit unlimited; 1 row merged. SQL> SQL> COL x for 9999 SQL> select * from tab1; X ----- 1 SQL> COL x for a4 SQL> select ora_err_number$, X from err$_tab1; ORA_ERR_NUMBER$ X --------------- ---- 1438 112 SQL>
Concerning
Peter -
insert/update County in the merge statement
In the Merge statement, we can count the number of inserted rows and updated?
ROWCOUNT SQL % simply returns the number of rows merged.
It does not tell us the separately the line inserted and updated.# To insert the rowcount is the number of inserted rows for update is the number of rows updated, for the merger, that's the number of merged lines.
-
need help with the Merge statement
I'm on: Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production
I'm currently an UPDATE statement and then it works and is accurate, it takes 30 minutes. I heard that MERGE
can do the same thing and is just as accurate and much faster!
Here's the query I want to convert into a MERGE INTO statement. I tried to do it myself, but I get errors and don't know simply, since it's new for me.
Basically I want to update table your on a corresponding condition in the table tt for 2 columns (GTP and UPDATE_DT), for UPDATE_DT I want to insert the Date current system.
Thank you!UPDATE /*+ PARALLEL (16) */ OLDER_Table ta SET (ta.GTP, ta.UPDATE_DT) = (SELECT /*+ PARALLEL (16) */ tt.GTP, SYSDATE FROM NEWER_Table tt WHERE ta.cust_id = tt.cust_id AND ta.STAMP_DATE = tt.STAMP_DATE AND ROWNUM = 1) WHERE EXISTS (SELECT 1 FROM NEWER_Table tt WHERE ta.cust_id = tt.cust_id AND ta.STAMP_DATE = tt.STAMP_DATE AND (NVL(ta.GTP, 'X') != NVL(tt.GTP, 'X')));
Hello
Whenever you have a problem, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) of all of the tables involved.
Also post the results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.
If you ask on a DML statement, such as UPDATE, CREATE TABLE and INSERT statements need to re - create the tables as they are before the DML, and results will be the content of the or the tables changed when it's all over.
See the FAQ forum {message identifier: = 9360002}MERGE peut be much faster than update; Sometimes, there is no significant difference in speed.
Tables in multiple situations like this, I've never seen a case where the MERGER has been slower than the UPDATE, even if the UPDATE is sometimes easier to code and just as fast.Maybe that's what you want:
MERGE INTO older_table dst USING ( SELECT n.cust_id , n.stamp_date , n.gtp , ROW_NUMBER () OVER ( PARTITION BY n.cust_id , n.stamp_date ORDER BY n.gtp ) AS r_num FROM newer_table n JOIN older_table o ON n.cust_id = o.cust_id AND n.stamp_date = o.stamp_date AND NVL ( n.gtp , 'X' ) != NVL ( o.gtp , 'X' ) ) src ON ( src.cust_id = dst.cust_id AND src.stamp_date = dst.stamp_date AND src.r_num = 1 ) WHEN MATCHED THEN UPDATE SET dst.gtp = src.gtp , dst.update_date = SYSDATE ;
As I can't test it, I can't be sure.
-
ORA 22813 in the merge statement
Hi the gems... Good afternoon...
My version of the database is 11.2.0.1.0 Solaris 64-bit OS.
I am facing a ' ORA-22813: value of the operand exceeds the limits of the system "during the execution of a procedure.
I used loggers and found that it is getting failed in a MERGE statement.
This merge statement is used to merge a table with a collection. the code is as below:
Function GET_BALANCE_HIST (V_MERGE_REC) parameter is an array type.MERGE /*+ INDEX(P BALANCE_HISTORIC_INDEX) */ INTO BALANCE_HOLD_HISTORIC P USING TABLE(GET_BALANCE_HIST(V_MERGE_REC)) M ON (P.CUSTOMER_ID = M.CUSTOMER_ID AND P.BOOK_ID = M.BOOK_ID AND P.PRODUCT_ID = M.PRODUCT_ID AND P.SUB_BOOK_ID = M.SUB_BOOK_ID AND) WHEN MATCHED THEN UPDATE <set .....> WHEN NOT MATCHED THEN INSERT<.....>
Now GET_BALANCE_HIST (V_MERGE_REC) is a function in the pipeline and we used that because the V_MERGE_REC collection can become huge with data.
This process worked very well since the beginning, but since yesterday, it was constantly throwing 22813 ORA error in this line.
Help, please... Thanks in advance...Gogol wrote:
The code flow is as below:There is a sql query, the output is a set of some several lakes of records. Now we take the result of the sql query in a collection with a limit of 1000 (FETCH cur_sql COLLECT LOOSE v_balance_rec LIMIT 1000). Then we do a lot of processing, the calculation of this collection.
After the treatment and calculation, we are filling another collection this collection transformed (V_BALANCE_REC) (V_MERGE_REC). Thus, if the loop iterates for 1000 times, then the V_MERGE_REC is filled with records of 1000 * 500 = 500000 processed.
And then we go to this huge V_MERGE_REC collection as a parameter to this function.
Don't know what are the Lakes. Please use International English.
Why can't do you math in a SQL query?
If it's really too hard to do in SQL (SQL queries can perform a treatment fairly complex), then I would look to Scripture
results of a table and use it. -
Unique constraint shot while refreshing in the MERGE statement.
Hi guys
I have a question that I can't solve. Would appreciate any help on this. The configuration of the data and the script is as below.
Can someone help me please to solve this as the actual code that I am developing has the same configuration and I am constantly getting this error. As long as the same record does not come to the top in the 'source' table, MERGE performs an update or an insert.SQL*Plus: Release 10.2.0.1.0 - Production on Wed May 4 11:46:02 2011 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production With the Partitioning, OLAP and Data Mining options SQL> create table table_1 (id number, id_name varchar2(20)); Alter table table_1 add primary key(id); create table table_2 (id number, id_name varchar2(20)); insert into table_2 values (1, 'id_1'); insert into table_2 values (2, 'id_2'); insert into table_2 values (1, 'id_1_upd'); SQL> select * from table_1; no rows selected SQL> select * from table_2; ID ID_NAME ---------- -------------------- 1 id_1 2 id_2 1 id_1_upd SQL> SQL> merge into table_1 target 2 using (select id, 3 id_name 4 from table_2) source 5 on (source.id = target.id) 6 when matched then 7 update set target.id_name = source.id_name 8 when not matched then 9 insert(id, 10 id_name) 11 values(source.id, 12 source.id_name); merge into table_1 target * ERROR at line 1: ORA-00001: unique constraint (SYS_C00137508) violated SQL> ed Wrote file afiedt.buf 1 select constraint_type, table_name, status 2* from user_constraints where constraint_name = 'SYS_C00137508' SQL> / C TABLE_NAME STATUS - ------------------------------ -------- P TABLE_1 ENABLED
But as a "duplicate" coming soon to update, I get the error of unique constraint.
Thank you
-K.B.Dear Sir
ERROR at line 1: ORA-00001: unique constraint (SYS_C00137508) violated
You think two things
(a) coherent reading: what was the situation of table_1 when the maching clause was initially assessed. There were 0 insert rows that correspond to which means that the merge operation will be all
(b) your corresponding clause has a problem: the join column must be unique in both tables the case the merger will be ambiguous. You do not have a unique key on the source table
(c) think that the merge operation will never insert id = 1 and then update id = 1 within the same operation. Will never happenHope this helps
Mohamed Houri
-
VLD-2761: impossible to generate the merge statement
Hi pros,.
I received this warning from validation on my complex mapping:
"Merge statement cannot be generated because the SUPPCODE column is used for correspondence and updating. A column cannot be updated in a merge statement.
I think that happens because of the restraint newly added to the target table that is used in my map, but what exactly does that mean?This means that the column THAT SUPPCODE is used as a correspondent and update.
Click on SUPPCODE and check the attribute propertyLoad when updating column lines = Yes
Matches columns when updating rows = YesSo the merger will not be generated for this
(The answer is mark as correct if it's useful)
See you soon
KatiaPublished by: Katia on April 28, 2010 06:13
-
Using the merge statement on support-compatible version table time invalid
Hello
just a simple question: is it possible to use a merge statement on a table of valid time support-compatible version?
For the next test, I get an ORA-01733.
(t1 is the version table compatible with time valid support t1 and t2 have the same structure: two fields: NAME and CODE (pk))
merge into < table1 > t1
with the help of < table2 > t2
on (t1. CODE = t2. CODE)
when matched, THEN update set t1.NAME = t1.NAME
where <>t1.NAME, t2.NAME;
Thank youHello
The sql merge operation does not currently work with versioned tables, with or without validtime. The optimizer of the merger results in insert/update statements on the underlying table for the _LT. As a result, instead of triggers that are created during the enableversioning are never triggered.
Kind regards
Ben
Maybe you are looking for
-
A code I have build to generate and acquire waveform signals and then write them in a text file with the appropriate time stamp is attached. As it is, I've linked only the portion of scripture to the acquired signals (I intend to write then generated
-
Takeing servays and getting paid for them idk yet at this point if someone does it, but what I know is something about an e-mail sent saying Microsoft recycling bin is Max I guess that investors make sure that I do as he asks and then they return tro
-
How to erase old data Window Vista PC?
I have a personal desktop computer and you want to format the hard drive, but fail. I use Vista. Right-click of the mouse to format drive C alow. I have the Vista of entry and try to re - install the Vista, it finally road at the request of messag
-
What is the warranty period on the screen above, purchased at retail (not Dell) in the United Kingdom?
-
problem installing photoshop CS5 Extended?
HelloI have a new iMac from Apple, I would like to transfer my old photoshop I have mac to my new. When I go to download the software I get the message 'install' is corrupted and cannot be opened, you should eject the disk image.Can you shed some li