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

Which of the following is not a database object TABLESPACE TABLE INDEX NONE

1 Answers  


How to use "if" statements on multiple conditions?

0 Answers  


How do I use os authentication with weblogic jdriver for oracle and connection pools?

0 Answers  


Please explain drop constraint oracle?

0 Answers  


How do I uninstall oracle client from windows?

0 Answers  






Anyone have the Latest Oracle Dumbs?While u have please forard to narain1411@gmail.com

0 Answers  


Briefly explain what is literal? Give an example where it can be used?

0 Answers  


Hi, I want table structure shown below. How can i create this ? Num Name Address Addr1 Addr2 I want Addr1 and Addr2 under Address column. How can i achive this ? Is it possible ?

2 Answers   IBM,


What is oracle in java?

0 Answers  


How to define a variable of a specific record type?

0 Answers  


What do you mean by merge in oracle and how can you merge two tables?

0 Answers  


How to rebuild an index in oracle?

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)