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)
Answer Posted / 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 |
Post New Answer View All Answers
Database is hung. Old and new user connections alike hang on impact. What do you do? Your SYS SQLPLUS session IS able to connect.
15. Display the item_cost and then truncate it to the nearest hundred, ten, unit, tenth and hundredth.
What is the purpose of save points in oracle database?
What are the parameters that we can pass through a stored procedure?
How to convert characters to numbers in oracle?
Explain the use of constraints option in exp command.
What is a trigger and what are its types in oracle?
How to select all columns of all rows from a table in oracle?
What is a nvl function? How can it be used?
Explain an exception?
How to join two tables in a single query using oracle?
Differentiate between pre-select and pre-query?
How to export several tables together?
Can we insert data in view oracle?
What do you mean by merge in oracle and how can you merge two tables?