Results 1 to 5 of 5

Thread: How to insert values

  1. #1
    Junior Member
    Join Date
    Dec 2007
    Answers
    1

    How to insert values

    How to insert values?

    I have on table having four columns,
    There is no primary Key to table.
    There are some records in the table

    Now I am inserting new records, but before insertion, I wants to verify If the records with same values is present in table or not? If it is , then insertion will not be done. else record shall be inserted. I m thinking about triggers. When I use insert option, table is get lock & I am not able to use it.

    So I request all to guide me.


  2. #2
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    Re: How to insert values

    You can do the same with help of a procedure. Before inserting data to the table check for count of that record in the specified field. If count returns 0 then only insert else raise some error message.


  3. #3
    Expert Member
    Join Date
    Apr 2007
    Answers
    500

    Re: How to insert values

    Follow this sample trigger
    CREATE OR REPLACE TRIGGER emp_tri before insert on emp for each row
    declare
    x char;
    begin
    begin
    select 'X' into x from dual where exists (select * from emp where empno=:new.empno);
    exception
    when no_data_found then
    x:=null;
    end;
    if nvl(x,' ')='X' then
    raise_application_error(-20000,'Data already entered');
    end if;
    end;


  4. #4
    Junior Member
    Join Date
    Dec 2007
    Answers
    1

    Re: How to insert values

    Thank u...

    But I get the values (to be insert) from system, automatically,after each 5 mins. & before inserting these values I wants to check whether these values are present in table if they r, then not permit them to insert. else insert them in table


  5. #5
    Contributing Member
    Join Date
    Nov 2007
    Answers
    53

    Re: How to insert values

    Quote Originally Posted by RupeshDharne View Post
    How to insert values?

    I have on table having four columns,
    There is no primary Key to table.
    There are some records in the table

    Now I am inserting new records, but before insertion, I wants to verify If the records with same values is present in table or not? If it is , then insertion will not be done. else record shall be inserted. I m thinking about triggers. When I use insert option, table is get lock & I am not able to use it.

    So I request all to guide me.
    Dear RupeshDharne,

    If you want to do this using trigger then it will not possible to do the same
    because while writing trigger on a table, you cannot use the DML on the same
    table. It will give Mutating error.

    You can do this at Form Level as follows:

    Suppose you have 4 columns

    A B C D

    consisting some data.

    Now before applying any DML you check first whether the values in
    the Text boxes or variables in your form, are there in your table or not.
    You can do this by using SELECT statement.

    Try this and reply if problem persists.

    Have a pleasant time


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact