Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

merge update insert into with exception ????

645300Oct 6 2009 — edited Oct 6 2009
Hello Gurus!!

i have trouble using exception in merge update insert into ...below is the code

merge into test t
using (select distinct
col1, col2, col3,id, job_id
from test1
where job_id = curr_job_id -- cur_job_id is variable which is declared
union
select distinct
col1, col2, col3,id, job_id
from test2
*where job_id = curr_job_id --cur_job_id is variable which is declared*
*) ss*
on (t.id = ss.id
AND t.job_id = ss.job_id)

when matched then update
set t.col1 = ss.col1,
t.col2 = ss.col2,
t.col3 = ss.col3
when not matched then insert into
*( t.col1,*
t.col2,
* t.col3,*
t.id,
t.job_id
*)Values*
*( ss.col1,*
* ss.col2,*
ss.col3,
ss.id,
ss.jobid,
*)*
The above code works absolutely fine....id is a PK

But i was trying to include exception to push the records in our error table
if i get any null records or bad records. But it doesnt works

Below is the code which doesnt works

merge into test t
using (select distinct
col1, col2, col3,id, job_id
from test1
where job_id = curr_job_id -- cur_job_id is variable which is declared
union
select distinct
col1, col2, col3,id, job_id
from test2
*where job_id = curr_job_id --cur_job_id is variable which is declared*
*) ss*
on (t.id = ss.id
AND t.job_id = ss.job_id)

when matched then update
set t.col1 = ss.col1,
t.col2 = ss.col2,
t.col3 = ss.col3
when not matched then insert into
*( t.col1,*
t.col2,
* t.col3,*
t.id,
t.job_id
*)Values*
*( ss.col1,*
* ss.col2,*
ss.col3,
ss.id,
ss.jobid,
*)*
exception
when others then
insert into error_table (
col1,
col2,
* col3,*
id,
job_id )
values ( ss.col1,
* ss.col2,*
ss.col3,
ss.id,
ss.jobid,
*)*


WHen i use exception, i get error saying :- *"ss.col1" column is not allowed here*

Any idea guys ???
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 3 2009
Added on Oct 6 2009
7 comments
1,123 views