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



t1 col1 col2 nishi 5000 lucky 6700 akash 7000 i want that a query that when i i..

Answer / 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

t1 col1 col2 nishi 5000 lucky 6700 akash 7000 i want that a query that when i i..

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

Post New Answer

More Oracle General Interview Questions

How to retrieve values from data fields in record variables?

0 Answers  


How do we switch from init.ora file to asp file?

2 Answers  


Explain a data segment?

0 Answers  


what is the difference between UNION AND UNIONALL

4 Answers  


how to get the second max val for every group in a table

6 Answers   Verizon,






1.display list of all users from ur data base.what is the query?

3 Answers   CGI, IBM,


How to pass a cursor variable to a procedure?

0 Answers  


How to execute a stored program unit?

0 Answers  


when a grant option is encountered for a table EMP to a peer sitting beside you who has already having the table of that name (EMP), then what is the result?

2 Answers  


Please explain oracle left join with an example?

0 Answers  


Explain do view contain data?

0 Answers  


How do we get field detail of a table?

0 Answers  


Categories
  • Oracle General Interview Questions Oracle General (1789)
  • Oracle DBA (Database Administration) Interview Questions Oracle DBA (Database Administration) (261)
  • Oracle Call Interface (OCI) Interview Questions Oracle Call Interface (OCI) (10)
  • Oracle Architecture Interview Questions Oracle Architecture (90)
  • Oracle Security Interview Questions Oracle Security (38)
  • Oracle Forms Reports Interview Questions Oracle Forms Reports (510)
  • Oracle Data Integrator (ODI) Interview Questions Oracle Data Integrator (ODI) (120)
  • Oracle ETL Interview Questions Oracle ETL (15)
  • Oracle RAC Interview Questions Oracle RAC (93)
  • Oracle D2K Interview Questions Oracle D2K (72)
  • Oracle AllOther Interview Questions Oracle AllOther (241)