t1
col1 col2
nishi 5000
lucky 6700
akash 7000
i want that a query that when i insert 7000 it will show me data already present and data will not insert. if data is not present it will insert.

Answer Posted / uday

The best thing would be to create a trigger which checks and not allows duplicate data .

Create or replace trigger trig1
before insert or update on t1
for each row
declare
a number (10);
begin
select count(*) into a from t1 where col2 = :new.col2;
if a >= 1 then
raise_application_error(-20123,'data already present and data will not insert');
elsif a = 0 then
dbms_output.put_line('inserted');
end if;
end;

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the use of Merge statement in oracle 11g

591


how may join possible between (requisition with purchase order)

1695


State the various uses of dbcc command?

544


How to loop through data rows in the implicit cursor?

537


Explain the use of rows option in exp command.

584






What do you mean by cdb and pdb in oracle 12c?

633


What happens in oracle commit?

561


How to pass parameters to procedures?

552


Difference between varchar and varchar2 data types?

658


How to add a new column to an existing table with a default value?

542


How does oracle handle read consistency?

674


What is PL/SQL ?

1106


why dont we assign not null constraint as table level constraint.

2251


Does oracle partitioning improve performance?

546


How to experiment a data lock in oracle?

593