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 do you bind variables in oracle?

0 Answers  


What is the effect of setting the value "CHOOSE" for OPTIMIZER_GOAL, parameter of the ALTER SESSION Command ?

2 Answers  


List the parts of a database trigger.

0 Answers  


How would you extract DDL of a table without using a GUI tool?

1 Answers  


How to display employee records who gets more salary than the average salary in the department?

0 Answers  






what are bitmap indexes? How does they work?

0 Answers  


What is different bet native dynamic sql and Dbms_Sql?

4 Answers   Thermotech,


If I have a select statment which retrives 2 rows, & that rows have the same data in all the fields except the last field and I want to merge the 2 rows to be in 1 row with concatenating the last field which have the different data.... eg: the 1st row has these fields: A-B-C the second row has: A-B-X ........ i want to merge the two row to be in one row like ----> A- B- C,X

2 Answers  


What are various constraints used in SQL?

1 Answers   Polaris,


i have a table and it has constraints and i want to get "ALTER TABLE table_name ADD CONSTRAINT constraint_name constraint type" this code must be in string type please help me if you want, i can give more explainings

2 Answers  


What is an Integrity Constrains ?

3 Answers  


There is a big table with "n" of rows and 40 + columns .It doesn't have primary key.How do you select the primary key. In other words how do you get the duplicate records.

2 Answers   Microsoft,


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)