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
What is the maximum limit on the number of columns in a table?
Calculate difference between 2 date / times in oracle sql?
How to drop a stored procedure in oracle?
How to use subqueries with the in operator using oracle?
How to display row numbers with the records?
How to execute a stored procedure in oracle?
What privilege is needed for a user to create tables in oracle?
ABOUT IDENTITY?
what is normalisation?what are its uses?
What is a dynamic performance view in oracle?
How to connect ms access to oracle servers?
What is an oracle tablespace?
Explain drop constraint oracle?
What is ASM (Automatic Storage Management) in Oracle?
Differentiate between pre-select and pre-query?