SQL Triggers

Hi everyone,
I'm hoping someone could help me here without sledging me or referring to name calling like 'n00b'. I admit I am new with SQL, but a way to learn is to ask questions...so...
I'm stuck on a query in which I have to write a trigger that will implement an 'update cascade referential integrity rule' between any 2 tables in a database.
The two tables I have chosen are Charter and Charter Leg.
Basically, what I want the trigger to do is to change CHARTER_NBR in Charter Leg when I modify CHARTER_NBR in Charter.
CHARTER_NBR is a PK in Charter and a FK in Charter Leg.
This is what I've come up with so far:
CREATE OR REPLACE TRIGGER Upd_Cas_01
BEFORE UPDATE OF charter_nbr ON Charter
FOR EACH ROW
BEGIN
     UPDATE           Charter_leg
     SET           charter_nbr = new.charter_nbr
     WHERE          charter_nbr = old.charter_nbr
     DBMS_OUTPUT.PUT_LINE ('Corresponding Charter Number in the Charter Leg table has also been updated');
END;
Output:
TRIGGER Upd_Cas_01 Compiled.
UPDATE Charter
SET charter_nbr = 999
WHERE charter_nbr = 1;
Output:
Error starting at line 1 in command:
UPDATE Charter
SET charter_nbr = 999
WHERE charter_nbr = 1
Error at Command Line:1 Column:7
Error report:
SQL Error: ORA-04098: trigger 'UPD_CAS_03' is invalid and failed re-validation
I hope someone can help me out. Thanks.

thanx for the help guys...eventually solved it in the end...not really sure how, but i played around with my existing code and it finally compiled without an error.
the last trigger i need to write now is pretty complex and i doubt i can explain it properly, but here goes:
-checks when an Employee is allocated to a Charter, they are qualified,
and
-when a Helicopter is allocated, it is suitable for the Charter.
it basically has to be one HUGE trigger...wish me luck -_-
null

Similar Messages

  • Usage of SQL Triggers in SAP B1

    Hi All,
    I wanted to know if it is Permissible according to SAP to create a SQL Trigger in SAP Company and then affect the UDT's, based on certain criteria.
    Regards
    Rohan S. Kamble.

    Hey Gordon,
    Do you know of an SAP note that specifies that SAP will not support a customer that put triggers on system tables?
    We are experiencing difficulties upgrading a client and I am gathering information for a case.
    Thanks,
    Denis

  • Help with some PL/SQL Triggers

    hello there, I'm totally new using PL/SQL so I need your help with two triggers.
    For instance
    1. Compare two dates, and verify that there are different, you must send a message Error
    2. When I insert a new record, a trigger must obtain data from other tables and add it (on a new record)
    Maybe not the answers, maybe the way to go!
    Thks!

    Hi,
    Welcome to the forum
    1. Compare two dates, and verify that there are different, you must send a message Errorwhy trigger ?
    Trigger is Only for when DML Performed :)
    try 1st one in procedure..
    create or replace procedure testing(p_date in date)
    is
    v_date date;
    begin
    select to_date(hiredate,'mm-dd-rr') into v_date
    from emp
    where to_date(hiredate,'mm-dd-rr')=to_date(p_date,'mm-dd-rr');
    dbms_output.put_line(v_date);
    exception
    when others then
    dbms_output.put_line('No Data Found');
    end;
    2. When I insert a new record, a trigger must obtain data from other tables and add it (on a new record)i didn't understand can you please explain me in detail ?
    Thanks
    Venkadesh

  • Best way to get sequence.next value in pl-sql/triggers

    Hi,
    I want to know the best practice about to get the sequence.next value in pl-sql procedures / triggers from the below two methods.
    1. SELECT PRINT_BATCH_SEQ.NextVal INTO PSQNO FROM DUAL;
    INSERT INTO TABLE R1TMP VALUES (PSQNO, '12-MAR-06');
    2. INSERT INTO TABLE R1TMP VALUES (PRINT_BATCH_SEQ.NextVal, '12-MAR-06');
    From the above two statements which one is best with respect to performance / parsing /memory usage.
    Kindly give your suggession please.
    Thanks,
    Riaz.

    Hi,
    Thanks for your immediate reply.
    My thought was
    1. when we do like this, at the time of insert the cost of the operation will be more and this will lead some performance issue as bulk insert.
    2. If we get it from dual and send the value as bind variable, then we can avoid the parsing of the sql.
    Please correct me if i am wrong.
    thanks,
    riaz.

  • SQL Triggering Unique constraint

    Hi,
    I'm not quite sure why this SQL is not working. In a table called t_car I want to change the data in the SECTIONAA_NO column so they end with a J if there is not already one in the table. There is a unique constraint on the column.
    This SQL is triggering the unique constraint.
    update t_car t
    set t.SECTIONAA_NO = substr(t.SECTIONAA_NO, 1,5) || 'J'
    where not exists
    (select 1 from t_car j
    where j.SECTIONAA_NO = substr(t.SECTIONAA_NO, 1,5) || 'J')
    But when I put it in a PL/SQL loop (below) and do the updates row by row it works. What am I doing wrong in the SQL above?
    declare
    begin
    for rec in (select car_id from t_car) loop
    begin
    update t_car t
    set t.SECTIONAA_NO = substr(t.SECTIONAA_NO, 1,5) || 'J'
    where not exists
    (select 1 from t_car j
    where j.SECTIONAA_NO = substr(t.SECTIONAA_NO, 1,5) || 'J')
    and car_id = rec.car_id;
    exception
    when others then dbms_output.put_line(rec.car_id); rollback;
    end;
    end loop;
    end;

    All of the data in the column is of length 6. I want to change the last letter to be 'J' if the new value does not already exist. There's a unique constraint on the column.
    I don't think
    update t_car t
    set t.SECTIONAA_NO = substr(t.SECTIONAA_NO, 1,5) || 'J'
    where t.SECTIONAA_NO <> substr(t.SECTIONAA_NO, 1,5) || 'J')
    will work as I need to check the entire table for the existence of the new value,

  • SQL UPDATE from PL/SQL triggered by button

    I have a form with the normal buttons (create/save/delete) working.
    For 2 of the fields I want to introduce a calculation on demand system. What I did is: created a button compute and associated some PL/SQL with it. The button submits as "compute" (something I made up) and has a branch that goes back to the same page. The button's PLSQL code is the following process (After Submit):
    DECLARE
      rasaDom VARCHAR2(2);
      pRasaDom NUMBER;
    BEGIN
    tRace(:APP_SESSION, to_number(:P5_K));
    domRace(:APP_SESSION, rasaDom, pRasaDom);
    if (pRasaDom > 0 and pRasaDom <= 100) then
         :P5_RASADOM := rasaDom;
         :P5_PRASADOM := pRasaDom;
         update BOVIS.S_CIV_F SET RASADOM=rasaDom, PRASADOM=pRasaDom where K = to_number(:P5_K);
         commit;
         wwv_flow.debug('THEN! rasaDom=' || rasaDom || ' %=' || pRasaDom);
    end if;
    END;
    The problem is the the above UPDATE simply does not work!
    I should also mention that:
    - the normal update process does not run (which is fine), because:
    0.03: ...Do not run process "Apply MRU", process point=AFTER_SUBMIT, condition type=REQUEST_IN_CONDITION, when button pressed=
    - my process displays the success message
    - the "then" debug message shows just fine.
    It looks like the is a big rollback somewhere (this is why I added the commit there). My guess is that APEX is doing an update to the old value. What am I doing wrong?
    Thanks!
    Edited by: Şerban on 12.02.2009 03:43

    Hello:
    update BOVIS.S_CIV_F SET RASADOM=rasaDom, PRASADOM=pRasaDom where K = to_number(:P5_K);Your update statement is updating the columns back to their current values !
    If you want the rasaDom and prasadom updated to what is contained in p5_rasadom & p5_prasadom your code should be
         update BOVIS.S_CIV_F SET RASADOM=:P5_RASADOM , PRASADOM=:P5_PRASADOM  where K = to_number(:P5_K);
    ....Varad
    Edited by: varad acharya on Feb 12, 2009 4:51 AM

  • Error using Page Items in PL/SQL Triggers

    Hello all,
    I am trying to use a page item value in my PL/SQl trigger statement.Following is my trigger
    create or replace TRIGGER "cts_apps_temp_insert"
    BEFORE INSERT ON CTS_APPS_TEMP
    FOR EACH ROW
    DECLARE
    vComputer_ID NUMBER;
    vTemp varchar(200);
    BEGIN
    select computer_id into vComputer_ID from cts_hardware_info where computer_name = v('P105_DEVICE_NAME');
    INSERT INTO CTS_SERVER_APP_CUSTOMER(SERVER_ID,DEPT_APP_REL_ID,TECHNICAL_MANAGER,FUNCTIONAL,APPLICATION_COORDINATOR,MODIFYUSERID,DATEOFMODIFICATION)
    VALUES (vComputer_ID,:NEW.DEP_APP_REL_ID,:NEW.TECHNICAL_MANAGER,:NEW.FUCNTIONAL_MANAGER,:NEW.APPLICATION_COORDINATOR,v('APP_USER'),sysdate);
    END;
    But am getting an error when I try to insert the data from the form
    ORA-01403: no data found ORA-01403: no data found ORA-06512: at "ESDBA.cts_apps_temp_insert", line 5 ORA-04088: error during execution of trigger 'ESDBA.cts_apps_temp_insert'
    Error Unable to process row of table CTS_APPS_TEMP.
    OK
    I tried printing the value of v('P105_DEVICE_NAME'); from a pl/sql block...It doesnt print anything..
    Can anyone please tell mw why the page item value is becoming null?
    Is there any other way I can use the Page item value in the trigger?
    Thanks in Advance,
    Nehal
    Edited by: user11122439 on Jun 23, 2009 11:27 AM

    Thanks for helping me out Tony.
    It is a single row form. But the same form is used many time to add records for that particular server..
    In the first form the user enters the server details. In the second form they need to associate applications with the server name they entered in the first form.
    They can add any number of such applications.
    The contenst in my form are
    Server_name: ( read only field populated by the name they entered in the first form)
    application_name:
    Manger1:
    Manager2:
    When the user clicks on add button the applcaition should be associated to the server he added in the first form.For this I need the Id of the Server_name he added in the first form.
    I also need to store this info in a temporary table apart from the original Server-App relationt able. Thats the reason I had database trigger which was also adding stuff to a temporary table apart from adding the relationships to the main table.
    But even if we frget about hte temporary table can you please tell me how I can use the Page item value in form 1 and get its id from database and use it to insert server-app relation in second form?

  • PL/SQL - Triggers

    using triggers, if a new row is inserted in a table(t1) then the same data has to be inserted in another table(t2). how do i get the data that was inserted in the table(t1).
    please reply soooon,

    refer manual
    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14220/triggers.htm#g22503

  • Java Store Procs/Store Procs/Triggers

    Hi,
    I have cases in my application where I would require Store Procedures or triggers.
    Can I use Java Store Procedures, Regular Store procedures and triggers with iFS.
    Thanks,
    Mario

    We have not published the schema for IFS because it is not supported to write PL/SQL triggers or Java Stored Procedures based on changes in the underlying database tables.
    The supported way to handle these requirements is to write an Agent which registers for IfsEvents, and does work based on what events have occurred.
    See the JavaDoc for "IfsEvent" for more information.

  • Edit schema objects with sql workshop

    I am trying to setup the ability for admin type user to log in via
    HTMLDB and use the sql workshop to create / change objects in
    the owning schema.
    But I can't seem to get it right.
    I have a schema, this was prexisting before HTMLDB
    BOB which contains hundreds of objects. From the outside world, the users would log in as BOB with BOB's password to trouble shoot and develop PL/SQL - say with Toad or pl/sql developer.
    We have 2 htmldb applications that run from BOB and work great (HTMLDB is great!)
    The number of people needing access to BOB has increased dramatically.
    I have created HTMLDB users that log into the BOB HTMLDB workspace and can via all the table data and the like.
    But when they go to look at PL/SQL the screen is red and there is no wrapping of lines and no scroll bar to see everything.
    So, I assumed it is priveleges - I granted everything, same thing. I ran a select user from dual from the sql scripts screen and it comes back as HTMLDB_PUBLIC_USER.
    I have tried logging into the workspace with the BOB oracle user password - won't work (invalid credentials). I created an HTMLDB BOB user and it still hits the database as HTMLDB_PUBLIC_USER.
    Is it possible somehow to "link" Bob HTMLDB user to BOB oracle user so that when the user logs into HTMLDB sql work shop (even if it is as BOB) they can edit PL/SQL, triggers etc?
    So, basically - log into the database using a database user/pass but have access to the wonderful sql work shop and utilities tools?
    I have tried messing with the DAD etc, but doesn't seem to work.
    I have checked the documentation, can't find anything.
    Help please.

    Hi,
    you have a typo there. You need a "." before the xbl and htc.
    See here for the full config:
    Alias /i/ "/u05/oracle/oraweb/marvel/images/"
    AddType text/xml .xbl
    AddType text/x-component .htc
    <Location /pls/htmldb>
      SetHandler pls_handler
      Order deny,allow
      Allow from all
      AllowOverride None
      PlsqlDatabaseUsername HTMLDB_PUBLIC_USER
      PlsqlDatabasePassword PSWD
      PlsqlDatabaseConnectString MYSERVER:MYPORT:BOBSID ServiceNameFormat
      PlsqlDefaultPage htmldb
      PlsqlDocumentTablename wwv_flow_file_objects$
      PlsqlDocumentPath docs
      PlsqlDocumentProcedure wwv_flow_file_manager.process_download
      PlsqlAuthenticationMode Basic
      PlsqlNLSLanguage AMERICAN_AMERICA.US7ASCII
    </Location>Regards,
    ~Dietmar.
    P.S.: Make sure to clear the browser cache before retrying.
    Message was edited by:
    daust_de

  • Want information about triggers

    hi,
    What is trigger,
    what is use of trigger,

    Try reading [PL/SQL Triggers|http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/triggers.htm#g1043102]. There is no good reason to retype it here.
    >
    Yes. It's better to start with Concepts: [Overview of Triggers|http://download.oracle.com/docs/cd/E11882_01/server.112/e10713/srvrside.htm#i13313], of course.

  • 10.1.2.3 Forms is not working properly on OEL5

    Hi
    I just installed OracleAS Forms Reports 10.1.2.3 on OEL5 and when I try to see the form on the web it appears that PL/SQL triggers are not being fired. The When-New-Form-Instance trigger is not fired or when I click the commit button there is no response. I check the application.log and OC4J~OC4J_BI_Forms~default_island~1 and I don't see any errors.
    Any ideas where can I check to see errores?
    Regards,
    Néstor Boscán

    Of course you recompiled your forms on the new server? Maybe just do the obvious: put some debug messages in your triggers to see if they actually fire instead of trying to solve the problem by guessing? Or don't you have the sources available?
    cheers

  • How to read the DB application error in JSP

    We have the PL/SQL triggers that perform validations on the insert and update. If validation fails the RAISE APPLICATION ERROR is used.
    On error the errorpage.jsp is called correctly, but my problem is that I can not read the actual error message from database.
    All I am getting from exception.getMessage() is the JBO message. The exception.printStackTrace() does not help either. How can I read text of PL/SQL exception message ?
    I have tried this test in errorpage:
    if( exception instanceof oracle.jbo.JboException ) { ...}
    but apparently the exception is not JboException, since test fails.
    I read about ApplicationModule.setExceptionHandler() and even build exception handler which does not do anything. I assumed that this would allow all exceptions to be passed to the error page. Nothing like that happens though. I still see only last JBO exception, I can not see the original DB exception.
    Thanks in advance,
    Michael

    Hi ankur,
    thanks for the quick reply,
    I have got the answer for the first question.
    Can u tell me solution for the 2nd question also. how to read the Portal user information in VC. like reading the Portal user information in webdynpro.
    In webdynpro we can read any of the portal user properties or information like using the following code.
    Itry{
    IWDClientUser user = WDClientUser.getCurrentUser();
    String fName = user.getFirstName();
    String lName = user.getLastName();
    }catch(Exception e){
    In the same way to read the portal user information in VC. BCz for every portal user we have created one custom properties, we need to read that propety value in my vc application, when the user logged in to portal and accessing integrated VC application.
    I have seen one of the thead this is possible from VC7.0 of NW2004s, current my version is also the same.
    Portal 7.0
    VC 7.0
    If u know how to do that, can u let me know.
    Regards
    Vijay

  • Problems with import utility.

    Hello friends,
    I'm having very basic problems during a import process, I have to import a database from a .dmp file exported from someone else's system to my system. I don´t know the Oracle version that export was generated, but my Oracle version is 9.2.0.4.0. I´m having problems with PL/SQL triggers during process and errors like you can see below:
    IMP-00017: following statement failed with ORACLE error 20000:
    "DECLARE SREC DBMS_STATS.STATREC; BEGIN SREC.MINVAL := '0030'; SREC.MAXVAL "
    ":= '0068006900730074006F007200690063'; SREC.EAVS := 0; SREC.CHVALS := NULL;"
    " SREC.NOVALS := DBMS_STATS.NUMARRAY(973555660975280000000000000000000,21094"
    "03095248890000000000000000000); SREC.BKVALS := DBMS_STATS.NUMARRAY(0,1); SR"
    "EC.EPC := 2; DBMS_STATS.SET_COLUMN_STATS(NULL,'"BI_INV_CDISSC"','"LQM_SEQ_N"
    "UM"', NULL ,NULL,NULL,4,.25,0,srec,15,0); END;"
    IMP-00003: ORACLE error 20000 encountered
    ORA-20000: Unable to set values for column LQM_SEQ_NUM: does not exist or insufficient privileges
    ORA-06512: at "SYS.DBMS_STATS", line 3325
    ORA-06512: at "SYS.DBMS_STATS", line 3483
    ORA-06512: at line 1
    IMP-00058: ORACLE error 904 encountered
    ORA-00904: "LQM_SEQ_NUM": invalid identifier
    IMP-00017: following statement failed with ORACLE error 20000:
    "DECLARE SREC DBMS_STATS.STATREC; BEGIN SREC.MINVAL := '0030'; SREC.MAXVAL "
    ":= '0068006900730074006F007200690063'; SREC.EAVS := 0; SREC.CHVALS := NULL;"
    " SREC.NOVALS := DBMS_STATS.NUMARRAY(973555660975280000000000000000000,21094"
    "03095248890000000000000000000); SREC.BKVALS := DBMS_STATS.NUMARRAY(0,1); SR"
    "EC.EPC := 2; DBMS_STATS.SET_COLUMN_STATS(NULL,'"BI_INV_CDISSC"','"LQM_BATCH"
    "_ID"', NULL ,NULL,NULL,26,.0384615384615385,0,srec,16,0); END;"
    IMP-00003: ORACLE error 20000 encountered
    ORA-20000: Unable to set values for column LQM_BATCH_ID: does not exist or insufficient privileges
    ORA-06512: at "SYS.DBMS_STATS", line 3325
    ORA-06512: at "SYS.DBMS_STATS", line 3483
    ORA-06512: at line 1
    Can you guess?
    Thanks in advance,
    Marcello.

    Hi
    One of the metalink note suggested trying STATISTICS=RECALCULATE in your import parameter.
    Read more about it and try it.
    Hope it helps.
    Rgds
    Adnan

  • How to use P_SESSION.GET_VALUE_AS_VARCHAR2 in MDform item default Value

    I have a master detail form based on two tables. In the DETAIL_BLOCK section I have an item named 'APPROVAL_STATUS' based on the column of the same name in the underlying table. I have an unassociated textbox named CURR_APPROVSTAT in the detail form for which I would like to set it's default value to the current value of APPROVAL_STATUS when the master detail form is opened in %3D mode via a hyperlink.
    I have tried using the p_session.get_value_as_varchar2 in the default value field of the CURR_APPROVSTAT item, but it generates errors on run.
    EX:
    Item CURR_APPROVSTAT
    default value field
    p_session.get_value_as_varchar2(
    p_block_name => 'DETAIL_BLOCK',
    p_attribute_name => 'APPROVAL_STATUS')
    Default Value type:
    Function returns varchar2
    on run, it generates error that p_session must be declared (I get the same error if I use portal.p_session... also).
    default value field
    select p_session.get_value_as_varchar2(p_block_name => 'DETAIL_BLOCK', p_attribute_name => 'APPROVAL_STATUS')from dual
    Default Value type:
    SQL returns varchar2
    on run, it generates and error that a right parenthesis is missing.
    I have also tried using the following in the Additional PL/SQL - before displaying form:
    p_session.set_value
    (p_block_name => 'DETAIL_BLOCK'
    ,p_attribute_name => 'CURR_APPROVSTAT'
    ,p_value => p_session.get_value_as_varchar2(
    p_block_name => 'DETAIL_BLOCK',
    p_attribute_name => 'APPROVAL_STATUS')
    on run, this generates the error identifier 'P_SESSION.GET_VALUE_AS_VARCHAR2' must be declared
    My questions are:
    1) is it possible to use the p_session.get_value_as_varchar2 in the default value field?
    2) If yes, then what if the proper syntax
    3) If no, can I set this value when the MD form opens from the additional pl/sql triggers, and if so, what is the syntax?
    any assistance you can offer is greatly appreciated.
    Sincerely,
    ARM

    In my detail block I have 10 rows displaying that may or may not have data after querying. To set the default value in the detail block, you have to set the index value of p_session.set_value. Since I don't know how many rows are already populated, I'm setting the default value to all 10 rows. Is there a better approach?
    Here's my code example, which I've placed in the additional PL/SQL section before displaying the form...
    DECLARE
    l_district_id VARCHAR2(7);
    BEGIN
    l_district_id := p_session.get_value_as_varchar2
    (p_block_name => 'MASTER_BLOCK',
    p_attribute_name => 'A_DISTRICT_ID');
    FOR i in 1 .. 10 LOOP
    p_session.set_value
    (p_block_name => 'DETAIL_BLOCK',
    p_attribute_name => 'A_DISTRICT_ID',
    p_value => TO_CHAR(l_district_id), p_index => i);
    END LOOP;
    END;

Maybe you are looking for

  • Error while unloading data from teradata to a flatfile

    while executing the interface that writes data into a flat file from a table, the interface fails with the error message "Bytes are too big for array" any idea ?

  • Problem in MIGO

    Dear Friends, I have one query in migo. In particular one Purchase order, i am getting message like, "Purchase order 4400000030 has no items. Means when i put above po no and then press enter then above message is coming. I have find out that problem

  • Change Price with BAPI_PO_CREATE

    Hello, i am trying to create a purchase order using BAPI_PO_CREATE, everything is working fine except price modification.  All positions are created with organization and warehouse, but the prices is not changed, it uses the list price.  The code i a

  • Adobe Camera Raw 6.6

    Hello, I downloaded Camera Raw 6.6 but it won't work. Help?

  • 2008 r2 Secure by Computer

    I have been asked to secure a 2008 R2 terminal server in the was 2x securerdp worked however it doesn't seem to work on this server. what I really need is to stop people from using non domain workstations logging into a terminal server without a lot