Custom Trigger issues on PO_DISTRIBUTIONS_ALL table... null id?

Hi...I have a custom after insert trigger on the PO_DISTRIBUTIONS_ALL table
It is having an issue with getting the req_distribution_id
I took out all the code and left in just a test, which only inserts the id into a test table. But it is always null! Can someone tell me why? Because there is an ID when created, and I see it after I query the table when it is finished. But I figured, after insert it will be there!
Below is the trigger...
create or replace
TRIGGER APPS.xxmc_po_distributions_auir
AFTER INSERT OR UPDATE ON PO_DISTRIBUTIONS_ALL
REFERENCING NEW AS new OLD AS old
FOR EACH ROW
DECLARE
v_trigger_location VARCHAR2(2000):= 'Declaration';
v_error_message VARCHAR2(2000);
BEGIN
delete from test_table;
insert into test_table values(to_char(:new.req_distribution_id));
END;
This enters null every time into the table. Why is that?
-J

OK my new trigger has the dml statements in a procedure and it still fails. The ID is always null. Below is the trigger...why is the id coming up null???
:new.req_distribution_id should never be a null value in my opinion, right?
create or replace
TRIGGER APPS.xxmc_po_distributions_auir
AFTER INSERT OR UPDATE ON PO_DISTRIBUTIONS_ALL
REFERENCING NEW AS new OLD AS old
FOR EACH ROW
DECLARE
v_trigger_location VARCHAR2(2000):= 'Declaration';
v_error_message VARCHAR2(2000);
/* Error Tracking local variables */
v_user_id NUMBER := FND_GLOBAL.User_Id;
v_inv_record_id_s NUMBER := 0;
v_mycall_status VARCHAR2(20);
v_myerror_msg VARCHAR2(200);
v_ric_code VARCHAR2(10);
v_tracking_id VARCHAR2(200);
v_source_system xxmc_track_summary.source_system%TYPE := 'XXMC_CRM';
v_destination_system xxmc_track_summary.destination_system%TYPE := 'XXMC_CRM';
v_rice_name xxmc_track_summary.rice_object_name%TYPE := 'E120';
v_failure_record_count xxmc_err_track_det.error_count%TYPE := 0;
v_module_name xxmc_err_track_det.procedure_name%TYPE := 'XXMC_PO_DISTRIBUTIONS_AUIR';
v_stg_tablename xxmc_track_summary.staging_table_name%TYPE := '';
v_processed INTEGER := 0;
v_failed INTEGER := 0;
v_total INTEGER := 0;
v_commit INTEGER := 0;
e_error_tracking_exception EXCEPTION;
CURSOR c_get_req_line_info(p_req_distribution_id IN NUMBER) IS
SELECT PORH.SEGMENT1
, porh.attribute1 po_heading_att1
, porl.line_num
, porl.destination_context
, porl.attribute1
, porl.attribute3
, porl.attribute4
, porl.attribute5
, porl.attribute6
, porl.attribute7
, porl.attribute8
, porl.attribute9
, porl.attribute10
, porl.attribute11
, porl.attribute12
, porl.requisition_line_ID
, to_char(porl.creation_date, 'mm/dd/yyyy hh24:mi:ss') format_create_date_line
FROM PO_REQ_DISTRIBUTIONS_ALL PORD
, PO_REQUISITION_LINES_ALL PORL
, PO_REQUISITION_HEADERS_ALL PORH
WHERE PORD.DISTRIBUTION_ID = p_REQ_DISTRIBUTION_ID
AND PORL.REQUISITION_LINE_ID = PORD.REQUISITION_LINE_ID
AND PORH.REQUISITION_HEADER_ID = PORL.REQUISITION_HEADER_ID
i number := 0;
TEMP NUMBER;
BEGIN
v_trigger_location := 'Beginning of trigger body';
KMG_WRITE('INSERTING IN XXMC TRIGGER ON PO DISTRIBUTIONS AT '
|| TO_CHAR(SYSDATE, 'MM/DD/YYYY HH24:MI:SS')
|| ' REQ_DISTRIBUTION_ID = '
|| NVL(TO_CHAR(:new.req_distribution_id), 'VALUE IS NULL') );
xxmc_tracking_pkg.create_source_tracking_record(
p_tracking_id => v_tracking_id
,p_source_system => 'XXMC_CRM'
,p_destination_system => 'XXMC_CRM'
,p_rice_object_name => v_rice_name
,p_creation_date => sysdate
,p_created_by => v_user_id
,p_transaction_type => 'XXMC_CRM'
,p_status => 'INFLIGHT'
,p_if_direction => 'O'
,p_sub_status => 'XXMC_PROCESSING_IN_EBS'
,p_src_total_records => 0
,p_call_status => v_mycall_status
,p_error_msg => v_myerror_msg);
IF v_mycall_status <> 'S' THEN
RAISE e_error_tracking_exception;
END IF;
TEMP:='AAA';
i := 0;
FOR r IN c_get_req_line_info(:new.req_distribution_id) LOOP
i := i + 1;
UPDATE po_lines_all pol
SET attribute_category = r.destination_context
, Attribute1 = r.attribute1
, Attribute3 = r.attribute3
, Attribute4 = r.attribute4
, Attribute5 = r.attribute5
, Attribute6 = r.attribute6
, Attribute7 = r.attribute7
, Attribute8 = r.attribute8
, Attribute9 = r.attribute9
, Attribute10 = r.attribute10
, Attribute11 = r.attribute11
, Attribute12 = r.attribute12
WHERE pol.po_line_id = :new.po_line_id;
UPDATE po_headers_all poh
SET attribute1 = r.po_heading_att1
WHERE poh.po_header_id = :new.po_header_id;
END LOOP;
EXCEPTION
WHEN e_error_tracking_exception THEN
kmg_write('Could not create source tracking record in XXMC PO DISTRIBUTIONS trigger. Status = '
|| v_mycall_status || ' Msg = ' || v_myerror_msg);
RAISE_APPLICATION_ERROR (
num=> -20003,
msg=> 'XXMC PO DISTRIBUTIONS trigger error in '
|| ' create_source_tracking_record '
|| v_myerror_msg);
WHEN OTHERS THEN
v_error_message := SQLERRM;
kmg_write('Error in XXMC PO DISTRIBUTIONS trigger. ' || v_error_message);
xxmc_tracking_pkg.log_then_report_errors(
p_tracking_id => v_tracking_id
,p_source_system => v_source_system
,p_destination_system => v_destination_system
,p_det_record_id => v_inv_record_id_s
,p_message_name => 'XXMC_PO_DISTRIBUTIONS'
,p_message_description => 'XXMC_PO_DISTRIBUTIONS'
,p_message_text => ltrim(rtrim(v_error_message))
,p_last_update_date => sysdate
,p_procedure_name => v_module_name
,p_staging_table_name => v_stg_tablename
,p_status => 'FAILED'
,p_sub_status => 'XXMC_PROCESSING_IN_EBS'
,p_src_success_records => v_processed
,p_src_failed_records => v_failed
,p_dest_success_records => v_processed
,p_dest_failed_records => v_failed
,p_error_count => v_failed
,p_call_status => v_mycall_status
,p_error_msg => v_myerror_msg
,p_key_field_value => v_tracking_id);
RAISE_APPLICATION_ERROR (
num=> -20001,
msg=> 'Error encountered in XXMC PO DISTRIBUTIONS AUIR Trigger '
|| ' Date = ' || to_char(sysdate, 'mm/dd/yyyy hh24:mi:ss')
|| ' SQLERRM = ' || v_error_message);
END;

Similar Messages

  • Custom Trigger Issues

    I am trying to create a PM messaging system with ADDT. So far, things are going pretty well. But I have a problem with a custom trigger i am trying to write. Before a message is sent, I want the recipients private message count to be checked. If it equals 2, an error message is displayed and the message does not get sent. This is the code that I have at the moment.
    //start checkPM_Count trigger
    function checkPM_Count(&$tNG) {
    $username_pmcount = $_POST['msg_reciever'];
    $checkPMCount_SQL = "SELECT u_pmcount from members WHERE u_name='$username_pmcount'";
    $result1 = mysql_query($checkPMCount_SQL) or die($checkPMCount_SQL."
    ".mysql_error());
    $pm_count = $result1['u_pmcount'];
    if ($pm_count == '2') {
    $tNG->setError(new tNG_error('The user you are trying to send a message to has 2 private messages, sorry but we cant send your message until that user deletes some of their messages.', array(), array()));
    Can anyone tell me if there is something wrong with the code above. No error message is shown and the message is still being sent regardless.
    Thanks

    I am trying to create a PM messaging system with ADDT. So far, things are going pretty well. But I have a problem with a custom trigger i am trying to write. Before a message is sent, I want the recipients private message count to be checked. If it equals 2, an error message is displayed and the message does not get sent. This is the code that I have at the moment.
    //start checkPM_Count trigger
    function checkPM_Count(&$tNG) {
    $username_pmcount = $_POST['msg_reciever'];
    $checkPMCount_SQL = "SELECT u_pmcount from members WHERE u_name='$username_pmcount'";
    $result1 = mysql_query($checkPMCount_SQL) or die($checkPMCount_SQL."
    ".mysql_error());
    $pm_count = $result1['u_pmcount'];
    if ($pm_count == '2') {
    $tNG->setError(new tNG_error('The user you are trying to send a message to has 2 private messages, sorry but we cant send your message until that user deletes some of their messages.', array(), array()));
    Can anyone tell me if there is something wrong with the code above. No error message is shown and the message is still being sent regardless.
    Thanks

  • Use Global Temp Table to overcome Mutating Trigger issue

    Hello all. I need to delete a line in a table, and thought I would get around the mutating trigger issue by creating a GTB table. I created 2 different triggers. One is a Row level trigger, the other a Statement level trigger.
    The first trigger gathers the information I need to identify the line I want to delete. This is:
    CREATE OR REPLACE TRIGGER Requisition_Capture
    AFTER UPDATE OF Delivery_Code on Supply_Items
    FOR EACH ROW
    BEGIN
      IF :NEW.Delivery_Code = '#' THEN
        INSERT INTO Requisition_Storage
          (Req_Code)
        VALUES
          (:NEW.Requisition_Code);
      END IF;
    END;And the second trigger deletes the line:
    CREATE OR REPLACE TRIGGER SUPPLY_ITEM_RESET
    AFTER INSERT ON Requisition_Storage
    DECLARE
    BEGIN
      DELETE FROM Supply_Items r
       WHERE r.Requisition_Code =
             (SELECT t.Req_Code
                FROM Requisition_Storage t, Supply_Items s
               WHERE t.Req_Code = s.Requisition_Code)
         AND r.Order_Qty = 0;
    END;The GTB is as follows stores the information I need to delete the line.:
    -- Create table
    create global temporary table REQUISITION_STORAGE
      req_code VARCHAR2(20)
    on commit delete rows;When the column Delivery_Code is updated in the Supply_Item table, and the value is reset to '#', I want to capture the Requisition_Code in the GTB, so I can run the statement level trigger and delete the reset row. However, I still have a mutating error problem. What am I missing?

    The statement level trigger would need to be an AFTER UPDATE OF Supply_Items for this to work around the mutating trigger issue. You need to ensure that your UPDATE has finished updating all the rows that it is going to update before your statement-level trigger runs.
    As has been pointed out, however, the desire to work around a mutating trigger error almost always indicates that you have a data model problem. And you're almost always better served by fixing the data model than working around the error.
    Justin

  • Can we update oracle standard table Attributes column by custom trigger?

    Can we update the oracle Standard table's Attributes column using custom trigger? Is it allowed by oracle? Is this supported?
    Thanks

    ATTRIBUTE columns store DFF information and therefore custom code can be used to update their contents. Care must be taken that such updates do not cause "logical" corruption (an ATTRIBUTE column may be designed to store the color of a product, for example, but an incorrect SQL statement can update the value to a numeric one, thus causing corruption - Oracle does not have a means to check the validity of these update statements). Also, some localizations, such as Brazil and India, reserve some ATTRIBUTE columns for their use - updating such columns is not supported. More information may be found in the Flexfields Guide for your release at http://www.oracle.com/technology/documentation/applications.html
    HTH
    Srini

  • Can anyone help with a custom trigger?

    Hi - I know this is a tough one and appreciate anyone's help!
    I'm trying to create a custom trigger that confirms 2 fields belong to the same record. If they do, proceed with insert transaction.
    I have gone through the tutorial (from the old Interakt Discussion Board tutorial at http://www.interaktonline.com/Documentation/MXKollection/075000_tutorialdiscussionboard.h tm) on how to create a custom trigger that checks to see whether a duplicate message and subject exist in the table and if so, stop the insert. I have this working fine, using my own table and fields.
    Can anyone help me to change the script here to confirm that both fields belong to the same record? Here is what I have right now:
    $query = "SELECT * FROM dan_camptrans_login_familyid_confirmid WHERE family_id = ".KT_escapeForSql($tNG->getColumnValue("family_id"),$tNG->getColumnType("family_id"))." AND confirm_id = ".KT_escapeForSql($tNG->getColumnValue("familyconfirm_id"),$tNG->getColumnType("familycon firm_id"));
    $result = $tNG->connection->Execute($query);
    if(!$result) {
    $error = new tNG_error("Could not access database!",array(),array());
    return $error;
    } else {
    if($numberOfRecords = $result->recordCount()) {
    $uniqueFailed = new tNG_error("There is already a message with the same subject and content!",array(),array());
    return $uniqueFailed;
    } else {
    return NULL;
    Any help would be SUPER appreciated!
    Dan

    Thank you very much Shane for responding.
    Right now, if I fill out the form and enter any numbers in the family_id and familyconfirm_id fields that are currently NOT in the dan_camptrans_login_familyid_confirmid table, the form submits fine. If however, both fields already exist within the same record, the error is returned.
    I guess what I am looking for is the opposite. When the form is submitted, the table dan_camptrans_login_familyid_confirmid is checked. If both field entries are not within the same record, return the error.
    Basically, I am sending out a user ID and confirmation number via mail to users. When they register they need to enter in both of these numbers and only if they match the records will the registration proceed.
    The main recordset/form that this custom trigger is attached to is one for my user registration table. This custom trigger and associated table is only to confirm the user registering has the correct information to register.
    Thanks again - I hope that I am explaining this clearly.
    Dan

  • Trigger issue

    I have a trigger sitting on a table column and supposed to be fired after inserting or updating for each row. If I insert or update the table record by record, the trigger works fine. If I issue a batch inserting, sometimes the trigger does not work properly. e.g. I insert 4 records in that table, I should see 4 records in another table, but sometimes, I just see 2 or 3 of the records in another table, the trigger was stopped by some reason. This scenario is not always appear, just some times.
    Do you have any idea what is behind the scene?
    Thanks in advance.

    Not insert the same record in another table. The code is a little bit long
    Thanks
    CREATE OR REPLACE TRIGGER int_01
    AFTER INSERT OR UPDATE
    ON history
    FOR EACH ROW
    WHEN (NEW.code = 0)
    DECLARE
    p_header_id               NUMBER;
    p_sequence_no          NUMBER;
    p_startdate               DATE;
    p_ownerid               NUMBER;
    p_employee_no          VARCHAR2(8);
    p_work_date               DATE;
    p_project_no          VARCHAR2(8);
         p_task_no               PLS_INTEGER;
    p_service_code          VARCHAR2(5);
    p_premium_code          VARCHAR2(5);
    p_premium_cost          FLOAT (13);
    p_submitted_by          VARCHAR2(8);
    p_submitted_time     DATE;
    p_approved_by          VARCHAR2(8);
    p_approver_id          NUMBER;
    p_hours_worked          NUMBER(5,2);
    p_time_id               NUMBER;
    v_cur_code VARCHAR2(1000);
    v_cur_code2               VARCHAR2(1000);
    v_cur_code3               VARCHAR2(1000);
    TYPE ref_cursor IS REF CURSOR;
    v_cur_01 ref_cursor;
    v_cur_02 ref_cursor;
    v_cur_03 ref_cursor;
         p_parent_task_code tasks.externalid%TYPE;
    v_log VARCHAR2(2048);
         v_flag PLS_INTEGER DEFAULT 0;
         v_outlinelevel tasks.outlinelevel%TYPE;
         v_l2_task_code tasks.externalid%TYPE;
    BEGIN
         BEGIN
    SELECT int_header_id.NEXTVAL INTO p_header_id FROM dual;
    INSERT INTO int_header_t01(ID,interface_table,status,TIMESTAMP,SOURCE) VALUES(p_header_id,'INT_EXP_TIME_trigger','W',SYSDATE,'eTime');
    EXCEPTION
    WHEN OTHERS THEN
         p_header_id := -1;
         v_log := v_log || ' Error Occurred when generating new header record. ' ||TRIM(SUBSTR(SQLERRM, 1, 255));
    END;
         IF (p_header_id > 0) THEN                
         p_StartDate := :NEW.startdate;
         p_OwnerId := :NEW.personid;
         p_Approver_Id := :NEW.managerid;
         BEGIN
         SELECT SUBSTR(EmployeeNo,1,8) INTO p_Approved_By FROM person WHERE PersonId = p_Approver_Id;
         EXCEPTION
         WHEN OTHERS THEN
              v_flag := v_flag + 1;
              p_approved_by := NULL;
              v_log := v_log || ' Error Occurred when getting Approver''s Info. Approver_Id('||TRIM(TO_CHAR(p_approver_id,'999999999999999'))||'-'||TRIM(SUBSTR(SQLERRM,1,255));
         END;
         BEGIN
              SELECT TO_DATE(MAX(TO_CHAR(audit_date,'YYYY-MM-DD')||' '||TRIM(audit_time)),'YYYY-MM-DD HH24:MI:SS') INTO p_submitted_time FROM approval_audits
              WHERE StartDate = p_StartDate AND PersonId = p_OwnerId AND ApprovalCode = 'Submitted' ;          
              SELECT SUBSTR(employeeno,1,8) INTO p_submitted_by FROM approval_audits aa JOIN person
              ON ( aa.personname_id = person.personid AND TO_DATE(TO_CHAR(audit_date,'YYYY-MM-DD')||' '||TRIM(audit_time),'YYYY-MM-DD HH24:MI:SS') = p_submitted_time
              AND startdate = p_startdate AND aa.personid = p_ownerid AND approvalcode = 'Submitted' );
         EXCEPTION
              WHEN OTHERS THEN
              v_flag := v_flag + 1;
              p_submitted_by := NULL;
              v_log := v_log || ' Error Occurred when getting submitter''s Info. Owner_Id('||TRIM(TO_CHAR(:NEW.personid,'999999999999999'))||')-'||TRIM(SUBSTR(SQLERRM,1,255));
         END;
         IF (p_approved_by IS NOT NULL AND p_submitted_by IS NOT NULL) THEN          -- ******
    v_cur_code := 'Select TimeId, SUBSTR(EmployeeNo,1,8), PostedDate, SUBSTR(ProjectCode,1,8), taskid
    FROM times WHERE OwnerId = :p_OwnerId AND StartDate = :p_StartDate ';
    OPEN v_cur_01 FOR v_cur_code USING p_OwnerId, p_StartDate ;
    LOOP
              v_log := NULL;
    FETCH v_cur_01 INTO p_Time_Id, p_Employee_No, p_Work_Date, p_Project_No, p_Task_No;
    EXIT WHEN v_cur_01%NOTFOUND;
              BEGIN
              SELECT outlinelevel,SUBSTR(TRIM(externalid),1,2) INTO v_outlinelevel,v_l2_task_code FROM tasks WHERE taskid = p_task_no;
              EXCEPTION          
              WHEN OTHERS THEN
                   v_outlinelevel := -1;
              END;     
              IF (v_outlinelevel > 0) THEN
              IF (v_outlinelevel = 3) THEN
              BEGIN
                   SELECT SUBSTR(TRIM(t1.externalid),1,2) INTO p_parent_task_code FROM tasks t1 JOIN tasks t2
                   ON (t1.taskid = t2.parentid AND t2.taskid=p_task_no);
              EXCEPTION
                   WHEN OTHERS THEN
                        v_flag := v_flag + 1;
                   p_parent_task_code := NULL;
                   v_log := v_log || ' Error occurred when getting Passport Work Order / Task Info. ' ||TRIM(SUBSTR(SQLERRM,1,255));
              END;
              ELSIF (v_outlinelevel = 2) THEN
                   p_parent_task_code := v_l2_task_code;
              END IF;
              END IF;
         IF ( p_parent_task_code IS NOT NULL ) THEN               
                   BEGIN
         v_cur_code2 := 'Select SUBSTR(Description,1,5), Hours From TimeTransactions Where TimeId = :p_Time_Id AND ownerid = :p_owner';
         OPEN v_cur_02 FOR v_cur_code2 USING p_Time_Id, p_ownerid;
         LOOP
              FETCH v_cur_02 INTO p_Service_Code, p_Hours_Worked;     
              EXIT WHEN v_cur_02%NOTFOUND;
              IF (p_Service_Code IS NOT NULL OR p_Service_Code <> '') THEN
              SELECT Int_Sequence_No.NEXTVAL INTO p_Sequence_No FROM Dual;
              INSERT INTO int_exp_time_trigger(Header_Id, Sequence_No, Employee_No, Work_Date, Project_No, Task_No, Service_Code, Premium_Code, Premium_Cost, Submitted_By, Submitted_Time, Approved_By, Hours_Worked, TIMESTAMP, status)
         VALUES(p_Header_Id, p_Sequence_No, p_Employee_No, p_Work_Date, p_Project_No, p_parent_task_code, p_Service_Code, '000', 0, p_Submitted_By, (p_Submitted_Time), p_Approved_By, p_Hours_Worked, CURRENT_DATE, 'R');
              wep_int_logging.saveline('trigger',1,NVL(p_header_id,0),NVL(p_sequence_no,0),' Time Report exported successfully.');
                   ELSE
                   v_flag := v_flag + 1;
                   wep_int_logging.saveline('trigger',3,NVL(p_header_id,0),0,' Time Report exported error. Service Code can not be null. (Ownerid='||p_ownerid||', Employeeno='||p_employee_no||', Work Date='||p_work_date||')');     
    END IF;          
    END LOOP;
         v_cur_code3 := 'Select SubStr(ExpenseType,1,5), ExpenseAmount From Expense Where TimeId = :p_Time_Id AND ownerid = :p_owner';
         OPEN v_cur_03 FOR v_cur_code3 USING p_Time_Id, p_ownerid;
         LOOP
              FETCH v_cur_03 INTO p_Premium_Code, p_Premium_Cost;     
              EXIT WHEN v_cur_03%NOTFOUND;
              IF (p_Premium_Code IS NOT NULL OR p_Premium_Code <> '') THEN
                   SELECT Int_Sequence_No.NEXTVAL INTO p_Sequence_No FROM Dual;
                   INSERT INTO int_exp_time_trigger(Header_Id, Sequence_No, Employee_No, Work_Date, Project_No, Task_No, Service_Code, Premium_Code, Premium_Cost, Submitted_By, Submitted_Time, Approved_By, Hours_Worked, TIMESTAMP, status)
              VALUES(p_Header_Id, p_Sequence_No, p_Employee_No, p_Work_Date, p_Project_No, p_parent_task_code, 'REG', p_Premium_Code, p_Premium_Cost, p_Submitted_By, (p_Submitted_Time), p_Approved_By, 0, CURRENT_DATE, 'R');
              wep_int_logging.saveline('trigger',1,NVL(p_header_id,0),NVL(p_sequence_no,0),' Time Report exported successfully.');
                   ELSE
                   v_flag := v_flag + 1;
                   wep_int_logging.saveline('trigger',3,NVL(p_header_id,0),NVL(p_sequence_no,0),' Time Report exported error. Premium Code can not be null.(Ownerid='||p_ownerid||', Employeeno='||p_employee_no||', Work Date='||p_work_date||')');     
              END IF;
    END LOOP;
                   EXCEPTION
                   WHEN OTHERS THEN
                        v_flag := v_flag + 1;
              wep_int_logging.saveline('trigger',3,NVL(p_header_id,0),NVL(p_sequence_no,0),' Time Report exported failed: (Ownerid='||p_ownerid||', Work Date='||p_work_date||'). Error: '||v_log||' '||SUBSTR(SQLERRM,1,255));
                   END;
              ELSE
              v_flag := v_flag + 1;
              wep_int_logging.saveline('trigger',3,NVL(p_header_id,0),0,' (Ownerid='||p_ownerid||', Work Date='||p_work_date||'). Error: '||v_log);
         END IF;     
    END LOOP;
         ELSE
         v_flag := v_flag + 1;
    wep_int_logging.saveline('trigger',3,NVL(p_header_id,0),0,' Submitted_by / Approved_by can not be null. Error: '||v_log);
         END IF;      
         ELSE
         v_flag := v_flag + 1;
    wep_int_logging.saveline('trigger',3,0,0,' Interface Header table data generated Error: '||v_log);
         END IF;     
         IF (v_flag = 0) THEN
         UPDATE int_header_t01 SET status = 'R' WHERE ID = p_header_id;
         ELSE
         UPDATE int_header_t01 SET status = 'E' WHERE ID = p_header_id;
         END IF;
         IF (v_cur_01%ISOPEN) THEN
         CLOSE v_cur_01;
         END IF;
         IF (v_cur_02%ISOPEN) THEN
         CLOSE v_cur_02;
         END IF;
         IF (v_cur_03%ISOPEN) THEN
         CLOSE v_cur_03;
         END IF;
         EXCEPTION
         WHEN OTHERS THEN
         v_log := v_log || SUBSTR(SQLERRM,1,255);
              IF (p_header_id > 0) THEN
              UPDATE int_header_t01 SET status = 'E' WHERE ID = p_header_id;
              END IF;
              wep_int_logging.saveline('trigger',4,CASE WHEN p_header_id > 0 THEN p_header_id ELSE 0 END,0,' Error: '||v_log);
              IF (v_cur_01%ISOPEN) THEN
              CLOSE v_cur_01;
              END IF;
              IF (v_cur_02%ISOPEN) THEN
              CLOSE v_cur_02;
              END IF;
              IF (v_cur_03%ISOPEN) THEN
              CLOSE v_cur_03;
              END IF;
    END;
    /

  • Delete mutiple image with custom trigger

    I am attempting to delete multiple images associated with a record being deleted. The record has a field with the default filename, then each image has a prefix ("thumb_", "callout_", "feature_") along with this filename.
    My issue is two-fold. I am attempting this with a custom trigger (on the delete record; using AFTER), but I keep getting an error message when I try to pull in the filename using tNG->getColumnValue(). The error reads:
    tNG_fields.getColumnValue:
    Column file is not part of the current transaction.
    Here is my code:
    $file = $tNG->getColumnValue('file');
    deleteFileAndThumbs($file);
    My second issue is in regards to the redirect after the triggers.
    getPrimaryKeyValue() works just fine. Thus, if I change the image names to correspond to my record's "id" #, it will pull the ID # just fine. It will make it through my code and redirect back to the listing page. However, the images will not be deleted. If I remove the redirect, the images delete, but it just sits on this page. So I assume my issue is a result of the page redirecting before al the images are deleted. Is there a way to not allow the redirect to run until my deleteImages function is completed?
    Thanks!

    Ok. How about executing a SELECT inside a Custom Trigger and accessing
    the resulting rows to use in PHP code also in the trigger?
    Example - within the Custom Trigger execute:
    $sql="SELECT * FROM table";
    How do I execute it? With the regular DW code like:
    mysql_select_db($database_conWV, $conWV);
    $sql="SELECT * FROM table";
    $result = mysql_query($sql, $conWV) or die(mysql_error());
    $row_result = mysql_fetch_assoc($result);
    $totalRows_result = mysql_num_rows($result);
    or with some ADDT code like:
    $result = $tNG->connection->execute($sql);
    If I do the "ADDT" way, how do I access the rows?
    $result['column'] or something?
    Alec
    Adobe Community Expert

  • HRMS Mutating Custom Trigger Error

    Hi Gurus! In Oracle 10.7 SC HRMS, the column PERSON_TYPE_ID in table PER_ALL_PEOPLE_F was used to populate the actual person type. In releases 11+, this column was redesigned to hold just the default user_person_type for a given system_person_type. It is not maintained to reflect the true user person type. Only the table person_type_usages_f will give you the true user_person_type. (Note: column PERSON_TYPE_ID in table PER_ALL_PEOPLE_F is ONLY used by non-HR areas, such as Purchasing)
    This link explains this:
    http://www.aboutoracleapps.com/2008/07/difference-between-perallpeoplefpersont.html
    My issue- our client upgraded from 10.7 to R12. The issue is that their custom code (a lot of it) looks at the column PERSON_TYPE_ID in table PER_ALL_PEOPLE_F to determine the actual person type.
    Since my client doesnt use Purchasing (or any other modules), and they have LOTS of custom code that looks at the PERSON_TYPE_ID column, it was decided that we would just populate that column with the correct person type.
    We created a trigger on the PER_PERSON_TYPE_USAGES_F table. Basically, any time a person type changes, the PERSON_TYPE_ID column is updated in the PER_ALL_PEOPLE_F table. Simple update.
    The problem is, we get a mutating table error. Does anyone see why? Or how my logic is not sound? Thank you.
    Trigger:
    BEFORE INSERT OR UPDATE ON "APPS"."PER_PERSON_TYPE_USAGES_F" FOR EACH ROW
    BEGIN
         UPDATE PER_ALL_PEOPLE_F
         SET PERSON_TYPE_ID = :new.person_type_id
         WHERE person_id = :NEW.person_id
         AND sysdate BETWEEN effective_start_date AND effective_end_date;
    EXCEPTION
    WHEN OTHERS THEN
    RAISE_APPLICATION_ERROR(-20005, 'Trigger UPDATE_PERSON_TYPE_ID: '||SQLERRM);
    END;
    Application Error:
    ORA-20005: Trigger UPDATE_PERSON_TYPE_ID: ORA-04091: table HR.PER_PERSON_TYPE_USAGES_F is mutating, trigger/function may not see it
    ORA-06512: at "APPS.PER_ALL_PEOPLE_F_ARIU", line 228
    ORA-04088: error during execution of trigger 'APPS.PER_ALL_PEOPLE_F_ARIU'
    ORA-04088: error during execution of trigger 'XXMIL.UPDATE_PERSON_TYPE_ID'
    ORA-06512: at "APPS.PER_PTU_SHD", line 398
    ORA-06512: at "APPS.PER_PTU_UPD", line 256
    ORA-06512: at "APPS.PER_PTU_UPD", line 338
    ORA-06512: at "APPS.PER_PTU_UPD", line 781
    ORA-06512: at "APPS.PER_PTU_UPD", line 915
    ORA-06512: at "APPS.HR_PER_TYPE_USAGE_INTERNAL", line 357
    ORA-06512: at "APPS.HR_PER_TYPE_USAGE_INTERNAL", line 757
    ORA-06512: at "APPS.HR_PER_PEOPLE12_PKG", line 1311

    Jason,
    you should push to change your custom code.
    Direct update over seeded tables is not supported by Oracle.
    per_people_f updates are allowed only through front end or API, and I doubt there is an API to update the person_Type_id.
    Furthermore it's way a bloody road to have the trigger, maintain it over upgrades and patches, have it firing at the right time (order in which they fire is not predictable), have data the consistent if you eventually upgrade to iREc o Benefits (when the person type could become ex-Employee.Applicant....).
    I believe triggers on per_people_f are not recommendable (except for auditing). You should create your custom function and substitute any person_type_id occurrence with your custom function (or use the hr_person_type_usage_info.get_user_person_type or another if suit you well).
    If you are upgrading from 10.7 to 12i, a lot of rework should be envisaged, so there should be room to create a business case to stick to oracle standard and adjust your custom code. Indeed you should check wth Oracle if what proposed is actually supported by them, this would eventually make your recomendation accepted.
    my 2c.
    Giuseppe
    Edited by: Giuseppe on 07-Jun-2012 10:27

  • Custom trigger

    Hi--
    I am inserting into 2 tables sc_tblBioInfo and sc_tblSemesterInfo. I have 2 fields 'Plantoenroll' and 'year' that are inserted into 2 different fields into sc_tblSemesterInfo. That works fine.
    I also need to insert 'Plantoenroll' and 'year' combined into 1 field called 'Plantoenroll' in sc_tblBioInfo.
    I have created a custom trigger to combine them and insert into sc_tblBioInfo:
    function Trigger_Custom(&$tNG) {
    $Plantoenroll = $tNG->getColumnValue("Plantoenroll");
    $year = $tNG->getColumnValue("year");
    $newSubject = $Plantoenroll . $year;
    $ins_sc_tblBioInfo->addColumn("Plantoenroll","STRING_TYPE","VALUE",$newSubject);
    return null;
    I am getting an error "Column Plantoenroll is not part of the current transaction." How do I make Column Plantoenroll part of the current transaction?
    Is there a better way to insert 2 fields into a table and also insert those 2 fields as 1 field into a different table?
    Thanks for any help.
    --rayne

    Rayne,
    If I understand correctly, you want to insert/update a different table than the table the ADDT form is inserting to.
    The form on your page inserts a new record into sc_tblSemesterInfo table. You also want to insert a new value based on combining two fields into one and insert or update the new value in the sc_tblBioInfo table.
    Unfortunately, you cannot use:
    $ins_sc_tblBioInfo->addColumn("Plantoenroll","STRING_TYPE","VALUE",$newSubject);
    to update a different database table than the one the form is associated with.
    The correct code would be:
    $tNG->addColumn("Plantoenroll","STRING_TYPE","VALUE",$newSubject);
    but using this in a trigger only allows you to add Columns to the trasaction database table that the form is inserting to. You cannot tell it to update a different database table like this.
    The key question is whether you need to do an Update to an existing record in sc_tblBioInfo, or are you a doing fresh an insert in the sc_tblBioInfo table?
    You need to do a custom trigger that does a database call to do an insert or update operation on the sc_tblBioInfotable table. After you combine the values into a new value, are you needing to insert a new record into the sc_tblBioInfotable table, or are you needing to update an existing record in the sc_tblBioInfotable table?
    Shane

  • Custom Trigger After Insert

    After a insert into table 1, i want to take a value from that transaction and use it in a custom trigger to instert into another datbase the 2 values. One is the primary key value of the transaction of table 1 and the other is a session variable of the logged in user. I can get the value of the session user, but i cant get the value of the transaction field.
    $updateRequestDate = "INSERT INTO request_notify (id_request, username) Values({rsrequest.id_request}, '" . $_SESSION['kt_login_user'] . "')";
    $update_result = $tNG->connection->execute($updateRequestDate);
    if(!$update_result) {
    $updateError = new tNG_error("Error setting the logged in status to N", array(), array());
    return $updateError;
    } else {
    return NULL;
    I have the custom trigger set to go after insert transaction.
    How do you get the value of a transaction field for a custom trigger?

    Gunter,
    You rock. Working example, using your knowledge.
    $updateRequestDate = "INSERT INTO test2 (idtest_note, username_note) VALUES ('". $tNG->getColumnValue("id_test") ."', '". $_SESSION['kt_login_user']."')";
    $update_result = $tNG->connection->execute($updateRequestDate);
    if(!$update_result) {
    $updateError = new tNG_error("Error setting the logged in status to N", array(), array());
    return $updateError;
    } else {
    return NULL;

  • Error while create trigger on for nested table

    I want to insert a record into a nested table.For this, I created a view for the table, which includes the nested table.It told me ORA-25015 cannot perform DML on this nested table view column.So I created a trigger for the nested table.However, it told me that ORA-25010 Invalid nested table column name in nested table clause.I think my nested table is valid, i don't konw why did it appear this kind of problem?
    My table is
    CREATE TABLE ENT
    ID NUMBER(7) NOT NULL,
    CREATE_DATE VARCHAR2(11 BYTE),
    UPDATE_DATE VARCHAR2(11 BYTE),
    DEPTS VARRAY_DEPT_SEQ
    CREATE OR REPLACE
    TYPE DEPT AS OBJECT
    ID NUMBER(8),
    ANCHOR VARCHAR2(20),
    CREATE OR REPLACE
    TYPE " VARRAY_DEPT_SEQ" as varray(930) of DEPT
    CREATE OR REPLACE VIEW ENT_NESTED_VIEW
    (ID, CREATE_DATE, UPDATE_DATE, DEPTS)
    AS
    select e.ID,cast(multiset(select r.id,r.anchor from ent z, table(z.depts) r where z.ID=e.ID )as varray_dept_seq)
    FROM ENT e
    Then when I created trigger;
    CREATE OR REPLACE TRIGGER EMP.ENT_NESTED_TRI
    INSTEAD OF INSERT
    ON NESTED TABLE DEPTS OF EMP.ENT_NESTED_VIEW
    REFERENCING NEW AS New OLD AS Old PARENT AS Parent
    FOR EACH ROW
    BEGIN
    END ;
    I met the problem: ORA-25010 Invalid nested table column name in nested table clause
    Could you please tell me the reason
    Thank you!
    My insert SQL is:
    insert into table(select depts from ent_nested_view where id=1856) values(varray_dept_seq(dept(255687,'AF58743')))
    Message was edited by:
    user589751

    Hi,TongucY
    Compared with the "Referencing Clause with Nested Tables" part of this reference -
    http://psoug.org/reference/instead_of_trigger.html, I found the answer of this
    quesion. That is "CREATE OR REPLACE TYPE " VARRAY_DEPT_SEQ" as[b] varray(930) of
    DEPT". It turns to be a varying array, not a nested table. It should be "CREATE OR
    REPLACE TYPE " VARRAY_DEPT_SEQ" as table of DEPT". That is OK. Thank you very
    much!
    While there is an another question, if I create a varying array like" CREATE OR
    REPLACE TYPE " VARRAY_DEPT_SEQ" as[b] varray(930) of DEPT " and I want to insert
    a record into the varying array, which the record has been existed.The method that
    create a view and a trigger seems not to be effective.
    For instance,
    There is a record in the table
    ID:1020
    CREATE_DATE:2005-10-20
    UPDATE_DATE:2007-2-11
    DETPS: ((10225,AMY))
    I want to ask this record to be
    ID:1020
    CREATE_DATE:2005-10-20
    UPDATE_DATE:2007-2-11
    DETPS: ((10225,AMY),(10558,TOM))
    How should I do?
    Could you please help me?
    Best regards.
    Message was edited by:
    user589751

  • Customer Include in Data Dictionary Table

    Hi
    I have added a new field in Structure PAD614 and Table HRPAD614 through a customer include CI_PAD614. The table is adjusted and structure is activated. Is there anyway that the newly added field becomes the part of a standard screen as structure PAD614 is used for a standard screen. I have to display the newly added field on the screen.
    Regards
    W Imran

    Hi Imran,
    Is this issue resolved.
    We are also facing a similar issue , and would like to incorporate the Custom field in the standard screen.
    Please let us know.
    Raj

  • Taglib problem: Cannot parse custom tag with short name table

    Hello!
    I am having problems deploying a jsp tag in web as. The same war file works fine on websphere, jboss. SAP web as seems to be complaining about the short name in the tld.
    Can any body me to any known web as issues with jsp tags?
    Thanks
    [code]
    Application error occurs during processing the request.
    Details: com.sap.engine.services.servlets_jsp.server.exceptions.WebIOException: Internal error while parsing JSP page /usr/sap/J2E/JC00/j2ee/cluster/server0/apps/sap.com/dispear/servlet_jsp/disp/root/test.jsp.
         at com.sap.engine.services.servlets_jsp.server.jsp.JSPParser.parse(JSPParser.java:85)
         at com.sap.engine.services.servlets_jsp.server.servlet.JSPServlet.getClassName(JSPServlet.java:207)
         at com.sap.engine.services.servlets_jsp.server.servlet.JSPServlet.compileAndGetClassName(JSPServlet.java:369)
         at com.sap.engine.services.servlets_jsp.server.servlet.JSPServlet.service(JSPServlet.java:164)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:385)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:263)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:340)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:318)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:821)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:239)
         at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92)
         at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:147)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:37)
         at com.sap.engine.core.cluster.impl6.session.UnorderedChannel$MessageRunner.run(UnorderedChannel.java:71)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:94)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:162)
    Caused by: com.sap.engine.services.servlets_jsp.lib.jspparser.exceptions.JspParseException: Cannot parse custom tag with short name table.
         at com.sap.engine.services.servlets_jsp.lib.jspparser.syntax.xmlsyntax.CustomJspTag.action(CustomJspTag.java:129)
         at com.sap.engine.services.servlets_jsp.lib.jspparser.syntax.ElementCollection.action(ElementCollection.java:52)
         at com.sap.engine.services.servlets_jsp.server.jsp.JSPParser.initParser(JSPParser.java:307)
         at com.sap.engine.services.servlets_jsp.server.jsp.JSPParser.parse(JSPParser.java:74)
         ... 18 more
    Caused by: com.sap.engine.services.servlets_jsp.lib.jspparser.exceptions.JspParseException: Unknown class name java.lang.Object.
         at com.sap.engine.services.servlets_jsp.lib.jspparser.taglib.TagBeginGenerator.convertString(TagBeginGenerator.java:365)
         at com.sap.engine.services.servlets_jsp.lib.jspparser.taglib.TagBeginGenerator.generateSetters(TagBeginGenerator.java:187)
         at com.sap.engine.services.servlets_jsp.lib.jspparser.taglib.TagBeginGenerator.generateServiceMethodStatements(TagBeginGenerator.java:212)
         at com.sap.engine.services.servlets_jsp.lib.jspparser.taglib.TagBeginGenerator.generate(TagBeginGenerator.java:269)
         at com.sap.engine.services.servlets_jsp.lib.jspparser.syntax.xmlsyntax.CustomJspTag.action(CustomJspTag.java:127)
         ... 21 more
    [/code]

    Hi Ray,
    I am facing similar kind of issue.
    Can you please help to resolve it?
    Thanks in advance.
    Logs are as below [Here I am using standard tag lib]::
    Caused by: com.sap.engine.services.servlets_jsp.jspparser_api.exception.JspParseException: Cannot parse custom tag with short name [out].
         at com.sap.engine.services.servlets_jsp.jspparser_api.jspparser.syntax.xmlsyntax.CustomJspTag.action(CustomJspTag.java:183)
         at com.sap.engine.services.servlets_jsp.jspparser_api.jspparser.syntax.ElementCollection.action(ElementCollection.java:59)
         at com.sap.engine.services.servlets_jsp.jspparser_api.jspparser.syntax.JspIncludeDirective.action(JspIncludeDirective.java:51)
         at com.sap.engine.services.servlets_jsp.jspparser_api.jspparser.syntax.ElementCollection.action(ElementCollection.java:59)
         at com.sap.engine.services.servlets_jsp.jspparser_api.jspparser.syntax.JspElement.customTagAction(JspElement.java:994)
         at com.sap.engine.services.servlets_jsp.jspparser_api.jspparser.syntax.JspElement.action(JspElement.java:228)
         at com.sap.engine.services.servlets_jsp.jspparser_api.jspparser.syntax.ElementCollection.action(ElementCollection.java:59)
         at com.sap.engine.services.servlets_jsp.jspparser_api.jspparser.syntax.ElementCollection.action(ElementCollection.java:69)
         at com.sap.engine.services.servlets_jsp.jspparser_api.jspparser.GenerateJavaFile.generateJavaFile(GenerateJavaFile.java:72)
         at com.sap.engine.services.servlets_jsp.server.jsp.JSPProcessor.parse(JSPProcessor.java:270)
         at com.sap.engine.services.servlets_jsp.server.jsp.JSPProcessor.generateJavaFile(JSPProcessor.java:194)
         at com.sap.engine.services.servlets_jsp.server.jsp.JSPProcessor.parse(JSPProcessor.java:126)
         at com.sap.engine.services.servlets_jsp.jspparser_api.JSPChecker.getClassName(JSPChecker.java:319)
         at com.sap.engine.services.servlets_jsp.jspparser_api.JSPChecker.compileAndGetClassName(JSPChecker.java:248)
         at com.sap.engine.services.servlets_jsp.jspparser_api.JSPChecker.getClassNameForProduction(JSPChecker.java:178)
         at com.sap.engine.services.servlets_jsp.jspparser_api.JSPChecker.processJSPRequest(JSPChecker.java:109)
         at com.sap.engine.services.servlets_jsp.jspparser_api.JspParser.generateJspClass(JspParser.java:154)
         at com.sap.engine.services.servlets_jsp.server.servlet.JSPServlet.service(JSPServlet.java:193)
         ... 47 more
    Caused by: com.sap.engine.services.servlets_jsp.jspparser_api.exception.JspParseException: Attribute [value] of [<c:out>] can accept only static values.
         at com.sap.engine.services.servlets_jsp.jspparser_api.jspparser.taglib.TagBeginGenerator.calculateAttributeValue(TagBeginGenerator.java:476)
         at com.sap.engine.services.servlets_jsp.jspparser_api.jspparser.taglib.TagBeginGenerator.generateSetters(TagBeginGenerator.java:394)
         at com.sap.engine.services.servlets_jsp.jspparser_api.jspparser.taglib.TagBeginGenerator.generateServiceMethodStatements(TagBeginGenerator.java:562)
         at com.sap.engine.services.servlets_jsp.jspparser_api.jspparser.taglib.TagBeginGenerator.generate(TagBeginGenerator.java:678)
         at com.sap.engine.services.servlets_jsp.jspparser_api.jspparser.syntax.xmlsyntax.CustomJspTag.action(CustomJspTag.java:181)
         ... 64 more
    Regards,
    Sankalp

  • Primary Key Issue With Creating Tables

    Hi,
    I have the following scripts to create my two tables in oracle 10g, i was wondering wether or not i had correctly set up my primary key or if there is a better way of doing it than the way i have.
    Here are my two scripts for my tables:
    CREATE TABLE CUSTOMER (
    fname varchar2(15) NOT NULL,
    lname varchar2(20) NOT NULL,
    age varchar2(3) NOT NULL,
    custAreaCode number(5) NOT NULL,
    custNumber number(6) NOT NULL,
    constraint cust_pk PRIMARY KEY (custAreaCode),
    constraint cust_pk2 PRIMARY KEY (custNumber),
    constraint age_chk CHECK (age >=18 AND age <150)
    CREATE TABLE PHONECALL (
    startDateTime smalldatetime NOT NULL,
    custAreaCode number(5) NOT NULL, ---Reference PK From Customer Table
    custNumber number(6) NOT NULL, ---Reference PK From Customer Table
    dialledAreaCode number(5) NOT NULL,
    dialledNumber number(6) NOT NULL,
    crgPerMinute number number (3,1) NOT NULL,
    endDateTime smalldatetime NOT NULL));
    I am not sure if i have referenced the primary keys correctly in the PHONECALL table.
    Thanks in advance :)

    Hi,
    You want like this below ? I think that smalltime data type is not a valid type. Other thing, this is not a rule, but I advice you to put the primary key columns as the first columns of your table. One question: There is no PK on the phonecall table ?
    SGMS@ORACLE10> create table customer (
      2  custareacode number(5) not null,
      3  custnumber number(6) not null,
      4  fname varchar2(15) not null,
      5  lname varchar2(20) not null,
      6  age varchar2(3) not null,
      7  constraint cust_pk primary key (custareacode),
      8  constraint cust_uk unique (custnumber),
      9  constraint age_chk check (age >=18 and age <150)
    10  );
    Table created.
    SGMS@ORACLE10> create table phonecall (
      2  custareacode number(5) not null constraint fk_phone_cusarecode_customer references customer,
      3  custnumber number(6) not null constraint fk_phone_custnumber_customer references customer,
      4  startdatetime date not null,
      5  dialledareacode number(5) not null,
      6  diallednumber number(6) not null,
      7  crgperminute number (3,1) not null,
      8  enddatetime date not null);
    Table created.
    SGMS@ORACLE10> select table_name,constraint_name,constraint_type from user_constraints
    2 where table_name in ('CUSTOMER','PHONECALL') and constraint_type in ('P','U','R');
    TABLE_NAME                     CONSTRAINT_NAME                C
    CUSTOMER                       CUST_PK                        P
    CUSTOMER                       CUST_UK                        U
    PHONECALL                      FK_PHONE_CUSARECODE_CUSTOMER   R
    PHONECALL                      FK_PHONE_CUSTNUMBER_CUSTOMER   RCheers

  • Trigger and Update Flag Table

    I've recently started trying to automate around a dozen procedures. These procedures are set to run immediately after the necessary previous procedure(s) is(are) done.
    What I am attempting to accomplish is a single generic trigger that will fire off each procedure when its parent procedures have finished firing. This will be accompanied by an update_flag table with three columns
    PARENT_PRC----------------------CHILD_PRC----------------------FLAG
    parent_prc_name1--------------child_prc_name1-----------------N
    parent_prc_name1--------------child_prc_name2-----------------N
    parent_prc_name3--------------child_prc_name3-----------------Y
    Logic:
    *1.*     When a procedure fires it updates this table to set any rows in which it is the “PARENT_PRC” by updating the FLAG column to = Y.
    *2.*     The trigger will execute a child procedure if its flag (or in the case of multiple parent procedures; all of its flags) are set to 'Y'. This trigger is set to fire AFTER a table update on the UPDATE_FLAG table.
    ----a.     I have to execute the procedure UFLAG in a job because I want the trigger to execute the procedure and then continue running immediately, rather than wait for the procedure to finish then commit. This way the trigger could start several procedures all running at the same time.
    ----b.     I have made it an autonomous transaction because I needed the job to fire immediately rather than be queued, which required a commit within the trigger.
    *3.*     The last step is to set the flag in UPDATE_FLAGS back to 'N' for CHILD_PRC = '||uflag||' once the child procedure is complete.
    ----a.     I have tried placing the update child_prc = 'N' in the trigger but it won’t allow a trigger that fires on update to update the same table.
    ----b.     I want to avoid putting the update statement in all of my procedures because I would like the option of running these procedures manually for testing purposes WITHOUT effecting the update_flags table.
    Number 3. is the key problem I have been having. Placing code within the trigger to update the update_flags table setting 'Y's back to 'N's once the procedures have fired causes a deadlock error.
    I believe this is simply because the trigger is attempting to update a table which (upon updating) causes the same trigger to fire before it has finish executing.
    How can I update the Flag table to reset the update flags back to 'N'?
    Is there a different way of doing this all together?
    Here is some code with dummy procedures that demonstrates what I have so far.
    With this code, executing parent procedures should set the update_flag table to 'Y' for FLAG where procedure = 'parent_prc'.
    I need to find a way to execute the child procedures AND set the FLAG column back to 'N' from the trigger.
    ex. executing parent_1 should set update_flags.flag = 'Y' where parent_prc = 'parent_1' and thus execute procedure CHILD_A and CHILD_B.
    create table update_flags (parent_prc varchar2(10), child_prc varchar2(10), flag varchar2(1));
    insert into update_flags values('parent_1', 'child_a', 'N');
    insert into update_flags values('parent_1', 'child_b', 'N');
    insert into update_flags values('parent_2', 'child_c', 'N');
    insert into update_flags values('parent_3', 'child_c', 'N');
    insert into update_flags values('parent_4', 'child_d', 'N');
    CREATE OR REPLACE procedure parent_1 as
    BEGIN
    update update_flags set flag = 'Y' where parent_prc = 'parent_1';
    END parent_1;
    CREATE OR REPLACE procedure parent_2 as
    BEGIN
    update update_flags set flag = 'Y' where parent_prc = 'parent_2';
    END parent_2;
    CREATE OR REPLACE procedure parent_3 as
    BEGIN
    update update_flags set flag = 'Y' where parent_prc = 'parent_3';
    END parent_3;
    CREATE OR REPLACE procedure parent_4 as
    BEGIN
    update update_flags set flag = 'Y' where parent_prc = 'parent_4';
    END parent_4;
    CREATE OR REPLACE procedure child_a as
    BEGIN
    dbms_output.PUT_LINE('CHILD_A Worked');
    commit;
    END child_a;
    CREATE OR REPLACE procedure child_b as
    BEGIN
    dbms_output.PUT_LINE('CHILD_B Worked');
    commit;
    END child_b;
    CREATE OR REPLACE procedure child_c as
    BEGIN
    dbms_output.PUT_LINE('CHILD_C Worked');
    commit;
    END child_c;
    CREATE OR REPLACE procedure child_d as
    BEGIN
    dbms_output.PUT_LINE('CHILD_D Worked');
    commit;
    END child_d;
    CREATE OR REPLACE TRIGGER MASTER_TRG
    AFTER UPDATE
    ON UPDATE_FLAGS
    DECLARE
    Pragma  AUTONOMOUS_TRANSACTION;
    BEGIN
      DECLARE
      job_num number;
      uflag varchar2(1000);
      BEGIN
            select  MAX(case when COUNT(case when flag='Y' then 1 end)=COUNT(*) then CHILD_PRC else '  ' end)
            into uflag
            from        update_flags
            group by    child_prc;
            IF   uflag <> '  ' THEN
                                      --update update_flags set  flag = 'N' where child_prc = uflag     --(line of code that causes deadlock error)
                            dbms_job.submit (job => job_num,
                            what => ' '||uflag||';'
            END IF; 
       END;            
    COMMIT;
    END MASTER_TRG;
    execute parent_2;
    execute parent_3;

    >
    I think I am getting my head around the transactional/trigger issue.
    >
    It doesn't sound like it since you are still talking 'triggers'. At any rate it is OP that needs to get their head around it.
    OP doesn't even know what the entire process needs to be but has already decided that
    1. a single generic trigger that will fire off each procedure when its parent procedures have finished firing
    2. an update_flag table with three columns: PARENT_PRC, CHILD_PRC, FLAG
    3. a procedure fires it updates this table to set any rows in which it is the “PARENT_PRC” by updating the FLAG column to = Y.
    4. a job - I have to execute the procedure UFLAG in a job
    5. I have made it an autonomous transaction because I needed the job to fire immediately rather than be queued, which required a commit within the trigger.
    6. there should be an option of running these procedures manually for testing purposes WITHOUT effecting the update_flags table.
    Fortunately OP had the wisdom to ask
    >
    Is there a different way of doing this all together?
    >
    Doesn't anyone design things anymore? Seems like everyone just wants to decide what the solution ought to be be and then try to force the problem to fit into it.
    The first stage is the DESIGN - not the implementation details or technology to use.
    The first design step is to outline, or flowchart, the PROCESS that needs to take place. Since OPs post lacks sufficient detail I will substitute my own 'guesstimations' to illustrate.
    1. there are one or more 'parent' processes
    2a. these parent processes are allowed to run in parallel as they do not interfere in any way with the processing done by other parent or child processes. (is this true?)
    2b. these parent processes ARE NOT allowed to run in parallel as they may interfere with each other.
    3. Each parent process can have one or more 'child' processes. (it appears that these aren't really children but rather processes that are 'dependent' on the parent or that must always be executed after, and each time that the parent executes.
    So here are just SOME of the things that are missing that must be known before possible alternatives can be explored
    1. Re item #2 - can the parent processes be executed in parallel? Or must they be executed serially? Will any of the parent processes be dependent on any other parent or child process?
    2. What is the relationship between a parent process and its child processes? Is the parent always executed first? What triggers the parent execution? How often is it executed?
    What if it is already executing? What if other parent processes are currently executing? What if one or more of its child processes are executing? What if the parent process fails for any reason - what action should be taken?
    Based on what was posted a set of parent and child processes might need nothing more than: execute parent, execute child1, execute child2, . . ., execute childn.
    3. What is the relationship between the child processes that belong to the same parent? Can they be executed in parallel (i.e. are they completely independent)? Or must they be executed in some particular order? What if one or more of the child processes fails for any reason - what action should be taken?
    4. Will any other user or process be executing these parent or child processes? That could interfered with the automated stream.
    5. What type of exception handling and recovery needs to be implemented in one or more steps of the processing fail for some reason?
    Typically there is often one or more control tables (OPs flag table) to control and limit the processing. But the table would have status information for every process not just the children:
    A. STATUS - DISABLED, ACTIVE, RUNNING, IDLE, ERROR
    B. START_TIME
    C. END_TIME
    D. RESULT_CODE
    The control table can be used by a parent or child process to determine if it is permitted to run. For example the first thing a procedure might do is check it's own STATUS. If it is already running it would exit or log an error or message. If that test is passed it might check the status of any dependent processes. For example it might check that its child processes are ACTIVE and ready to run; if a child was still running the parent would exit or log an error or message.
    The control process would lock the appropriate control table records (FOR UPDATE) and would set the status and other fields appropriately to prevent interference by other processes or procedures.
    Design first. Then look at the implementation options.

Maybe you are looking for