HElp in MERGE statement.
I want to user MERGE statment. I want to merge values in another database of table on the netwrok. When i am going to run my script the following error araise.
ORA-02071 error initializing capabilities for remote database string
How can u user MERGE.
scott@ORA92> MERGE into emp@DB_LINK c
USING scott.emp e
on (c.empno = e.empno)
WHEN MATCHED THEN
UPDATE SET
c.ename = e.ename,
c.job = e.job,
c.mgr = e.mgr,
c.hiredate = e.hiredate,
c.sal = e.sal,
c.comm = e.comm,
c.deptno = e.deptno
WHEN NOT MATCHED THEN
insert values(e.empno,e.ename,e.job,e.mgr,e.hiredate,e.sal,e.comm,e.deptno)
ORA-02071: error initializing capabilities for remote database string
Cause: Could not load a remote-specified capability table.
Action: Contact Oracle Support Services for the remote SQL*Connect product.
Similar Messages
-
Help for merge statement?
I have a problem in Merge statement. My merge statement is following:
MERGE INTO hoadon hd
USING (
SELECT m.ma_ttoan, t.ma_ttoan ma_kh
FROM tai_anhxa_makh t
INNER JOIN hoadon m on t.ma_kh = m.ma_ttoan
WHERE m.thang_nam = '200908' and m.ma_ttoan not like 'DLC%' and t.ma_ttoan IS NOT NULL
GROUP BY m.ma_ttoan, t.ma_ttoan
) m ON (hd.ma_ttoan = m.ma_kh)
WHEN MATCHED THEN
UPDATE SET ma_ttoan = m.ma_ttoan
WHEN NOT MATCHED THEN
INSERT (thang_nam, ma_ttoan) VALUES('200908','thaodv')
After execute this query, PS/SQL show error message: "ORA-00904: hd.ma_ttoan invalid identifier"
I'm using Oracle version 9i
Can anyone help me to resolve this problem?
Thanks in advanceIn 9i you can't use the columns from the ON clause in your UPDATE part of the MERGE statement
this is invalid:
UPDATE SET ma_ttoan = m.ma_ttoanuse a different column here. -
I have a MERGE statement, I am executing it from shell script, I want to print that how many rows has been updated and Inserted.
Can any one give me some idea.
Thanks in AdvanceI want to print that how many rows has been updated and Inserted. If you really want/need to print that information, then don't use MERGE but INSERT and UPDATE statements.
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:35615502072484
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:122741200346595110 -
Help on Merge Statement ,I got 'ORA-00904: invalid column name' Error
Pls help
In Oracle 9i i implement the following qry
MERGE INTO jobs A
USING (select order_no,jOB_SEQ_NO from jobs_dlt) B
ON (A.ORDER_NO = B.ORDER_NO and A.JOB_SEQ_NO =B.JOB_SEQ_NO )
WHEN MATCHED THEN
UPDATE SET
A.ORDER_NO= B.ORDER_NO ,
A.JOB_SEQ_NO= B.JOB_SEQ_NO
WHEN NOT MATCHED THEN
INSERT (
A.JOB_SEQ_NO ,
A.ORDER_NO
VALUES (
B.JOB_SEQ_NO ,
B.ORDER_NO
but i got 'ORA-00904: invalid column name' Error
JOBS table Contain the above Column
how i implement the Merge Statment
Thanks in advance
By
SekarI seem to recall this error being spuriously (well unhelpfully) thrown if you tried to UPDATE a key that you used in the ON clause, but I could be mistaken.
For us to recreate this you would need to supply the exact version and scripts to create the tables in question. -
Help needed in MERGE statement
Hi,
I am new to PL/SQL, I want to update a table called "final_test" based on the below query result.
1. I want to check whether that particular record is present or not in my "final_test" table.
2. If its present in the "final_test" table and the process_status got changed then I want to update that alone in my "final_test" table.
3. If its not present then I want to insert that record into my "final_test" table.
Basically I am retrieving the report and its status for a particular date.
select
b.id,
a.name,
a.t_name,
c.process_status,
c.time_process
from rep_tab_map a, j_tab_map b, proc_status c
where a.t_name=b.t_name
and b.id=c.id (+)
and trunc(c.date_start)=trunc(sysdate -1)
group by a.name,b.id,c.process_status,c.time_process,a.t_name
order by 2
I thought of using Merge statement but i am not sure what i have to use in ":USING" and "ON" clause.
Please help me with MERGE or with someother way.
ThanksAssuming final_test has same structure as select list in your query:
merge
into final_test a
using (
select b.id,
a.name,
a.t_name,
c.process_status,
c.time_process
from rep_tab_map a,
j_tab_map b,
proc_status c
where a.t_name=b.t_name
and b.id=c.id(+)
and trunc(c.date_start)=trunc(sysdate -1)
group by a.name,b.id,c.process_status,c.time_process,a.t_name
) b
on (b.id = a.id)
when matched then update set a.name = case a.process_status
when b.process_status then a.name
else b.name
end,
a.t_name = case a.process_status
when b.process_status then a.t_name
else b.t_name
end,
a.process_status = b.process_status,
a.time_process = case a.process_status
when b.process_status then a.time_process
else b.time_process
end
when not matched then insert(
a.id,
a.name,
a.t_name,
a.process_status,
a.time_process
values(
b.id,
b.name,
b.t_name,
b.process_status,
b.time_process
/SY. -
Help needed in the Merge Statement
Hi All,
I am using MERGE statement in my program. I want to maintain the log for the duplicate reords mean maintain the log for those reocrds which are updated in the merge statement.
Can any one help me in this that how can i maintain the log?
Thanks for your help in advance.
kind Regards,http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:35615502072484
-
Help needed on Merge statement
Hi,
I want to merge a record which has a LONG field to a table with LOB field.
Am getting error "ORA-00932: inconsistent datatypes: expected - got LONG" at "to_lob(col2) " in the query. Please help in resolving this.
Thanks
RK
MERGE INTO message_STG d
USING (SELECT col1,to_lob(col2) col2
FROM message jm
WHERE modificationdate >= <some_date_value> ) f
ON (d.MESSAGEID= f.MESSAGEID)
WHEN matched THEN
UPDATE SET
col1=f.col1,
col2=f.col2
WHEN NOT matched THEN
INSERT VALUES (f.col1,f.col2);Am getting error "ORA-00932: inconsistent datatypes: expected - got LONG" at "to_lob(col2) "If you read the documentation you will discover that to_lob() only works in an insert statement.
What you will have is create a holding table with a CLOB column and insert all your MESSAGE records into it, doing the TO_LOB() there. Then you can drive your MERGE statement from that holding table.
Is this a one-off data migration exercise or something you'll have to do regularly?
Cheers, APC
Blog : http://radiofreetooting.blogspot.com/ -
Hi
I am using a merge statement where i am updating and inserting records in table 2 from table 1.
I want to log the no. of rows updated and new rows inserted in the log table.
If i am not wrong, we can use sql%rowcount but i need help as how to use this statement.
Please suggest a solution.
Thanksuser11018028 wrote:
Will the sql%rowcount will give the no. of updated rows OR no. of newly inserted rows OR the sum of both in case of a merge statement.Total number of rows that changed (SUM). -
Error while using Merge statement
Hi,
Can any one please look at the merge statement and help me understand the error.Thanks in advance.
MERGE /*+ APPEND */
INTO intf_lpa_master m
USING (SELECT std_district_student_id,
std_grade_code,
sub_test,
test_date,
performance_lvl_code,
test_lang_code,
v_student_id,
v_test_id,
v_lang_cd,
v_plc,
valid_test_date,
-- school_year,
-- school_id,
valid_src_stu_id,
test_code
FROM intf_lpa_master_vw
MINUS
SELECT std_district_student_id,
std_grade_code,
sub_test,
test_date,
performance_lvl_code,
test_lang_code,
v_student_id,
v_test_id,
v_lang_cd,
v_plc,
valid_test_date,
-- school_yr,
-- school_id,
valid_src_stu_id,
test_code
FROM intf_lpa_master
WHERE active_flag = 'Y') v
ON ( m.std_district_student_id = v.std_district_student_id
AND m.sub_test = v.sub_test
AND m.test_date = v.test_date)
WHEN MATCHED
THEN
UPDATE SET m.std_grade_code = v.std_grade_code,
m.performance_lvl_code = v.performance_lvl_code,
m.test_lang_code = v.test_lang_code,
m.active_flag = 'Y', -- if we are touching this record, it is to be active.
m.error_message = NULL, -- refresh these, to properly reconsider records.
m.create_date = SYSDATE,
m.record_id = intf_lpa_master_seq.NEXTVAL,
m.process_row = 'U',
m.last_update_date = SYSDATE,
m.last_update_user = 'PRE_PROCESS_LPA - UPDATE',
-- m.job_id = c_run_id ,
m.validation_step = NULL, -- refresh these, to properly reconsider records.
m.v_student_id = v.v_student_id,
m.v_test_id = v.v_test_id,
m.v_lang_cd = v.v_lang_cd,
m.v_plc = v.v_plc,
m.valid_test_date = v.valid_test_date,
-- m.school_year = v.schloo_year,
-- m.school_id = v.school_id,
m.valid_src_stu_id = v.valid_src_stu_id,
m.test_code = v.test_code
WHEN NOT MATCHED
THEN
INSERT (
m.std_district_student_id,
m.std_grade_code,
m.sub_test,
m.test_date,
m.performance_lvl_code,
m.test_lang_code,
m.active_flag,
m.error_message,
m.create_date,
m.record_id,
m.process_row,
m.last_update_date,
m.last_update_user,
-- m.job_id,
m.validation_step,
m.v_student_id,
m.v_test_id,
m.v_lang_cd,
m.v_plc,
m.valid_test_date,
-- m. school_year,
-- m. school_id,
m.valid_src_stu_id,
m.test_code)
VALUES (
v.std_district_student_id,
v.std_grade_code,
v.sub_test,
v.test_date,
v.performance_lvl_code,
v.test_lang_code,
'Y',
NULL,
SYSDATE,
intf_lpa_master_seq.NEXTVAL,
'I',
SYSDATE,
'PRE_PROCESS_LPA - INSERT',
-- c_run_id,
NULL,
v.v_student_id,
v.v_test_id,
v.v_lang_cd,
v.v_plc,
v.valid_test_date,
-- v. school_year,
-- v. school_id,
v.valid_src_stut_id,
v.test_code);
Error Message :
ORA-06553 : PLS-306:wrong number or types of arguments in call to 'V'There are a couple of thngs wrong here. In the when matched insert column list, you cannot qualify the field name with the table alias. It should be just:
insert (std_district_student_id, std_grade_code, sub_test ...)Are v_student_id, v_test_id, v_lang_cd, and v_plc really columns in the intf_lpa_master table? I am more used to seeing v_name as a variable naming convention than a column name, but I could be wrong.
John -
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 -
Hi all,
I am working on oracle9i
I am using the Merge Statement to INS/UPD rows
I am using loops to
I am updating 29 rows as insert and 1 row a update
Values are inserting and updating correctly in table
But in Sql prompt
I am getting the output as
below
12:03:54 SQL> execute Pr_Bdms_Cont_Insupd;
1 rows merged.
1 rows inserted.
1 rows updated.
PL/SQL procedure successfully completed.
But i take out the loop i am getting exact result
12:03:54 SQL> execute Pr_Bdms_Cont_Insupd;
30 rows merged.
29 rows inserted.
1 rows updated.
PL/SQL procedure successfully completed.
Any help
Below is my procedure
and
CREATE OR REPLACE PROCEDURE Pr_EMP_Insupd IS
empID VARCHAR2(7);
CURSOR C_empno IS SELECT empno FROM TEMP WHERE ROWNUM < 30;
REC_BIN C_empid%ROWTYPE;
BEGIN
FOR REC_BIN IN C_empid LOOP
empID := fn_emp_Id(REC_BIN.Bin);-- Calling function
Merge INTO EMP E
BGC
USING (SELECT A.EMP_ID,B.SALARY,B.BONUS
FROM EMP_IN A, TEMP B
WHERE A.EMPNO = B.EMPNO
AND A.EMP_ID = EMPID)NP
ON(E.EMP_ID = NP.EMP_ID)
WHEN MATCHED THEN UPDATE SET E.SALARY = NP.SALARY,
E.BONUS = NP.BONUS
WHEN NOT MATCHED THEN INSERT (E.EMP_ID,E.SALARY,E.BONUS,E.CREATED_DATE)
VALUES (CASE Check_Upd_Ins.merge_counter(Check_Upd_Ins.c_inserting)
WHEN 0 THEN E.EMP_ID
END,
E.SALARY,E.BONUS,SYSDATE);
END LOOP;
/* Use insert count... using ETL Package*/
dbms_output.put_line(Check_Upd_Ins.get_merge_update_count(SQL%rowcount) || ' rows updated.');
dbms_output.put_line(Check_Upd_Ins.get_merge_insert_count || ' rows inserted.');
Check_Upd_Ins.reset_counters;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20000, SQLERRM(SQLCODE));
END Pr_EMP_Insupd;Perhaps I can help you with this piece of code and this link :
MERGE INTO bonuses D
USING (SELECT employee_id, salary, department_id FROM employees
WHERE department_id = 80) S
ON (D.employee_id = S.employee_id)
WHEN MATCHED THEN UPDATE SET D.bonus = D.bonus + S.salary*.01
WHEN NOT MATCHED THEN INSERT (D.employee_id, D.bonus)
VALUES (S.employee_id, S.salary*0.1);
http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96624/13_elems30.htm#37586
Joel P�rez -
Problem using TAPI triggers and merge statement
Hi,
I use Designer tapi triggers on a table. When I try to execute a merge statement, I get the following error:
ORA-06502: PL/SQL: numeric or value error: NULL index table key value.
Is there a restriction when using TAPI triggers and merge statements that anyone is aware of?No restrictions on MERGE commands that I know of. I have, however, seen the TAPI give inexplicable ORA-06502 errors. It would help to know what line in which procedure or trigger gave the error. That information should have been in the error stack.
-
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. -
Error in Merge statement for Oracle 10gR2
Hi,
When I use the MERGE statement to copy data across a database link (from 10gR2 to 10gR2 database), if I have both an update and insert clause it works fine, but if I omit the insert clause and have just update on its own, I get error "ORA-02064: distributed operation not supported".
Can anyone help on thisThis came up in a thread last week, the 10g versions of MERGE (without INSERT or with DELETE) did not appear to work over DB links.
-
Returning clause in MERGE statement
Hi ,
I'm using Oracle 10g Version
I tried the below code using UPDATE with Returning Clause & MERGE with Returning Clause .
I found NO errors while working with UPDATE statement . The following is the code with 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 getting the error PL/SQL: ORA-00933: SQL command not properly ended when working with 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 meProbably because the RETURNING INTO clause doesn't belong to MERGE statement. It's available only for INSERT, UPDATE and DELETE. Here is the quote from Oracle Documentation:
The static RETURNING INTO clause belongs to a DELETE, INSERT, or UPDATE statement. The dynamic RETURNING INTO clause belongs to an EXECUTEIMMEDIATE statement.
And here's the link.
RETURNING INTO Clause
Hope it helps.
Ishan
Maybe you are looking for
-
Migrated using PST, problem with replying to old mails now
Hi, we have migrated from Exchange 2007 to Exchange 2013. We built a new Exchange 2013 organization with new Active Directory... All new :) After exporting all mailboxes to PST's, we imported them using new-mailboximportrequest... Everything works fi
-
Japanese input with non-English keyboard
I installed a brandnew iMac for my wife. She wanted to have the system in Japanese, however the keyboard layout needs to be Swiss German (where we bought the HW). Now - when I use Roman fonts in Text Edit etc with the Swiss Input menu, everything is
-
What is the 'Other' section in iOS
I can't seem to find a definitive answer on Google. I noticed that the Other section on my iPhone is now taking up 1.3 GB of space and I'm just curious as to waht this is. I still have 10+ GB left so it's not a big deal, just curious as to what cou
-
AppStore past purchases not Showing up after updating to IOS6
After I go into my iphone 4s and I go to Appstore and check my purchased items non of my purchases show up. When i click in appstoreI> updates> purchased it either starts loading or crash. I can see my purchased items in my ipod 4G and my syster Ipho
-
Opening a pdf file on the host computer from a virtual machine (Microsoft Virtual PC) takes 10 - 15 min. In the meantime I'm watching Reader window, all white, except for the title bar. With Protected Mode disabled, opening a file is normal, 3 - 4 se