Table Has C1 And C2 Column If Exits any record in c1 then
Update c2 record Otherwise insert new record in the C1 And
C2 (Using Procedure)

Answers were Sorted based on User's Feedback



Table Has C1 And C2 Column If Exits any record in c1 then Update c2 record Otherwise insert new rec..

Answer / ron

use oracle's new feature called upsert :

merge t1
using (select * t1) t2
on (t1.col1=t2.col1)
when matched then
update set col2='value'
when not matched then
insert into (col1, col2) values ('val1', 'val2');

Is This Answer Correct ?    3 Yes 0 No

Table Has C1 And C2 Column If Exits any record in c1 then Update c2 record Otherwise insert new rec..

Answer / dinesh a.

select * from x;

C1 C2
----- ----------
1
2
3
4
5
6
7
8
9
10


1 create or replace procedure updt_x is
2 cnt number(4);
3 begin
4 select count(1) into cnt from x where c1 is not null;
5 if cnt > 0 then
6 update x
7 set c2=10;
8 else
9 insert into x
10 values(1,2);
11 end if;
12 commit;
13* end;

SQL> execute updt_x;

PL/SQL procedure successfully completed.

SQL> select * from x;

C1 C2
---------- ----------
1 10
2 10
3 10
4 10
5 10
6 10
7 10
8 10
9 10
10 10

10 rows selected.


SQL> delete from x;

10 rows deleted.

SQL> commit;

PL/SQL procedure successfully completed.

SQL> select * from x;

C1 C2
---------- ----------
1 2

Is This Answer Correct ?    2 Yes 0 No

Table Has C1 And C2 Column If Exits any record in c1 then Update c2 record Otherwise insert new rec..

Answer / ramprasad.s

Hi Answer to Your question
IS
create or replace procedure samp(cname IN sample.ename%type,
cno IN sample.eno%type)
AS
ccount number;
begin
select count(*) INTO ccount from sample;
IF ccount = 0 then
update sample set ename = cname;
else
insert into sample values(cname, cno);
END IF;
END;


Sample Table is
ENAME ENO
100

Is This Answer Correct ?    1 Yes 0 No

Table Has C1 And C2 Column If Exits any record in c1 then Update c2 record Otherwise insert new rec..

Answer / senthilkumar

create or replace procedure update is

declare

cursor updt is

select cl from table;

num number(4);

begin

open updt;

fetch updt into num;

if num != NULL

then
update table set c2 = num or(desired data);


else
insert into table values(value,value);


exception

when others then

DBMS_OUTPUT.PUT_LINE('SQLERR'|| ''||SQLERRM);

end;

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Oracle General Interview Questions

Why do we need oracle client?

0 Answers  


How to manage transaction isolation level?

0 Answers  


select to_char('10','10') from dual This gives me an error oRA-1481 INVALID NUMBER FORMAT MODEL why? pls help

6 Answers  


Which dictionary view(s) would you first look at to understand or get a high-level idea of a given Advanced Replication environment?

0 Answers  


Why does oracle 9i treat an empty string as null?

0 Answers  






Oracle

0 Answers   ABC, Genpact, HUI, Oracle,


What is a data dictionary and how can it be created?

0 Answers  


Whats the benefit of dbms_stats over analyze?

0 Answers  


How to write numeric literals in oracle?

0 Answers  


What privilege is needed for a user to create indexes in oracle?

0 Answers  


Difference between primary key and unique key ?

77 Answers   Accenture, B2B Software Technologies, Cognizant, HP Finsoft, IndiaNIC, Karomi Technology, Keane India Ltd, L&T, Onward eServices, R Systems, Shakti, Techtic Solutions,


Explain can a view based on another view?

1 Answers  


Categories
  • Oracle General Interview Questions Oracle General (1789)
  • Oracle DBA (Database Administration) Interview Questions Oracle DBA (Database Administration) (261)
  • Oracle Call Interface (OCI) Interview Questions Oracle Call Interface (OCI) (10)
  • Oracle Architecture Interview Questions Oracle Architecture (90)
  • Oracle Security Interview Questions Oracle Security (38)
  • Oracle Forms Reports Interview Questions Oracle Forms Reports (510)
  • Oracle Data Integrator (ODI) Interview Questions Oracle Data Integrator (ODI) (120)
  • Oracle ETL Interview Questions Oracle ETL (15)
  • Oracle RAC Interview Questions Oracle RAC (93)
  • Oracle D2K Interview Questions Oracle D2K (72)
  • Oracle AllOther Interview Questions Oracle AllOther (241)