Re-doing complex Merge statement in OWB
I have a complex merge written in sql that needs to be redone in owb.
The code is something like this :
MERGE INTO table_1
USING (
WITH u1 AS (SELECT STATEMENT 1....)),
u2 AS (SELECT STATEMENT 2....)),
u3 AS (SELECT STATEMENT 3....)),
u4 AS (SELECT STATEMENT 4....)),
u5 AS (SELECT STATEMENT 5....))
SELECT *
FROM (SELECT * FROM u1
UNION
SELECT * FROM u2
UNION
SELECT * FROM u3
UNION
SELECT * FROM u4
UNION
SELECT * FROM u5) a,b
WHERE a.column1 = b.column1(+) ) table_2
ON (table_1.id = table_2.id)
when matched then update set....
when not matched then insert...
How do I implement some thing like above in OWB? Do i need to use pluggable mappings?
any feedback would be of great help!
Thanks
Billu
Hi Billu,
no, you do not need pluggable mappings.
Design your selects for u1 - u5 as required in one mapping. Then use a set operator (union) with 5 ingroups. Connect the results of your selects to each ingroup.
Connect the output of the set operator to your target table table_1. Set loading type to insert/update (this will generate a merge statement). Use the column id for matching.
Regards,
Carsten.
Similar Messages
-
Can't generate Merge statement in OWB
Hi All,
I'm facing a very strange problem in OWB. Version is 9.0.3. I have a target table which has its properties set to INSERT/UPDATE and I have set one of its fileds to be the one used for matching. However when generating the code, OWB is generating only an INSERT statement and not a MERGE as I'd expect. The table is very simple, it has 4 columns, 1 of which I will be using to match on. the properties of them are:
Load on Insert Load on Update Use for Matching
F1 Y Y N
F2 Y Y N
F3 Y Y N
F4 N N Y
The module in which this mapping was created is pointing to an Oracle8i/9i DB. All other mappings when created in a seperate module with this project CAN generate the Merge...strange!
I have used the Merge statement successfully on many other mappings but at this client site I'm having problems
Any help would me most appreciated.
Take care
MiteshThanks for your reply. My target table does not have any contraints on it and that is why in the properties in OWB I have selected the value "no contraints" for "match by constrainsts". I have then set one of the 4 fields to:
Insert:Use for loading = No
Update:Use for loading = No
Update:Use for matching = Yes
The other threee columns are set to:
Insert:Use for loading = Yes
Update:Use for loading = Yes
Update:Use for matching = No
The table Loading/Type is Insert/Update but I'm still not getting the merge to work. I really am not sure if this is a Java bug or not. I have deleted the mapping and created it from scratch but I get the same problem. Then next point of call I think would be to create a new module within my projects - but its just strange how other moules in this same project work with merge.
Thanks
Mitesh -
Managing the first application of the MERGE statement in an ETL logic - SQL Server 2012
Hi,
in order to feed a fact table of a dwh from a staging table I'm using the MERGE statement in order to control insert and update operations. It is possible that the staging table has duplicate rows respect to the fields controlled in the merge condition:
when I run the first time the MERGE statement unwanted rows could be inserted in the fact table.
Does the MERGE statement allow to manage this case or do I need to filter data from the staging table before to write them into the fact table?
Many thanksHi Anuj,
thank for your reply. Unfortunately the DISTINCT in the using clause isn't enough for my case: I need to read a subset of fields of a staging table and for this subset I could have duplicate rows, but also I need to the change date of the rows inserted in
the staging table and I cannot include this date in the distincted columns.
However the answer is that I need to handle the staging data before to write them into the fact table.
Thanks
Yes
One more thing to note is when running MERGE statement subsequently in case there are multiple records which matches the update criteria then default behavior of MERGE is to throw an error indicating that it tried to update same record twice.
So in any case you need to make sure you eliminate duplicates before applying MERGE over it at first.
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
How to change the merge condition in OWB generated code
Hi,
This is regarding the OWB generated code for cubes. We required to change the ON condition of MERGE statement. OWB merge the records on the basis of dimension keys only. Is there any ways to provide the customised merge condition or is it possible to add a measure of the cube to be used in ON condition of the merge?Hi,
cant´t you customize the generated Code in the Database?
I know that owb has the trait to do the following:
If you create a Mapping, etc. the generated Code will be deployed as PL/SQL Package in the Database Schema.
Now you can edit the Code as Schema User right in the Database.
Don´t edit it in the Metadata, only in the Databse.
If you run now any Process in OWB, he´ll execute your edited Code,
´cause he just takes whats still there. :-)
It´s not realy clean, but in most Times that works.
LoneWolf -
Why does OWB generate merge statement when target type = Update
Hi there
getting problem message cannot generate merge. I don't undretand why even trying to ctreate a merge when should be an update and then sql would be fine.
trying to update a table whose expiry date = '31-DEC-4000' (via raget filter for update
and also put value from src into this field.
This would be ok in sql
update table
set col = new_value
where col = 31-dec-4000'
Any thoughts - it seems strange why OWB generate a merge when set target type to Update since other target types of Update/Insert and Insert/Update available to generate merge.
Many ThanksI understand what you are trying to say...
One simple workaround for this is: In the mapping, add one more column in the target table eg: match_val. Set the bound name to match column eg: col.
Set the one match_val attribute properties to "match column when updating" & actual column eg: col attribute properties to "Load column when updating".
This will generate merge statement for your requirements. This will help u. -
Problem in merge statement -ORA-27432 Step does not exist for chain
Hi
I m getting ORA-27432 Step does not exist for chain error in merge statement.Please explain the same.
MERGE INTO fos.pe_td_hdr_sd B
USING (
SELECT ACTIVE, ADDUID, ADDUIDTIME,TDKEY FROM pe.pe_td_hdr
WHERE (adduidtime like '20070104%' or edituidtime like '20070104%')
AND NVL(legacy_td,'N')<>'Y'
AND SUBSTR(adduidtime,1,4)='2007'
AND AMENDMENT_NO=0)A ON ( B.TDKEY = A.TDKEY)
WHEN MATCHED THEN
UPDATE SET B.ACTIVE=A.ACTIVE,
B.ADDUID=A.ADDUID,
B.ADDUIDTIME=A.ADDUIDTIME
WHEN NOT MATCHED THEN
INSERT
B.ACTIVE,
B.ADDUID,
B.ADDUIDTIME)
VALUES(
A.ACTIVE,
A.ADDUID,
A.ADDUIDTIME)This query is a short version of the main query.It is same but having 180 columns in original table.What version of Oracle are you using? This message does not appear in my 10.1 Error Messages document, but the other messages in that range seem to be about DBMS_SCHEDULER.
Are you using scheduler somewhere around where you are getting the error message?
John -
MERGE Statement - unable to get a stable set of rows in the source tables
OWB Client: 10.1.0.2.0
OWB Repository: 10.1.0.1.0
I am trying to create a MERGE in OWB.
I get the following error:
ORA-12801: error signaled in parallel query server P004 ORA-30926: unable to get a stable set of rows in the source tables
I have read the other posts regarding this and can't seem to get a fix.
The target table has a unique index on the field that I am matching on.
The "incoming" data doesn't have a unique index, but I have checked and confirmed that it is unique on the appropriate key.
The "incoming" data is created by a join and filter in the mapping and I'd rather avoid having to load this data into a new table and add a unique index on this.
Any help would be great.
Thanks
LauraHello Laura,
The MERGE statement does not require any constraints on its target table or source table. The only requirement is that two input rows cannot update the same target row, meaning that all existing target rows can be matched by at most one input row (otherwise the MERGE would be undeterministic since you don't know which of the input rows you would end up with in the target).
If a table takes ages to load (and is not really big) I suspect that your mapping is not running in set mode and that it performs a full table scan on source data for each target row it produces.
If you ARE running in set mode you should run explain plan to get a hint on what is wrong.
Regarding your original mapping, try to set the target operator property:
Match by constraint=no constraints
and then check the Loading properties on each target column.
Regards, Hans Henrik -
Question on passing string values to Partition clause in a merge statement
Hello All,
I am using the below code to update specific sub-partition data using oracle merge statements.
I am getting the sub-partition name and passing this as a string to the sub-partition clause.
The Merge statement is failing stating that the specified sub-partition does not exist. But the sub-partition do exists for the table.
We are using Oracle 11gr2 database.
Below is the code which I am using to populate the data.
declare
ln_min_batchkey PLS_INTEGER;
ln_max_batchkey PLS_INTEGER;
lv_partition_name VARCHAR2 (32767);
lv_subpartition_name VARCHAR2 (32767);
begin
FOR m1 IN ( SELECT (year_val + 1) AS year_val, year_val AS orig_year_val
FROM ( SELECT DISTINCT
TO_CHAR (batch_create_dt, 'YYYY') year_val
FROM stores_comm_mob_sub_temp
ORDER BY 1)
ORDER BY year_val)
LOOP
lv_partition_name :=
scmsa_handset_mobility_data_build.fn_get_partition_name (
p_table_name => 'STORES_COMM_MOB_SUB_INFO',
p_search_string => m1.year_val);
FOR m2
IN (SELECT DISTINCT
'M' || TO_CHAR (batch_create_dt, 'MM') AS month_val
FROM stores_comm_mob_sub_temp
WHERE TO_CHAR (batch_create_dt, 'YYYY') = m1.orig_year_val)
LOOP
lv_subpartition_name :=
scmsa_handset_mobility_data_build.fn_get_subpartition_name (
p_table_name => 'STORES_COMM_MOB_SUB_INFO',
p_partition_name => lv_partition_name,
p_search_string => m2.month_val);
DBMS_OUTPUT.PUT_LINE('The lv_subpartition_name => '||lv_subpartition_name||' and lv_partition_name=> '||lv_partition_name);
IF lv_subpartition_name IS NULL
THEN
DBMS_OUTPUT.PUT_LINE('INSIDE IF => '||m2.month_val);
INSERT INTO STORES_COMM_MOB_SUB_INFO T1 (
t1.ntlogin,
t1.first_name,
t1.last_name,
t1.job_title,
t1.store_id,
t1.batch_create_dt)
SELECT t2.ntlogin,
t2.first_name,
t2.last_name,
t2.job_title,
t2.store_id,
t2.batch_create_dt
FROM stores_comm_mob_sub_temp t2
WHERE TO_CHAR (batch_create_dt, 'YYYY') = m1.orig_year_val
AND 'M' || TO_CHAR (batch_create_dt, 'MM') =
m2.month_val;
ELSIF lv_subpartition_name IS NOT NULL
THEN
DBMS_OUTPUT.PUT_LINE('INSIDE ELSIF => '||m2.month_val);
MERGE INTO (SELECT *
FROM stores_comm_mob_sub_info
SUBPARTITION (lv_subpartition_name)) T1
USING (SELECT *
FROM stores_comm_mob_sub_temp
WHERE TO_CHAR (batch_create_dt, 'YYYY') =
m1.orig_year_val
AND 'M' || TO_CHAR (batch_create_dt, 'MM') =
m2.month_val) T2
ON (T1.store_id = T2.store_id
AND T1.ntlogin = T2.ntlogin)
WHEN MATCHED
THEN
UPDATE SET
t1.postpaid_totalqty =
(NVL (t1.postpaid_totalqty, 0)
+ NVL (t2.postpaid_totalqty, 0)),
t1.sales_transaction_dt =
GREATEST (
NVL (t1.sales_transaction_dt,
t2.sales_transaction_dt),
NVL (t2.sales_transaction_dt,
t1.sales_transaction_dt)),
t1.batch_create_dt =
GREATEST (
NVL (t1.batch_create_dt, t2.batch_create_dt),
NVL (t2.batch_create_dt, t1.batch_create_dt))
WHEN NOT MATCHED
THEN
INSERT (t1.ntlogin,
t1.first_name,
t1.last_name,
t1.job_title,
t1.store_id,
t1.batch_create_dt)
VALUES (t2.ntlogin,
t2.first_name,
t2.last_name,
t2.job_title,
t2.store_id,
t2.batch_create_dt);
END IF;
END LOOP;
END LOOP;
COMMIT;
end;
Much appreciate your inputs here.
Thanks,
MK.I've not used partitioning, but I do not see MERGE supporting a variable as a partition name in
MERGE INTO (SELECT *
FROM stores_comm_mob_sub_info
SUBPARTITION (lv_subpartition_name)) T1
USING ... I suspect it is looking for a partition called lv_subpartition_name.
I also don't see why you need that partition name - the ON clause should be able to identify the partition's criteria. -
Issue while using SUBPARTITION clause in the MERGE statement in PLSQL Code
Hello All,
I am using the below code to update specific sub-partition data using oracle merge statements.
I am getting the sub-partition name and passing this as a string to the sub-partition clause.
The Merge statement is failing stating that the specified sub-partition does not exist. But the sub-partition do exists for the table.
We are using Oracle 11gr2 database.
Below is the code which I am using to populate the data.
declare
ln_min_batchkey PLS_INTEGER;
ln_max_batchkey PLS_INTEGER;
lv_partition_name VARCHAR2 (32767);
lv_subpartition_name VARCHAR2 (32767);
begin
FOR m1 IN ( SELECT (year_val + 1) AS year_val, year_val AS orig_year_val
FROM ( SELECT DISTINCT
TO_CHAR (batch_create_dt, 'YYYY') year_val
FROM stores_comm_mob_sub_temp
ORDER BY 1)
ORDER BY year_val)
LOOP
lv_partition_name :=
scmsa_handset_mobility_data_build.fn_get_partition_name (
p_table_name => 'STORES_COMM_MOB_SUB_INFO',
p_search_string => m1.year_val);
FOR m2
IN (SELECT DISTINCT
'M' || TO_CHAR (batch_create_dt, 'MM') AS month_val
FROM stores_comm_mob_sub_temp
WHERE TO_CHAR (batch_create_dt, 'YYYY') = m1.orig_year_val)
LOOP
lv_subpartition_name :=
scmsa_handset_mobility_data_build.fn_get_subpartition_name (
p_table_name => 'STORES_COMM_MOB_SUB_INFO',
p_partition_name => lv_partition_name,
p_search_string => m2.month_val);
DBMS_OUTPUT.PUT_LINE('The lv_subpartition_name => '||lv_subpartition_name||' and lv_partition_name=> '||lv_partition_name);
IF lv_subpartition_name IS NULL
THEN
DBMS_OUTPUT.PUT_LINE('INSIDE IF => '||m2.month_val);
INSERT INTO STORES_COMM_MOB_SUB_INFO T1 (
t1.ntlogin,
t1.first_name,
t1.last_name,
t1.job_title,
t1.store_id,
t1.batch_create_dt)
SELECT t2.ntlogin,
t2.first_name,
t2.last_name,
t2.job_title,
t2.store_id,
t2.batch_create_dt
FROM stores_comm_mob_sub_temp t2
WHERE TO_CHAR (batch_create_dt, 'YYYY') = m1.orig_year_val
AND 'M' || TO_CHAR (batch_create_dt, 'MM') =
m2.month_val;
ELSIF lv_subpartition_name IS NOT NULL
THEN
DBMS_OUTPUT.PUT_LINE('INSIDE ELSIF => '||m2.month_val);
MERGE INTO (SELECT *
FROM stores_comm_mob_sub_info
SUBPARTITION (lv_subpartition_name)) T1 --> Issue Here
USING (SELECT *
FROM stores_comm_mob_sub_temp
WHERE TO_CHAR (batch_create_dt, 'YYYY') =
m1.orig_year_val
AND 'M' || TO_CHAR (batch_create_dt, 'MM') =
m2.month_val) T2
ON (T1.store_id = T2.store_id
AND T1.ntlogin = T2.ntlogin)
WHEN MATCHED
THEN
UPDATE SET
t1.postpaid_totalqty =
(NVL (t1.postpaid_totalqty, 0)
+ NVL (t2.postpaid_totalqty, 0)),
t1.sales_transaction_dt =
GREATEST (
NVL (t1.sales_transaction_dt,
t2.sales_transaction_dt),
NVL (t2.sales_transaction_dt,
t1.sales_transaction_dt)),
t1.batch_create_dt =
GREATEST (
NVL (t1.batch_create_dt, t2.batch_create_dt),
NVL (t2.batch_create_dt, t1.batch_create_dt))
WHEN NOT MATCHED
THEN
INSERT (t1.ntlogin,
t1.first_name,
t1.last_name,
t1.job_title,
t1.store_id,
t1.batch_create_dt)
VALUES (t2.ntlogin,
t2.first_name,
t2.last_name,
t2.job_title,
t2.store_id,
t2.batch_create_dt);
END IF;
END LOOP;
END LOOP;
COMMIT;
end;
Much appreciate your inputs here.
Thanks,
MK.
(SORRY TO POST THE SAME QUESTION TWICE).
Edited by: Maddy on May 23, 2013 10:20 PMDuplicate question
-
Hi All,
I am using merge statement to update 30000 records from the tables having 55 lacs records.
But it is taking much time as i have to kill the session after 12 hours,as it was still going on.
If,Same update i m doing using cursors,it will finish in less than 3 hours.
Merge i was using is :-
MERGE INTO Table1 a
USING (SELECT MAX (TO_DATE ( TO_CHAR (contact_date, 'dd/mm/yyyy')
|| contact_time,
'dd/mm/yyyy HH24:Mi:SS'
) m_condate,
appl_id
FROM Table2 b,
(SELECT DISTINCT acc_no acc_no
FROM Table3, 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
ON (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 records and table2 and table 3 have 3670955 and 555674 records respectively.
Please suggest,what i am doing wrong in merge,because as per my understanding merge statement is much better than updates or updates using cursors.
Required info is as follows:
SQL> show parameter user_dump_dest
NAME TYPE VALUE
user_dump_dest string /opt/oracle/admin/FINCLUAT/udu
mp
SQL> show parameter optimizer
NAME TYPE VALUE
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 10.2.0.4
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_mode string ALL_ROWS
optimizer_secure_view_merging boolean TRUE
SQL> show parameter db_file_multi
NAME TYPE VALUE
db_file_multiblock_read_count integer 16
SQL> show parameter db_block_size
NAME TYPE VALUE
db_block_size integer 8192
SQL> column sname format a20
SQL> column pname format a20
SQL> column pval2 format a20
SQL> select
2 sname ,
3 pname ,
4 pval1 ,
5 pval2
6 from
7 sys.aux_stats$;
sys.aux_stats$
ERROR at line 7:
ORA-00942: table or view does not exist
Elapsed: 00:00:00.05
SQL> explain plan for
2 -- put your statement here
3 MERGE INTO cs_case_info a
4 USING (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
10 FROM CS_CASE_DETAILS_ACLOS b,
11 (SELECT DISTINCT acc_no acc_no
12 FROM 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 OR followup_branch_code IS NOT NULL
18 )
19 GROUP BY appl_id) c
20 ON (a.appl_id = c.appl_id AND a.delinquent_flag = 'Y')
21 WHEN MATCHED THEN
22 UPDATE
23 SET last_contact_date = c.m_condate
24 ;
Explained.
Elapsed: 00:00:00.08
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)|
| 0 | MERGE STATEMENT | | 47156 | 874K| | 128K (1)|
| 1 | MERGE | CS_CASE_INFO | | | | |
| 2 | VIEW | | | | | |
| 3 | HASH JOIN | | 47156 | 36M| 5672K| 128K (1)|
| 4 | VIEW | | 47156 | 5111K| | 82339 (1)|
| 5 | SORT GROUP BY | | 47156 | 4236K| 298M| 82339 (1)|
| 6 | HASH JOIN | | 2820K| 247M| 10M| 60621 (1)|
| 7 | HASH JOIN | | 216K| 7830K| | 6985 (1)|
| 8 | VIEW | 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 | INDEX FAST FULL SCAN| IDX_NACL_RSH_ACC_NO | 5539K| 68M| | 5382 (1)|
| 13 | TABLE ACCESS FULL | CS_CASE_DETAILS_ACLOS | 3670K| 192M| | 41477 (1)|
| 14 | TABLE ACCESS FULL | CS_CASE_INFO | 304K| 205M| | 35975 (1)|
Note
- 'PLAN_TABLE' is old version
24 rows selected.
Elapsed: 00:00:01.04
SQL> rollback;
Rollback complete.
Elapsed: 00:00:00.03
SQL> set autotrace traceonly arraysize 100
SQL> alter session set events '10046 trace name context forever, level 8';
ERROR:
ORA-01031: insufficient privileges
Elapsed: 00:00:00.04
SQL> disconnect
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> spool off
Edited by: user4528984 on May 5, 2009 10:37 PMFor one thing, alias your tables and use that in the column specifications (table1.column1 = table2.column3 for example)...
SELECT
DISTINCT
acc_no acc_no
FROM Table3, Table1
WHERE acc_no = appl_id
AND delinquent_flag = 'Y'
AND financier_id = 'NEWACLOS'We don't know what your tables look like, what columns come from where. Try and help us help you, assume we know NOTHING about YOUR system, because more likely than naught, that's going to be the case.
In addition to that, please read through this which will give you a better-er idea of how to post a tuning related question, you've not provided near enough information for us to intelligently help you.
HOW TO: Post a SQL statement tuning request - template posting -
FORALL MERGE statement works in local database but not over database link
Given "list", a collection of NUMBER's, the following FORALL ... MERGE statement should copy the appropriate data if the record specified by the list exists on both databases.
forall i in 1..list.count
merge into tbl@remote t
using (select * from tbl
where id = list(i)) s
on (s.id = t.id)
when matched then
update set
t.status = s.status
when not matched then
insert (id, status)
values (s.id, s.status);
But this does not work. No exceptions, but target table's record is unchanged and "sql%rowcount" is 0.
If the target table is in the local database, the exact same statement works:
forall i in 1..list.count
merge into tbl2 t
using (select * from tbl
where id = list(i)) s
on (s.id = t.id)
when matched then
update set
t.status = s.status
when not matched then
insert (id, status)
values (s.id, s.status);
Does anyone have a clue why this may be a problem?
Both databases are on Oracle 10g.
Edited by: user652538 on 2009. 6. 12 오전 11:29
Edited by: user652538 on 2009. 6. 12 오전 11:31
Edited by: user652538 on 2009. 6. 12 오전 11:45Should throw an error in my opinion. The underlying reason for not working is basically because of
SQL> merge into t@remote t1
using ( select sys.odcinumberlist (1) from dual) t2
on (1 = 1)
when matched
then
update set i = 1
Error at line 4
ORA-22804: remote operations not permitted on object tables or user-defined type columnsSame reason as e.g.
insert into t@remote select * from table(sys.odcinumberlist(1,2,3))doesn't work. -
Why won't this MERGE statement work?
I am testing out a MERGE statement, which contains a subquery that will return no rows...on this condition, it should insert a record; however I get 0 records merged. Why is this?
Ultimately, the hard-coded values will actually be passed in as parameters. If those a record with those four values is not found, then it should insert.
MERGE INTO tb_slea_election_worksheet A
USING
(SELECT i.slea_year,i.empid,i.bda_sum_sort,i.bda_dtl_sort FROM tb_slea_election_worksheet i
WHERE slea_year = '2008'
AND empid = '6468T'
AND bda_sum_sort = '30'
AND bda_dtl_sort = '9999'
) B
ON (A.slea_year = B.slea_year
AND A.empid =B.empid
AND A.bda_sum_sort = B.bda_sum_sort
AND A.bda_dtl_sort = B.bda_dtl_sort)
WHEN MATCHED THEN
UPDATE SET A.fa_proj_exp_amt = 888
WHEN NOT MATCHED THEN
INSERT (slea_year,empid,bda_sum_sort,bda_dtl_sort,act_exp_lst_yr,fa_proj_exp_amt)
VALUES ( '2008','6468T','30','9999','0','55');A merge statement is just a much more efficient way of doing something like this pl/sql block
DECLARE
l_n NUMBER;
BEGIN
FOR r IN (SELECT pk, col1, col2 FROM source) LOOP
BEGIN
SELECT 1 INTO l_n
FROM target
WHERE pk = r.pk;
UPDATE target
SET col1 = r.col1,
col2 = r.col2
WHERE pk = r.pk;
EXCEPTION WHEN NO_DATA_FOUND THEN
INSERT INTO target
VALUES(r.pk, r.col1, r.col2);
END;
END LOOP;
END;So, if the select from source returns no rows, nothing is going to happen.
John -
Error in MERGE statement - ORA-00969: missing ON keyword
Hi All ,
I am trying to write a Merge statement , but I am getting the below error .
MERGE INTO main_table m
USING tab_1 l, tab_2 u
ON ( l.col1 = m.col1
AND u.col2 = l.col2)
When Matched then
update........
When not mached then
Insert ......
But here I am using 2 tables in the USING clause . and here I am getting this error :-
142/17 PL/SQL: SQL Statement ignored
143/42 PL/SQL: ORA-00969: missing ON keyword
May I know where i am doing wrong ?Hi LuKKa, you are on the Portugues Forum, but we can help you, try the code mentioned below:
MERGE INTO main_table m
USING (select l.col1, l.col2, u.col2 from tab_1 l join tab_2 u on (u.col2 = l.col2)) t
ON (t.col1 = m.col1)
When Matched then
update........
When not mached then
Insert ......
Regards. -
Hi All,
I am using merge statement to insert and update rows. The merge statement takes a row level exclusive lock
Suppose the select statement returns 1 Million records does
1) The merge statement first tries to lock all the affected rows and then update / insert records.
OR
2) The merge statement aquires lock on an incremental basis as returned by the select statement.The merge works just like an insert or update statement in that locks are acquired "on an incremental basis", but as of the timestamp the merge began. When Oracle detects that another session has updated a row in the meantime, then it re-executes the entire merge statement as of that new timestamp. It is sometimes referred to as "write consistency".
Here is a good Asktom thread on this topic: http://asktom.oracle.com/pls/asktom/f?p=100:11:1694097844551766::::P11_QUESTION_ID:11504247549852
Regards,
Rob. -
hi gems..good afternoon...
My database version is 11.2.0.1.0 64 bit Solaris OS.
I am facing an "ORA-22813: operand value exceeds system limits" while running a procedure.
I have used loggers and found that it is getting failed in a MERGE statement.
That merge statement is used to merge a table with a collection. the code is like below:
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<.....>The parameter of the function GET_BALANCE_HIST(V_MERGE_REC) is a table type.
Now the function GET_BALANCE_HIST(V_MERGE_REC) is a pipelined function and we have used that because the collection V_MERGE_REC may get huge with data.
This proc was running fine from the beginning but from day before yesterday it was continously throwing ORA 22813 error in that line.
please help..thanks in advance..hi paul..thanks for your reply...
the function GET_BALANCE_HIST is not selecting data from any tables.
What this pipeline function is doing is, it is taking the huge collection V_MERGE_REC as parameter and releasing its datas in pipelined form. The code for the functions is :
CREATE OR REPLACE FUNCTION GET_BALANCE_HIST(P_MERGE IN TAB_TYPE_BALANCE_HISTORIC)
RETURN TAB_TYPE_BALANCE_HISTORIC
PIPELINED AS
V_MERGE TAB_TYPE_BALANCE_HISTORIC := TAB_TYPE_BALANCE_HISTORIC();
BEGIN
FOR I IN 1 .. P_MERGE.COUNT LOOP
V_MERGE.EXTEND;
V_MERGE(V_MERGE.LAST) := OBJ_TYPE_BALANCE_HISTORIC(P_MERGE(I).CUSTOMER_ID,
P_MERGE(I).BOOK_ID,
P_MERGE(I).PRODUCT_ID,
P_MERGE(I).SUB_BOOK_ID,
P_MERGE(I).EARNINGS,
P_MERGE(I).EARNINGS_HOUSE,
P_MERGE(I).QUANTITY,
P_MERGE(I).ACCOUNT_INTEGER);
END LOOP;
FOR J IN 1 .. V_MERGE.COUNT LOOP
PIPE ROW(OBJ_TYPE_BALANCE_HISTORIC(V_MERGE(I).CUSTOMER_ID,
V_MERGE(I).BOOK_ID,
V_MERGE(I).PRODUCT_ID,
V_MERGE(I).SUB_BOOK_ID,
V_MERGE(I).EARNINGS,
V_MERGE(I).EARNINGS_HOUSE,
V_MERGE(I).QUANTITY,
V_MERGE(I).ACCOUNT_INTEGER));
END LOOP;
RETURN;
END;I think the error is comming because of the parameter value of V_MERGE_REC. Since it is huge, so loading that into memory is causing problem. But in this case, how can I resolve it?? Can I use a global temporary table for this??
Please suggest...
Maybe you are looking for
-
Photos that aren't mine are in my iPhoto app.
Recently I went on a vacation with other iPhone users. While uploading my photos from the trip to my mac (via my digital camera) I noticed that I had someone else's albums in my events section of iPhoto. This person was on the trip with me and sai
-
S.M.A.R.T.--is it?
I've been noticing the "S.M.A.R.T. capable but disabled" go by when my system boots up, so I looked it up in the manual. So now I know what it is, but what I want to know is: is anyone using this?
-
SEND_ERROR in the SMARTFORM function module
Hi All, I want to send the PO via e-mai as attached PDF file. It is working fine in DEV. But in PRD i am getting SEND_ERROR in the SMARTFORM function module. can any one hep me to fix this???? CALL FUNCTION fm_name EXPORTING archive_index
-
How do you restore a phone when it is in recovery mode?
Tried updating my phone to 7.1.1 and it is now giving me what I think is the screen of death. I have the iTunes logo and it telling me to plug it in. Plugged it into my computer and iTunes is telling me it detects a phone in recovery mode and that
-
HII, I am working with CCM 5.1 as a service Provider. One of my customer have a third party 3Com 2102. I can't register his phone in my register.I have some configured already that i attached with mail. plz. help me ..and tell me how to configure tha