0

I currently wish to write a query to duplicate data in database while modifying one column.
First of all, my database structure:
table code

CURCD                                     NOT NULL VARCHAR2(3)
CODE                                      NOT NULL VARCHAR2(2)
ITEM                                               NUMBER(1)
DSCPT                                              VARCHAR2(20)

The unique idx is the curcd,code,item.

What I wish to achieve is duplicate data of code '80' with a set of code = '82'
So, my query will be insert into code (CURCD,CODE,ITEM,DSCPT) select CURCD,'82',ITEM,DSCPT from code where code = '80';
this is working. Then I planned to create for code = '83', but due to there is already having existing data in the table for code 83, can anyone giving advises on how to modify the script? The existing data is having curcd = 'MYR' and item is in (3,5)

I had tried the not exist without success.

2
Contributors
2
Replies
25
Views
2 Years
Discussion Span
Last Post by lps
0

@rch1231 it didn't work though. But I managed to done it by using 2 query instead of one query:

insert into code (CURCD,CODE,ITEM,DSCPT) 
select CURCD,'83',ITEM,DSCPT from code where code = '80' and CURCD != 'MYR';

insert into code (CURCD,CODE,ITEM,DSCPT) 
select CURCD,'83',ITEM,DSCPT from code where code = '80' and CURCD = 'MYR' and ITEM not in (3,5);
commit;

`

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.