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.
Answers were Sorted based on User's Feedback
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 |
Answer / ravi gali
hi u can use DUP_VAL_ON_INDEX exception
SQL> create table test(id number primary key);
Table created.
SQL> set serverout on
SQL>
begin
insert into test values(1);
exception
when DUP_VAL_ON_INDEX then
raise_application_error('duplicate value entered on the row ');
when others then
dbms_output.put_line('if u entered wrong data');
end;
| Is This Answer Correct ? | 1 Yes | 2 No |
Please explain me all types of Data models. Also give me the details if each model can have other name.for example:schematic data model is also known as conceptual data model and entity relation data model.
How do you get nicely formatted results from an oracle procedure that returns a reference cursor?
How to create a new tablespace in oracle?
how many columns can a plsql table have
I have table-A(1,2,3,4,4,5,6,6,6,7). how to get all duplicate values?what is sql query?
which is best institue to learn oracle 11i in ameerpet or maithrivanam or sr nagar please help
Why should I use oracle database?
Give the sequence in which triggers fired during insert operations, when the following 3 triggers are defined at the same block level ?
Name the three major set of files on disk that compose a database in Oracle?
What is the difference between Sleep and Wait? (Java)
select to_char('10','10') from dual This gives me an error oRA-1481 INVALID NUMBER FORMAT MODEL why? pls help
How translate command is different from replace?