Create a trigger for to prevent  duplicate

Hi
How can I to build a trigger for insert , to prevent duplicate register when I use SQLLOADER ?

The user guide is your friend.
As for an unique index:
CREATE UNIQUE INDEX <name> ON <table>(<column1>, <column2>);Again, refer to the user guide.
C.

Similar Messages

  • How to create a trigger for particular value insertion?

    If I have a Table T, which has columns as A,B,C,D. I want to create a trigger to give an error message if someone inserts or updates T with values in A as '001' AND value in B as '99'
    Please reply soon....
    Thanks

    user8560155 wrote:
    I need a trigger only not a constraint...
    Why? Is there any valid reason for that?
    I tried the above trigger but it was not successful :(
    Can I use 'If statements' as well???The below will work..
    create table t
      a varchar2(10),
      b varchar2(10),
      c varchar2(10),
      d varchar2(10)
    create or replace trigger trig1
    after insert or update on t
    for each row
    --"trigger will be fired only when below condition is satisfied"
    when ( new.a = '001' or new.b = '99' )
    begin
    raise_application_error(-20000, 'Invalid value in A or B');
    end;
    insert into t(a) values('001');
    SQL Error: ORA-20000: Invalid value in A or B
    ORA-06512: at "SCOTT.TRIG1", line 2
    ORA-04088: error during execution of trigger 'SCOTT.TRIG1'
    insert into t(a) values('002');
    1 rows inserted.

  • Help me in creating a Trigger for Insert and Update Options

    Hi
    Please help me in creating a Trigger .
    My requirement is that after insert or update on a Table , i want to fire an event .
    I have started this way ,but doesn't know how to fully implement this .
    say i have a dept table
    CREATE TRIGGER DepartmentTrigger
    AFTER INSERT ON Dept
    BEGIN
    INSERT INTO mytable VALUES("123","Kiran");
    END DepartmentTrigger;
    Please tell me how can i put the Update option also .
    Thanks in advance .

    Please tell me how can i put the Update option also .Add "Or Update". ;-)
    Here are a few suggestions, but you definitely need to refer to the manual page that the previous poster suggested.
    CREATE OR REPLACE TRIGGER DepartmentTrigger
    AFTER INSERT Or Update ON Dept
    BEGIN
    INSERT INTO mytable VALUES(:new.Dept,'DEPT ADDED OR CHANGED');
    END DepartmentTrigger;
    The "Or Replace" means you can replace the trigger while you're developing without having to type in a drop statement every time. Just change and rerun your script, over and over until you get it right.
    Adding "Or Update" or "Or Delete" makes the trigger fire for those events too. Note, you may want seperate triggers in different scripts and with different names for each event. You have to decide if your design really does the same thing whether it's an insert or an update.
    :new.Dept is how you would refer to the changed vale of the Dept column (:old.Dept is the prior value). I changed the double quotes on the string in the VALUES clause to single quotes.
    Andy

  • Creating a trigger for update

    I have a table that consists of the following: product_id number, location number, qty number. product_id and location are primary keys.
    I want to create a trigger before an update and if the record doesn't exist that is trying to be updated, then I have to create the record.
    For example, if I want to do an update of the following:
    update inventory set qty = 80 where product_id=13 and location=45;
    Let's say that the record doesn't exist, how do I do this with a trigger.

    Hi,
    First of all i would like to clear one thing:
    IF you are trying to update any record and that record does not exist in table then trigger will not be called.
    "afiedt.buf" 10 lines, 236 characters
      1  CREATE OR REPLACE TRIGGER t_trig
      2  BEFORE UPDATE ON t
      3    FOR EACH ROW
      4    BEGIN
      5             DBMS_OUTPUT.PUT_LINE('Trigger has been  called!!!');
      6    EXCEPTION
      7       WHEN OTHERS THEN
      8               DBMS_OUTPUT.PUT_LINE('IN EXCEPTION:'||SQLERRM);
      9*  END;
    SQL>/
    Trigger created.
    SQL>DESC t;
    Name                                      Null?    Type
    NAME                                               VARCHAR2(20)
    SQL>SELECT * FROM t;
    NAME
    BBB
    1 row selected.
    SQL>SET SERVEROUTPUT ON
    SQL>
    SQL>UPDATE t SET NAME='XXX' WHERE name='AAA';
    0 rows updated.
    SQL>UPDATE t SET NAME='XXX' WHERE name='BBB';
    Trigger has been  called!!!  <-- Trigger called here
    1 row updated.So to achieve your result you have to do it outside the trigger.
    If you are updating trougha a procedure, after update statement you can use SQL%ROWCOUNT to get how many rows have been updated. If it zero you can insert the record.
    Regards

  • Creating a Trigger for Deleting the records from a parent Table

    I am new to creating Trigger
    We will need several small tables that will be used to store any records that are deleted by the owner of the table. These will likely need a trigger where we would Delete from the parent table and on that Delete populate the child table with the previous record's data.
    Please give me a pseudo code for this
    Thanks
    John
    Edited by: user10750995 on Dec 30, 2008 9:06 AM

    Something like this:
    CREATE OR REPLACE TRIGGER trg_my_table_hist
    AFTER DELETE
    ON my_table
    FOR EACH ROW
    BEGIN
    INSERT INTO Hist_MyTable
    ( column1, column2, ..., DELETION_DATE)
    VALUES
    (:OLD.column1, :OLD.column2, ...., SYSDATE);
    END;
    /My_Table is your main table. When a row is deleted, the trigger will be fired and copy the deleted row to another table called Hist_My_Table. I'm supposing that the history table has all columns as they are defined in main tables plus a column named DELETION_DATE.
    My experience indicates that, probably, it's a good idea maintain update history and the user. But it depends on your requests.
    Regards,
    Miguel

  • Create a trigger after delete

    Hi,
    I would a distributed database with two database. I have a orders tables on both the database. I would like to create a trigger for when deleting a record from one database would delete from the other database.
    CREATE OR REPLACE TRIGGER orders_after_delete
    AFTER DELETE ON orders
    BEGIN
    -- DELETE record into orders table in Database 1 (DB1)
    END;
    Thanks.

    Your trigger is (after) STATEMENT level trigger.
    What happens if you delete two (or more) rows using one DELETE statement:
    ORA-01427: single-row subquery returns more than one row.
    Use "WHERE o_id IN (SELECT...)"
    instead of "WHERE o_id = (SELECT...)".
    Another way is to use simple ROW level trigger:
    CREATE OR REPLACE TRIGGER orders_after_delete
      AFTER DELETE ON orders
      FOR EACH ROW
    BEGIN
      DELETE orders@DB1Link
       WHERE o_id = :OLD.o_id;
    END;
    /But, with row level trigger, one local DELETE statement launches more remote DELETE statements (one for each deleted row) .
    This can cause performance and/or integrity problems (if table has self-referential integrity constraint, for example).
    Regards,
    Zlatko

  • GeoRasterException: -13463 .. even after creating DML trigger

    Hi all
    i am getting the following exception :
    oracle.spatial.georaster.GeoRasterException: -13463;GeoRaster object with rasterId = 281, rdt = null not found in system data view.
    Please create DML trigger for its table and column. Do:
    sdo_geor_utl.createDMLTrigger('tableName','columnName')
    at oracle.spatial.georaster.JGeoRaster.getRasterSubset_NoComp(JGeoRaster.java:1001)
    at oracle.spatial.georaster.JGeoRaster.getRasterSubset(JGeoRaster.java:798)
    at oracle.spatial.georaster.JGeoRaster.getRasterImage(JGeoRaster.java:2510)
    at oracle.spatial.georaster.JGeoRaster.getRasterImage(JGeoRaster.java:2038)
    at spdb.SpatialQuery.getRaster(SpatialQuery.java:68)
    at spdb.SpatialQuery.main(SpatialQuery.java:91)
    I have created the DML trigger using
    sdo_geor_utl.createDMLTrigger('IMGTABLE','RASTER');
    but still i keep getting the same error
    what am i doing wrong
    THanks

    AB,
    about your application, please consider these:
    If your original images are seamlessly mosaickable, it's better to mosaick them into one large image and then query. Note, the requirement from the oracle 10g sdo_geor.mosaic is very strict.
    But I guess, in most apps, this is not practical. So, you have to query multiple images and do some work in your app. The approach could be:
    1. Since your images are all georeferenced, call sdo_geor.generateSpatialExtent and populate the spatial extent for all images. Then build a spatial index (RTree) on the georaster table based on the spatial extents. Note, If the georaster objects have different model spaces, you need call sdo_cs.transform to convert the extents to the same SRID. You can also directly update the spatial extents using a right/appropriate geometry.
    2. Spatially query the GeoRaster table using your area-of-interest geometry in a single sql stmt to filter out all the georaster objects which overlap or partially overlap your AOI.
    3. call getRasterSubset on each georaster object of the above result set with a proper window.
    4. the BLOBs returned by getrastersubset don't have any metadata inside them, but you can easily and precisely figure out their dimension sizes, cell depth, interleaving etc based on the metadata of the georaster objects as well as your query criteria (i.e., band numbers, window sizes and pyramid levels).
    5. get all blobs into your app. then you can either directly work on them, such as mosaick them into one image for display, OR you can generate RenderedImages (very easy to do thru JAI) and directly display them into one image (ie, simply render the images in a window) or call JAI rotate/tranform/mosaic to create a single image.
    The above approach has been done in many of our partner products, such as PCI FOCUS and Geomatica, Leica ERDAS Imagine and LPS.
    In addition, Oracle Applicattion Server MapViewer has this capability as well, which you might consider to use.
    Hope this helps.
    Best Regards,
    Jeffrey

  • Trigger for more  than One table

    Hi,
    is it possible to create a trigger for more than one table?
    I need a trigger that fires when anyone of the users updates a special value in one of the DB tables.
    this value is in about 8 or 10 tables, or must i create a trigger for each table?
    thanx
    marcel

    You would wrap the functionality required into a packaged procedure and then have a trigger on each of these tables that simply call this packaged procedure.
    Yes, you would have one trigger per table.

  • How to create a scenarios for duplicate entries

    Hi friends,
    Please help me how to create a scenarios for duplicate entries, we are using stock transfer orders from there we need to create scenarios for duplicate entries, please guide me on the same.

    Hi,
    F-01 can be used to create a sample document.
    Regards
    Aditya

  • How to create a database trigger for automatic run statspack.snap

    Hi,
    I want to create a database trigger to run statspack.snap at startup.
    connect /as sysdba
    grant create any trigger to perfstat;
    connect perfstat/perfstat
    create or replace trigger auto_snap
    after startup on database
    begin
    statspack.snap;
    end;
    after startup on database
    error at line 2:
    ora-01031: insufficient privileges
    connect /as sysdba
    create or replace trigger perfstat.auto_snap
    after startup on database
    begin
    statspack.snap;
    end;
    Trigger created.
    after shutdown and startup the database, the trigger has not been run. (no statspack snapshot)
    What I have done wrong?

    981145 wrote:
    hi... I have created a database link but it is showing some error. Can you please tell me, do we have to update the details in TNSNAMES.ora file regarding the database which i am creating now before creating database link?????
    awaiting for your response,
    Thanks in advanceI'm sorry, but "showing some error" is NOT an actionable error message. Why do you think we can solve your error if you don't tell us what the error is?
    Yes you will need to adjust your tnsnames. When a process in a database_A accesses database_B via a dblink in database_A, the database_A is acting as a client to database_B. At that point database_A is just like sqlplus or sqldeveloper, and all tns considerations are the same.

  • How do I create a trigger script for BOT on Xcode 5 CI?

    When creating a bot for xcode 5 CI, I am offered to use custom script to trigger on every commit. how do I create this script?
    xcode help page: https://help.apple.com/xcode/mac/1.0/#apdE6540C63-ADB5-4B07-89B7-6223EC40B59C
    Click Schedule, then change the settings as desired.
    Example values are shown with each setting.
    Schedule:
    Choose to run manually, periodically, on new commits, or on trigger scripts.

    Did you ever figure this out?
    Been searching the web endlessly without any results.

  • Trying to create trigger for some action to take place after a user logs on

    Hello,
    I want to create a trigger to fire after a user logs on. How to write this trigger.
    I am getting an error with syntax below. Thank you.
    create or replace trigger after_logon_xxtestuser
    after logon
    on xxtestuser.xxtestuser
    begin
    alter session set nls_territory = France;
    end;
    /

    I figured it out...
    create or replace trigger after_logon_xxtestuser
    after logon
    on xxtestuser.schema
    begin
    execute immediate 'alter session set nls_territory = France';
    end;
    /

  • Preventing duplicate rows insertion

    suppose i have a table with 2 columns
    no constraints are there
    then how i will prevent duplicate rows insertion using triggers.

    but i tried to solve the poster's requirement.yes, but the trigger does not solve it.
    The example you posted above, try this:
    do the first insert in your first sql*plus session, and then without committing, open another sql*plus session and do the second insert.
    Do you see an error?
    SQL> create table is_dup(x number, y varchar2(10));
    Table created.
    SQL> CREATE OR REPLACE TRIGGER chk
      2      BEFORE INSERT ON is_dup
      3      FOR EACH ROW
      4  BEGIN
      5      FOR i IN (SELECT * FROM is_dup)
      6      LOOP
      7          IF (:NEW.x = i.x) AND
      8             (:NEW.y = i.y)
      9          THEN
    10              raise_application_error(-20005, 'Record already exist...');
    11          END IF;
    12      END LOOP;
    13  END;
    14  /
    Trigger created.
    SQL> insert into is_dup values(123,'MYNAME');
    1 row created.
    SQL>
    SQL> $sqlplus /
    SQL*Plus: Release 10.2.0.1.0 - Production on Sun Apr 23 10:17:07 2006
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> insert into is_dup values(123,'MYNAME');
    1 row created.
    SQL> exit
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> select * from is_dup ;
             X Y
           123 MYNAME
           123 MYNAME
    SQL> commit ;
    Commit complete.
    SQL> select * from is_dup ;
             X Y
           123 MYNAME
           123 MYNAME
    SQL>

  • Need advice on preventing duplicate entries in People table

    Hi,
    In my database, I have a "People" table where I store basic information about people e.g. PersonId, FirstName, LastName, Gender, etc.
    There will be lots of entries made into this table and I want to prevent duplicate entries as much as humanly possible. I'd appreciate some pointers on what I should do to minimize duplicates.
    My primary concerns are:
    Duplicate entries for the same person using the person's full name vs. given name e.g. Mike Smith and Michael Smith
    Making sure that two separate individuals with identical names do get entered into the table and get their unique PersonId's.
    Not even sure how I can even possibly know if two individuals with identical names are two different people without having additional information but I wanted to ask the question anyway.
    Thanks, Sam

    Thank you all very much for your responses.
    There are three separate issues/points here.
    It is clear that it is impossible to prevent duplicates using only a person's first, middle and last names. Once I rely on an additional piece of information, then things get "easier" though nothing is bullet proof. I felt that this was self evident but
    wanted to ask the question anyway.
    Second issue is "potential" duplicates where there are some variations in the name e.g. Mike vs Michael. I'd like a bit more advice on this. I assume I need to create a table to define variations of a name to catch potential duplicates.
    The third point is what Celko brought up -- rather nicely too :-) I understand both his and Erland's points on this as typical relational DB designs usually create people/user tables based upon their context e.g. Employees, Customers, etc.
    I fundamentally disagree with this approach -- though it is currently the norm in most commercial DB designs. The reason for that is that it actually creates duplicates and my point is to prevent them. I'm going for more of an object based approach in the DB
    design where a person is a person regardless of the different roles he/she may play and I see no reason in repeating some of the information about the person e.g. repeating first, last name, gender, etc in both customer and employee tables.
    I strongly believe that all the information that are directly related to a person should be kept in the People table and referenced in different business contexts as necessary.
    For example, I assign every person a PersonId in the People table. I then use the PersonId as part of the primary key in the Customers or Employees table as well. Obviously, PersonId is also a foreign key in Customers and Employees tables. This prevents the
    need for a separate CustomerId and allows me to centralize all the personal data in the People table.
    In my opinion this has three advantages:
    Prevent duplication of data
    Allow global edits e.g. if the last name of a female employee changes, it is automatically updated for her within the context of "Customer" role she may play in the application.
    Last but not least, data enrichment where a person may enter additional data about himself/herself in different contexts. For example, in the employee context, we may have the person's spouse information through "Emergency Contacts" which may come handy
    within the context of customer for this person.
    Having everyone in the People table gives me these three advantages.
    Thanks, Sam

  • Preventing duplicates in Aperture?

    I'm using the Import function (not dragging from the Finder) JPG photos and I have the box checked "do not import duplicates" - yet when I import files into the same project I'm getting duplicates and they are the exact same file name.  Is there some other setting I need to have checked or this a bug - does anyone know?  It is definitely creating a lot of manual work to try and get rid of the duplicates once I've completed the import.  Thanks for any help anyone can provide. 

    If you import from the same card into the same project, then it shouldn't duplicate. That said, this functionality is imperfect.
    The best way to prevent duplicates is to not continually import the same files. When you import, you have the ability to choose what files you import; you should only select new files.

Maybe you are looking for