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 |
Is it possible to enter only time value into a column of a table in sql?
What is the max number of columns in an oracle table?
why you need store procedure ? where do we use it in a Java project? can you get the code for as store procedure using in Java?
How to pass parameters to procedures in oracle?
What are the Characteristics of Data Files ?
what are bitmap indexes? How does they work?
What does sharding mean?
What is an oracle user role?
How to connect to a local oracle 10g xe server?
What is a Temporary Segment ?
1:-How to write to update command in a procedure in oracle which update two different table at a time 2:-How to write the select command in a procedure in oracle which give multiple records
What are joins..how many types of joins are there?
29 Answers Amdocs, CSC, TCS,