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 |
Why does Oracle not permit the use of PCTUSED with indexes?
What is the difference between primary key and unique key and foreign key in oracle?
What is Normalization ?
55 Answers ACS, Genpact, Graphix Solution, IBM, Keane India Ltd, TCS, Vault,
nw i'm doing MBA system and planning to do oracle,database management.tell me that whether it is useful r not?.refer any course for my carrier pls
Can u make a synonym for deptno=10 only from emp table.
1. How actually index will work ? 2. Why do people prefer mostly bitmap index and btree index in datawarehouse ? 3. If I use the column in aggrigate functions like max,min,count and avg and if I have a index created on that column, will it increases the performance ?
Define Transaction ?
What is the fastest query method to fetch data from the table?
What is a sub query? What are its various types?
Query to retrieve record for a many to many relationship ?
Without giving condition how to retrieve the unmatched records from table.
What is a deadlock in SQL? How can you prevent it?