INSTEAD OF TRIGGER Issue

The following is the select statement for which I have created the view:
(SELECT person.person_id, person.employee_number worker_number,
pps.actual_termination_date, pps.date_start start_date,
ppt.system_person_type,
hr_person_type_usage_info.get_user_person_type
(TRUNC (SYSDATE),
person.person_id
) user_person_type,
person.full_name, person.last_name, person.first_name,
person.middle_names middle_initial, person.known_as preferred_name,
person.mailstop mail_stop, person.office_number roomnumber,
DECODE
('Y',
(SELECT 'Y'
FROM DUAL
WHERE EXISTS (
SELECT 'Y'
FROM per_all_assignments_f sup
WHERE sup.supervisor_id = person.person_id
AND TRUNC (SYSDATE)
BETWEEN sup.effective_start_date
AND NVL (sup.effective_end_date,
TRUNC (SYSDATE)
OR EXISTS (
SELECT 'Y'
FROM per_all_assignments_f paaf, per_jobs mgr
WHERE paaf.person_id = person.person_id
AND TRUNC (SYSDATE)
BETWEEN paaf.effective_start_date
AND NVL (paaf.effective_end_date,
TRUNC (SYSDATE)
AND paaf.job_id = mgr.job_id
AND UPPER (mgr.NAME) LIKE '%MANAGER%')), 'Y',
'N'
) manager_flag,
(SELECT supervisor.full_name
FROM per_all_people_f supervisor
WHERE supervisor.person_id = asg.supervisor_id
AND TRUNC (SYSDATE) BETWEEN supervisor.effective_start_date
AND supervisor.effective_end_date)
supervisor,
job.NAME job_name, pay.payroll_name payroll_name,
asg.ass_attribute6 cc,
(SELECT DISTINCT ffv.description
FROM fnd_flex_values_vl ffv,
fnd_flex_value_sets ffvs
WHERE ffv.flex_value_set_id = ffvs.flex_value_set_id
AND ffvs.flex_value_set_name = 'VS_GL_COMPANY_GLOBAL'
AND ffv.enabled_flag = 'Y'
AND TRUNC (SYSDATE)
BETWEEN TRUNC (NVL (ffv.start_date_active,
SYSDATE
AND TRUNC (NVL (ffv.end_date_active,
SYSDATE
AND ffv.flex_value = SUBSTR (asg.ass_attribute6, 1, 3))
company,
(SELECT DISTINCT ffv.description
FROM fnd_flex_values_vl ffv,
fnd_flex_value_sets ffvs
WHERE ffv.flex_value_set_id = ffvs.flex_value_set_id
AND ffvs.flex_value_set_name =
'VS_GL_BUSINESS_UNIT_GLOBAL'
AND ffv.enabled_flag = 'Y'
AND TRUNC (SYSDATE)
BETWEEN TRUNC (NVL (ffv.start_date_active,
SYSDATE
AND TRUNC (NVL (ffv.end_date_active,
SYSDATE
AND ffv.flex_value = SUBSTR (asg.ass_attribute6, 5, 4))
business,
(SELECT DISTINCT ffv.description
FROM fnd_flex_values_vl ffv,
fnd_flex_value_sets ffvs
WHERE ffv.flex_value_set_id = ffvs.flex_value_set_id
AND ffvs.flex_value_set_name =
'VS_GL_DEPARTMENT_GLOBAL'
AND ffv.enabled_flag = 'Y'
AND TRUNC (SYSDATE)
BETWEEN TRUNC (NVL (ffv.start_date_active,
SYSDATE
AND TRUNC (NVL (ffv.end_date_active,
SYSDATE
AND ffv.flex_value =
SUBSTR (asg.ass_attribute6, 10, 4))
department,
loc.location_code location_name,
DECODE (loc.style,
'JP', (loc.address_line_1 || ' ' || address_line_2),
'JP_GLB', (loc.address_line_1 || ' ' || address_line_2),
( loc.address_line_1
|| ' '
|| address_line_2
|| ' '
|| address_line_3
) location_address,
DECODE (loc.style,
'JP', address_line_3,
'JP_GLB', address_line_3,
town_or_city
) location_city,
loc.region_2 location_state, loc.country location_country,
loc.postal_code location_zip,
(SELECT ph.phone_number
FROM per_phones ph
WHERE ph.party_id = person.party_id
AND ph.phone_type = 'W1'
AND TRUNC (SYSDATE) BETWEEN ph.date_from
AND NVL (ph.date_to, TRUNC (SYSDATE))
AND ph.date_from =
(SELECT MAX (p.date_from)
FROM per_phones p
WHERE p.party_id = ph.party_id
AND p.phone_type = 'W1'
AND p.date_from <= TRUNC (SYSDATE))) work_number,
(SELECT ph.phone_number
FROM per_phones ph
WHERE ph.party_id = person.party_id
AND ph.phone_type = 'W2'
AND TRUNC (SYSDATE) BETWEEN ph.date_from
AND NVL (ph.date_to, TRUNC (SYSDATE))
AND ph.date_from =
(SELECT MAX (p.date_from)
FROM per_phones p
WHERE p.party_id = ph.party_id
AND p.phone_type = 'W2'
AND p.date_from <= TRUNC (SYSDATE))) voip_number,
(SELECT ph.phone_number
FROM per_phones ph
WHERE ph.party_id = person.party_id
AND ph.phone_type = 'M'
AND TRUNC (SYSDATE) BETWEEN ph.date_from
AND NVL (ph.date_to, TRUNC (SYSDATE))
AND ph.date_from =
(SELECT MAX (p.date_from)
FROM per_phones p
WHERE p.party_id = ph.party_id
AND p.phone_type = 'M'
AND p.date_from <= TRUNC (SYSDATE)))
mobile_public_number,
person.attribute5 acquisition_name,
person.attribute6 acquisition_date, ad.email,
ad.legacy_email, ad.primary_email_flag, ad.sam_account_name,
ad.guid, ad.last_oracle_update_date, ad.last_ad_update_date,
ad.opt_out_flag
FROM per_all_people_f person,
per_periods_of_service pps,
per_all_assignments_f asg,
per_person_types ppt,
per_person_type_usages_f pptu,
hr_locations loc,
per_jobs job,
pay_payrolls_f pay,
xxvs_hr_sync_ad ad
WHERE person.person_id = asg.person_id
AND ad.person_id(+) = person.person_id
AND TRUNC (SYSDATE) BETWEEN person.effective_start_date
AND person.effective_end_date
AND TRUNC (SYSDATE) BETWEEN asg.effective_start_date
AND asg.effective_end_date
AND asg.primary_flag = 'Y'
AND ( ( asg.assignment_type = 'B'
AND person.current_employee_flag IS NULL
OR ( asg.assignment_type = 'E'
AND person.current_employee_flag IS NOT NULL
AND person.person_id = pps.person_id
AND pps.date_start = (SELECT MAX (pps1.date_start)
FROM per_periods_of_service pps1
WHERE pps1.person_id = pps.person_id)
AND pps.date_start >=
NVL ((SELECT MAX (ppp1.date_start)
FROM per_periods_of_placement ppp1
WHERE ppp1.person_id = pps.person_id
AND ppp1.date_start <= TRUNC (SYSDATE)),
pps.date_start
AND person.employee_number IS NOT NULL
AND person.person_id = pptu.person_id
AND TRUNC (SYSDATE) BETWEEN pptu.effective_start_date
AND pptu.effective_end_date
AND pptu.person_type_id = ppt.person_type_id
AND ppt.active_flag = 'Y'
AND ppt.system_person_type IN
('EMP', 'EX_EMP') -- only employees and ex-employees.
AND ppt.business_group_id = person.business_group_id
AND NOT EXISTS (
SELECT 'x'
FROM per_person_type_usages_f pptu1, per_person_types ppt1
WHERE pptu1.person_id = person.person_id
AND pptu1.effective_end_date =
NVL (pps.actual_termination_date,
TO_DATE ('31-DEC-4712', 'DD-MON-YYYY')
AND pptu1.person_type_id = ppt1.person_type_id
AND ppt1.business_group_id = person.business_group_id
AND ppt1.user_person_type = 'Contract Labor')
AND asg.location_id = loc.location_id(+)
AND asg.job_id = job.job_id(+)
AND asg.payroll_id = pay.payroll_id(+)
AND TRUNC (SYSDATE) BETWEEN NVL (pay.effective_start_date(+),
TRUNC (SYSDATE))
AND NVL (pay.effective_end_date(+),
TRUNC (SYSDATE)))
UNION ALL
(SELECT person.person_id, person.npw_number worker_number,
ppp.actual_termination_date, ppp.date_start start_date,
ppt.system_person_type,
hr_person_type_usage_info.get_user_person_type
(TRUNC (SYSDATE),
person.person_id
) user_person_type,
person.full_name, person.last_name, person.first_name,
person.middle_names middle_initial, person.known_as preferred_name,
person.mailstop mail_stop, person.office_number roomnumber,
DECODE
('Y',
(SELECT 'Y'
FROM DUAL
WHERE EXISTS (
SELECT 'Y'
FROM per_all_assignments_f sup
WHERE sup.supervisor_id = person.person_id
AND TRUNC (SYSDATE)
BETWEEN sup.effective_start_date
AND NVL (sup.effective_end_date,
TRUNC (SYSDATE)
OR EXISTS (
SELECT 'Y'
FROM per_all_assignments_f paaf, per_jobs mgr
WHERE paaf.person_id = person.person_id
AND TRUNC (SYSDATE)
BETWEEN paaf.effective_start_date
AND NVL (paaf.effective_end_date,
TRUNC (SYSDATE)
AND paaf.job_id = mgr.job_id
AND UPPER (mgr.NAME) LIKE '%MANAGER%')), 'Y',
'N'
) manager_flag,
(SELECT supervisor.full_name
FROM per_all_people_f supervisor
WHERE supervisor.person_id = asg.supervisor_id
AND TRUNC (SYSDATE) BETWEEN supervisor.effective_start_date
AND supervisor.effective_end_date)
supervisor,
job.NAME job_name, pay.payroll_name payroll_name,
asg.ass_attribute6 cc,
(SELECT DISTINCT ffv.description
FROM fnd_flex_values_vl ffv,
fnd_flex_value_sets ffvs
WHERE ffv.flex_value_set_id = ffvs.flex_value_set_id
AND ffvs.flex_value_set_name = 'VS_GL_COMPANY_GLOBAL'
AND ffv.enabled_flag = 'Y'
AND TRUNC (SYSDATE)
BETWEEN TRUNC (NVL (ffv.start_date_active,
SYSDATE
AND TRUNC (NVL (ffv.end_date_active,
SYSDATE
AND ffv.flex_value = SUBSTR (asg.ass_attribute6, 1, 3))
company,
(SELECT DISTINCT ffv.description
FROM fnd_flex_values_vl ffv,
fnd_flex_value_sets ffvs
WHERE ffv.flex_value_set_id = ffvs.flex_value_set_id
AND ffvs.flex_value_set_name =
'VS_GL_BUSINESS_UNIT_GLOBAL'
AND ffv.enabled_flag = 'Y'
AND TRUNC (SYSDATE)
BETWEEN TRUNC (NVL (ffv.start_date_active,
SYSDATE
AND TRUNC (NVL (ffv.end_date_active,
SYSDATE
AND ffv.flex_value = SUBSTR (asg.ass_attribute6, 5, 4))
business,
(SELECT DISTINCT ffv.description
FROM fnd_flex_values_vl ffv,
fnd_flex_value_sets ffvs
WHERE ffv.flex_value_set_id = ffvs.flex_value_set_id
AND ffvs.flex_value_set_name =
'VS_GL_DEPARTMENT_GLOBAL'
AND ffv.enabled_flag = 'Y'
AND TRUNC (SYSDATE)
BETWEEN TRUNC (NVL (ffv.start_date_active,
SYSDATE
AND TRUNC (NVL (ffv.end_date_active,
SYSDATE
AND ffv.flex_value =
SUBSTR (asg.ass_attribute6, 10, 4))
department,
loc.location_code location_name,
DECODE (loc.style,
'JP', (loc.address_line_1 || ' ' || address_line_2),
'JP_GLB', (loc.address_line_1 || ' ' || address_line_2),
( loc.address_line_1
|| ' '
|| address_line_2
|| ' '
|| address_line_3
) location_address,
DECODE (loc.style,
'JP', address_line_3,
'JP_GLB', address_line_3,
town_or_city
) location_city,
loc.region_2 location_state, loc.country location_country,
loc.postal_code location_zip,
(SELECT ph.phone_number
FROM per_phones ph
WHERE ph.party_id = person.party_id
AND ph.phone_type = 'W1'
AND TRUNC (SYSDATE) BETWEEN ph.date_from
AND NVL (ph.date_to, TRUNC (SYSDATE))
AND ph.date_from =
(SELECT MAX (p.date_from)
FROM per_phones p
WHERE p.party_id = ph.party_id
AND p.phone_type = 'W1'
AND p.date_from <= TRUNC (SYSDATE))) work_number,
(SELECT ph.phone_number
FROM per_phones ph
WHERE ph.party_id = person.party_id
AND ph.phone_type = 'W2'
AND TRUNC (SYSDATE) BETWEEN ph.date_from
AND NVL (ph.date_to, TRUNC (SYSDATE))
AND ph.date_from =
(SELECT MAX (p.date_from)
FROM per_phones p
WHERE p.party_id = ph.party_id
AND p.phone_type = 'W2'
AND p.date_from <= TRUNC (SYSDATE))) voip_number,
(SELECT ph.phone_number
FROM per_phones ph
WHERE ph.party_id = person.party_id
AND ph.phone_type = 'M'
AND TRUNC (SYSDATE) BETWEEN ph.date_from
AND NVL (ph.date_to, TRUNC (SYSDATE))
AND ph.date_from =
(SELECT MAX (p.date_from)
FROM per_phones p
WHERE p.party_id = ph.party_id
AND p.phone_type = 'M'
AND p.date_from <= TRUNC (SYSDATE)))
mobile_public_number,
person.attribute5 acquisition_name,
person.attribute6 acquisition_date, ad.email,
ad.legacy_email, ad.primary_email_flag, ad.sam_account_name,
ad.guid, ad.last_oracle_update_date, ad.last_ad_update_date,
ad.opt_out_flag
FROM per_all_people_f person,
per_periods_of_placement ppp,
per_all_assignments_f asg,
per_person_types ppt,
per_person_type_usages_f pptu,
hr_locations loc,
per_jobs job,
pay_payrolls_f pay,
xxvs_hr_sync_ad ad
WHERE person.person_id = asg.person_id
AND ad.person_id(+) = person.person_id
AND TRUNC (SYSDATE) BETWEEN person.effective_start_date
AND person.effective_end_date
AND asg.primary_flag = 'Y'
AND asg.assignment_type = 'C'
AND asg.effective_start_date =
(SELECT MAX (asg1.effective_start_date)
FROM per_all_assignments_f asg1
WHERE asg1.person_id = asg.person_id
AND asg1.assignment_type = 'C'
AND asg1.primary_flag = 'Y')
AND person.person_id = ppp.person_id
AND ppp.date_start = (SELECT MAX (ppp1.date_start)
FROM per_periods_of_placement ppp1
WHERE ppp1.person_id = ppp.person_id)
AND ppp.date_start >=
NVL ((SELECT MAX (pps1.date_start)
FROM per_periods_of_service pps1
WHERE pps1.person_id = ppp.person_id
AND pps1.date_start <= TRUNC (SYSDATE)),
ppp.date_start
AND person.npw_number IS NOT NULL
AND person.person_id = pptu.person_id
AND TRUNC (SYSDATE) BETWEEN pptu.effective_start_date
AND pptu.effective_end_date
AND pptu.person_type_id = ppt.person_type_id
AND ppt.active_flag = 'Y'
AND ppt.system_person_type IN ('CWK', 'EX_CWK') -- only CWK and ex-CWK.
AND ppt.business_group_id = person.business_group_id
AND asg.location_id = loc.location_id(+)
AND asg.job_id = job.job_id(+)
AND asg.payroll_id = pay.payroll_id(+)
AND TRUNC (SYSDATE) BETWEEN NVL (pay.effective_start_date(+),
TRUNC (SYSDATE))
AND NVL (pay.effective_end_date(+),
TRUNC (SYSDATE)))
Update of per_all_people_f is firing the trigger while insert is not working...Please help.Is that bcz I have a outer join between per_all_people_f and xxvs_hr_sync_ad ?
Following is my trigger:
create or replace trigger XXVS_HR_SYNC_AD_T
Instead of update or insert
on xxvs_hr_ad_v
for each row
begin
--raise_application_error('updates are prohibited')
raise_application_error(-116,'error occured while inserting');
insert into temp10 values ('New Person Id'||:new.person_id);
insert into temp10 values ('Old Person Id'||:old.person_id);
insert into temp10 values ('New email'||:new.email);
insert into temp10 values ('Old email'||:old.email);
insert into temp10 values('New account'||:new.sam_account_name);
insert into temp10 values('Old account'||:old.sam_account_name);
commit;
raise_application_error(-117,'error occured while inserting');
IF (:new.person_id=:old.person_id) and
((:new.email <>:old.email) or
(:new.sam_account_name <>:old.sam_account_name)) THEN
raise_application_error(-118,'error occured while inserting');
update xxvs_hr_sync_ad
set email =:new.email,
sam_account_name=:new.sam_account_name
where person_id =:old.person_id;
if sql%rowcount = 0 then
insert into XXVS_HR_SYNC_AD
(PERSON_ID
,email
,sam_account_name)
values
(:new.person_id,:new.email,:new.sam_account_name);
END IF;
END IF;
end;
/

Statements between /* */ are used for debugging purpose.
Requirement is if there is an insert or update on per_all_people_f I need to perform insert or update in my staging table ie;xxvs_hr_sync_ad
If there is an update on per_all_people_f trigger is working fine,for insert it is not working.
create or replace trigger XXVS_HR_SYNC_AD_T
Instead of update or insert
on xxvs_hr_ad_v
for each row
begin
--raise_application_error('updates are prohibited')
raise_application_error(-116,'error occured while inserting');
insert into temp10 values ('New Person Id'||:new.person_id);
insert into temp10 values ('Old Person Id'||:old.person_id);
insert into temp10 values ('New email'||:new.email);
insert into temp10 values ('Old email'||:old.email);
insert into temp10 values('New account'||:new.sam_account_name);
insert into temp10 values('Old account'||:old.sam_account_name);
commit;
raise_application_error(-117,'error occured while inserting');
IF (:new.person_id=:old.person_id) and.........
Thanks

Similar Messages

  • Issue in Invoking an Updatable View with Instead of Trigger

    Hi,
    I am trying to insert a record using Updatable View with Instead of Trigger. When i try to save the data, i get the below error:
    java.sql.SQLException: ORA-01403: no data found
    ORA-06512: at line 1
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:457)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:405)
    at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:889)
    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:476)
    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:204)
    at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:540)
    at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:213)
    at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:1075)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1466)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3752)
    at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3887)
    at oracle.jdbc.driver.OracleCallableStatement.executeUpdate(OracleCallableStatement.java:9323)
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1508)
    at weblogic.jdbc.wrapper.PreparedStatement.executeUpdate(PreparedStatement.java:172)
    at oracle.jbo.server.OracleSQLBuilderImpl.doEntityDML(OracleSQLBuilderImpl.java:432)
    at oracle.jbo.server.EntityImpl.doDMLWithLOBs(EntityImpl.java:8566)
    Can someone help me resolve this issue?
    Also it would be great if you can share Sample codes for Invoking an updatable view with instead of trigger on Save/commit.
    Regards,
    Jeevan

    As a trigger is executed in the db and not in your app it's really hard to help as you did not give any useful information.
    Have you read this blog http://stegemanoracle.blogspot.com/2006/03/using-updatable-views-with-adf.html ?
    Timo
    Edited by: Timo Hahn on 22.09.2011 09:15
    And my friend google also found http://technology.amis.nl/blog/1447/adf-business-components-resfresh-after-insertupdate-and-instead-of-triggers

  • Issue with instead of trigger on a view

    Gurus,
    I have an issue with an instead of trigger on a view. The trigger is listed below. The insert and update seem to be working fine but the delete section is not.
    From the application, we have a screen on which we attach images. We trigger of an insert and update when we attach images. We are using hibernate as our object relational mapping tool.
    We have added some logging into the delete section but that portion of the trigger does not seem to be executing at all.
    Please advise.
    Thanks
    Hari
    CREATE OR REPLACE TRIGGER trg_vw_result_image_uid
    INSTEAD OF
    INSERT OR DELETE OR UPDATE
    ON vw_result_image
    REFERENCING NEW AS NEW OLD AS OLD
    DECLARE
    v_cnt number(38);
    v_cnt_old number(38);
    v_err_msg VARCHAR2 (250);
    BEGIN
    -- v_rslt_id number(38);
    -- v_cnt number(38);
    select count(1) into v_cnt from result_image_master
    where RSLT_IMAGE_ID = :new.RSLT_IMAGE_ID;
    --select count(1) into v_cnt from result_image_master
    -- where ACC_BLKBR_ID = :new.ACC_BLKBR_ID
    -- and upper(RSLT_IMAGE_NM) = upper(:new.RSLT_IMAGE_NM);
    select count(1) into v_cnt_old from result_image_master
    where RSLT_IMAGE_ID = :old.RSLT_IMAGE_ID;
    insert into t2( TEXT_VAL, DT1, seq1)
    values (' before v_cnt', sysdate, t6.NEXTVAL);
    --if v_cnt = 0
    --****INSERTING
    IF INSERTING
    THEN
    insert into t2( TEXT_VAL, DT1, seq1)
    values (' v_cnt is 0 and inserting into result_image_master', sysdate, t6.NEXTVAL);
    insert into t2( TEXT_VAL, DT1, seq1)
    values (' inserted bb id :'||:new.ACC_BLKBR_ID, sysdate, t6.NEXTVAL);
    insert into result_image_master (
    RSLT_IMAGE_ID
    ,RSLT_IMAGE_HBR_VER
    ,RSLT_IMAGE_TYPE_ID
    ,RSLT_IMAGE_NM
    ,RSLT_IMAGE_LABEL
    ,RSLT_IMAGE_SEQ
    ,RSLT_SHOW_ON_RPT
    ,RSLT_SLIDE_NO
    ,RSLT_CELL_NO
    ,RSLT_X_COORD
    ,RSLT_Y_COORD
    ,ACC_BLKBR_ID
    ,CREATED_BY
    ,DATE_CREATED
    ,MODIFIED_BY
    ,DATE_MODIFIED
    values (
    :new.RSLT_IMAGE_ID
    ,:new.RSLT_IMAGE_HBR_VER
    ,:new.RSLT_IMAGE_TYPE_ID
    ,:new.RSLT_IMAGE_NM
    ,:new.RSLT_IMAGE_LABEL
    ,:new.RSLT_IMAGE_SEQ
    ,:new.RSLT_SHOW_ON_RPT
    ,:new.RSLT_SLIDE_NO
    ,:new.RSLT_CELL_NO
    ,:new.RSLT_X_COORD
    ,:new.RSLT_Y_COORD
    ,:new.ACC_BLKBR_ID
    ,:new.CREATED_BY
    ,:new.DATE_CREATED
    ,:new.MODIFIED_BY
    ,:new.DATE_MODIFIED
    insert into result_image_blob (
    RSLT_IMAGE_ID
    ,rslt_image_blob
    values (
    :new.RSLT_IMAGE_ID
    ,:new.rslt_image_blob
    --****UPDATING
    ELSIF UPDATING
    -- v_cnt > 0 --
    THEN
    insert into t2( TEXT_VAL, DT1, seq1)
    values (' updating result_image_master', sysdate, t6.nextval);
    insert into t2( TEXT_VAL, DT1, seq1)
    values (' updating bb id :'||:new.ACC_BLKBR_ID, sysdate, t6.nextval);
    update result_image_master
    set RSLT_IMAGE_HBR_VER = RSLT_IMAGE_HBR_VER + 1
    ,RSLT_IMAGE_TYPE_ID = :new.RSLT_IMAGE_TYPE_ID
    ,RSLT_IMAGE_NM = :new.RSLT_IMAGE_NM
    ,RSLT_IMAGE_LABEL = :new.RSLT_IMAGE_LABEL
    ,RSLT_IMAGE_SEQ = :new.RSLT_IMAGE_SEQ
    ,RSLT_SHOW_ON_RPT = :new.RSLT_SHOW_ON_RPT
    ,RSLT_SLIDE_NO = :new.RSLT_SLIDE_NO
    ,RSLT_CELL_NO = :new.RSLT_CELL_NO
    ,RSLT_X_COORD = :new.RSLT_X_COORD
    ,RSLT_Y_COORD = :new.RSLT_Y_COORD
    ,ACC_BLKBR_ID = :new.ACC_BLKBR_ID
    ,MODIFIED_BY = :new.MODIFIED_BY
    ,DATE_MODIFIED = :new.DATE_MODIFIED
    where RSLT_IMAGE_ID = :new.RSLT_IMAGE_ID;
    update result_image_blob
    set rslt_image_blob = :new.rslt_image_blob
    where RSLT_IMAGE_ID = :new.RSLT_IMAGE_ID;
    END IF;
    IF DELETING OR v_cnt_old > 0
    THEN
    insert into t2( TEXT_VAL, DT1, seq1) values (' deleting rows ...', sysdate, t6.NEXTVAL);
    DELETE from result_image_blob where RSLT_IMAGE_ID = :old.RSLT_IMAGE_ID;
    insert into t2( TEXT_VAL, DT1, seq1) values ('deleting result_image_blob : '||:old.RSLT_IMAGE_ID , sysdate, t6.NEXTVAL);
    DELETE from result_image_master where RSLT_IMAGE_ID = :old.RSLT_IMAGE_ID;
    insert into t2( TEXT_VAL, DT1, seq1) values ('deleting result_image_master : '||:old.RSLT_IMAGE_ID , sysdate, t6.NEXTVAL);
    END IF;
    EXCEPTION
    WHEN OTHERS THEN
    v_err_msg := SQLERRM;
    insert into t2( TEXT_VAL, DT1, seq1) values (v_err_msg, sysdate, t6.nextval);
    END;
    Edited by: bhanujh on Sep 13, 2010 7:55 AM

    bhanujh wrote:
    The error msg that we are getting is
    09/08/2010 4:02:09 PM: Unable to save the results :: Could not execute JDBC batch updateSorry, we don't recognize this message as any valid Oracle error.
    :p

  • BULK INSERT into View w/ Instead Of Trigger - DML ERROR LOGGING Issue

    Oracle 10.2.0.4
    I cannot figure out why I cannot get bulk insert errors to aggregate and allow the insert to continue when bulk inserting into a view with an Instead of Trigger. Whether I use LOG ERRORS clause or I use SQL%BULK_EXCEPTIONS, the insert works until it hits the first exception and then exits.
    Here's what I'm doing:
    1. I'm bulk inserting into a view with an Instead of Trigger on it that performs the actual updating on the underlying table. This table is a child table with a foreign key constraint to a reference table containing the primary key. In the Instead of Trigger, it attempts to insert a record into the child table and I get the following exception: +5:37:55 ORA-02291: integrity constraint (FK_TEST_TABLE) violated - parent key not found+, which is expected, but the error should be logged in the table and the rest of the inserts should complete. Instead the bulk insert exits.
    2. If I change this to bulk insert into the underlying table directly, it works, all errors get put into the error logging table and the insert completes all non-exception records.
    Here's the "test" procedure I created to test my scenario:
    View: V_TEST_TABLE
    Underlying Table: TEST_TABLE
    PROCEDURE BulkTest
    IS
    TYPE remDataType IS TABLE of v_TEST_TABLE%ROWTYPE INDEX BY BINARY_INTEGER;
    varRemData remDataType;
    begin
    select /*+ DRIVING_SITE(r)*/ *
    BULK COLLECT INTO varRemData
    from TEST_TABLE@REMOTE_LINK
    where effectiveday < to_date('06/16/2012 04','mm/dd/yyyy hh24')
    and terminationday > to_date('06/14/2012 04','mm/dd/yyyy hh24');
    BEGIN
    FORALL idx IN varRemData.FIRST .. varRemData.LAST
    INSERT INTO v_TEST_TABLE VALUES varRemData(idx) LOG ERRORS INTO dbcompare.ERR$_TEST_TABLE ('INSERT') REJECT LIMIT UNLIMITED;
    EXCEPTION WHEN others THEN
    DBMS_OUTPUT.put_line('ErrorCode: '||SQLCODE);
    END;
    COMMIT;
    end;
    I've reviewed Oracle's documentation on both DML logging tools and neither has any restrictions (at least that I can see) that would prevent this from working correctly.
    Any help would be appreciated....
    Thanks,
    Steve

    Thanks, obviously this is my first post, I'm desperate to figure out why this won't work....
    This code I sent is only a test proc to try and troubleshoot the issue, the others with the debug statement is only to capture the insert failing and not aggregating the errors, that won't be in the real proc.....
    Thanks,
    Steve

  • Issue using an INSTEAD OF trigger

    Hi Guys,
    I've not posted in here before so please tell me if i'm asking too much or just not doing something right.
    I have created the following view which will compile ok:
    DROP VIEW book_cust_vu;
    CREATE VIEW book_cust_vu AS
    SELECT c.cust_id, c.name, c.tel_no, b.table_no, b.book_date, b.time, b.book_id, b.notes, b.rest_id
    FROM booking b, customer c
    WHERE c.cust_id = b.cust_id;
    I am trying to create and INSTEAD OF trigger that will not allow an update to occur that matches and existing combination of b.table_no, b.rest_id and b.book_date. I have come up with the following:
    CREATE OR REPLACE TRIGGER book_chk
    INSTEAD OF UPDATE ON book_cust_vu
    FOR EACH ROW
    DECLARE
    tableno               book_cust_vu.table_no%TYPE;
    bookdate          book_cust_vu.book_date%TYPE;
    restid               book_cust_vu.rest_id%TYPE;     
    BEGIN
    SELECT table_no, book_date, rest_id
    INTO tableno, bookdate, restid
    FROM book_cust_vu
    WHERE book_id = :new.book_id;
    DBMS_OUTPUT.PUT_LINE('rest_id = '||restid);
    DBMS_OUTPUT.PUT_LINE('table_no = '||tableno);
    DBMS_OUTPUT.PUT_LINE('book_date = '||bookdate);
    IF :new .table_no != tableno AND
    :new.book_date != bookdate AND
    :new.rest_id != restid THEN
    UPDATE booking
    SET table_no = :new.table_no,
    book_date = :new.book_date,
    time = :new.time,
    notes = :new.notes,
    rest_id = :new.rest_id,
    book_id = :new.book_id
    WHERE book_id = :new.book_id;
    ELSE
    DBMS_OUTPUT.PUT_LINE('This booking matches an existing one');
    END IF;
    END;
    The DBMS outputs confirm that the variables are being populated with values that math existing combinations of those records, but the statement:
    IF :new .table_no != tableno AND
    :new.book_date != bookdate AND
    :new.rest_id != restid THEN
    does not seem to find this combination. The last DBMS output will also print, so that seems to confirm that the above statement is working in part, as DBMS output should only appear if the first IF statement is false. So basically, it will allow duplicates of the table_no, book_date, rest_id combo.
    This is my test update line:
    UPDATE book_cust_vu SET table_no = '1', rest_id = '1', book_date = '30-OCT-05' WHERE book_id = 3;
    The combination of values for table_no, book_date, rest_id already exist for another record.
    I have run out of ideas and simply comparing :new.variable != :old.variable will also allow the update to occur.
    If anyone can spot what is wrong or anything I need to change, that would be really helpful!!!
    Thanks,
    Anton

    Hi,
    Thanks for the suggestions guys, managed to get it going with a cursor instead:
    CREATE OR REPLACE TRIGGER book_chk
    INSTEAD OF UPDATE ON book_cust_vu
    FOR EACH ROW
    DECLARE
    temp          NUMBER;
    CURSOR book_count IS
    SELECT count(*)
    INTO temp
    FROM book_cust_vu
    WHERE book_date = :new.book_date
    AND table_no = :new.table_no
    AND rest_id = :new.rest_id;
    BEGIN
    OPEN book_count;
    LOOP
    FETCH book_count INTO temp;
    EXIT WHEN book_count%NOTFOUND;
    IF(temp = 1) THEN
    RAISE_APPLICATION_ERROR(-20012,
         'This booking matches an existing one');
    ELSE
    UPDATE booking
    SET table_no = :new.table_no,
    book_date = :new.book_date,
    time = :new.time,
    notes = :new.notes,
    rest_id = :new.rest_id,
    book_id = :new.book_id
    WHERE book_id = :new.book_id;
    END IF;
    END LOOP;
    CLOSE book_count;
    END;
    Worked on the first test, but we'll see!

  • Issue with Instead of Trigger

    Hi everyone,
    I have a view v_test . Created one instead of trigger over it. When I try to insert over the view it is throwing an error like' ORA-00036: maximum number of recursive SQL levels (50) exceeded' . Please help me how to over come from this.
    Please find the below DDL Stmts;
    CREATE TABLE test (id NUMBER,
    name VARCHAR2(10 CHAR),
    sal NUMBER,
    dept_id NUMBER);
    CREATE OR REPLACE VIEW v_test
    IS
    SELECT * FROM test;
    Trigger Code:
    CREATE OR REPLACE TRIGGER TR_V_TEST
    INSTEAD OF INSERT ON V_test
    FOR EACH ROW
    BEGIN
    INSERT INTO V_test VALUES(107,'VEERA',20000,30);
    END;
    Thanks in Advance !!
    Thanks,
    Vissu....

    Vissu,
    One and main scenario of mutating table error is depicted by your code only. You have created instead of Insert Trigger on view, within which again you are trying to insert on the same view i.e. you are trying to perform DML on a view which is already under transition state.
    Actually, Oracle tries hard to do the task. No of attempts is the value specified for "session_cached_cursors" (which is 50 here), but fails finally to recognise the table/view state, so throws the exception ORA-00036.
    In your case, instead of trigger was not required. You must understand the purpose of Instead of triggers. They are used when Multiple Tables build a view, and a DML on the view required data insertion in multiple tables. In above case, only one table is involved, so instead of trigger is not required. DML on your view can insert only in TEST table.
    But in above case, handle this by avoiding the DML(Insert) on the view inside the instead of insert trigger.
    Your purpose by insert on the view is to insert into TEST table only. So inside Instead of trigger,you can directly insert into table.
    Hope it is clear now !!

  • Instead of Trigger for tabular form

    I have a tabular layout on a form that returns data from a database view. Based on user interaction I would like to update the underlying view records that are returned by a query in the form using an INSTEAD OF trigger. I have my trigger working, however I can only get it to update the first record of the tabular layout item on the form. I realize that INSTEAD OF triggers are row level triggers, but is there a way to get this trigger to fire for multiple records? I've written a simple update statement in the form that updates the view: update newborn.nb_ltfu_positive_v
    set export_dt = sysdate
    where barcode = :nb_ltfu_positive_v.barcode;
    and my INSTEAD OF trigger looks like this: if :old.export_dt <> :new.export_dt then
    update nbpat set export_dt = sysdate
    where spec = :old.spec;
    end if;
    if :old.export_dt <> :new.export_dt then
    update nbhear_audiotest set export_dt = sysdate
    where barcode = :old.barcode;
    end if;
    Do I need to do some looping in the trigger?
    Any assistance would be greatly appreciated.
    Thanks

    No you cannot do any looping in the database trigger. The database trigger will for every record which is involved in an UPDATE issued againt the view.
    The problem is your code inside the form. In general you do not issue "manual" update against a table/view in forms, but let forms do so. So, if you want to update a record in a tabular block in forms you would just assign the new value to the forms-item, such as
    :BLOCK.EXPORT_DT:=SYSDATE;in your example. This code marks the "active" reocrd in the block as "to be updated" in the next transactions, mean when the user presses "Save". If you want to update multiple records in forms, this is either done when the user navigates between different record and then does some changes in the block-fields, or if you want to do it "programmatical", by looping over the block, something like:
    FIRST_RECORD;
    LOOP
      EXIT WHEN :SYSTEM.RECORD_STATUS ='NEW';
      -- do some stuff on the current record, exampel code
      :BLOCK.EXPORT_DT:=SYSDATE;
      EXIT WHEN :SYSTEM.LAST_RECORD='TRUE';
      NEXT_RECORD;
    END LOOP;hope this helps

  • Instead of Trigger Error

    Hi ALL,
    I am trying to create INSTEAD OF trigger on the existing VIEW, but I getting error as:-
    Not found
    The requested URL /apex/wwv_flow.show was not found on this server
    I'm creating trigger as :-
    CREATE OR REPLACE TRIGGER "trigger_name"
    INSTEAD OF UPDATE ON "view_name"
    FOR EACH ROW
    BEGIN
    UPDATE query;
    UPDATE query;
    END;
    but when I'm writting only one update query rather two update queires in the above trigger, it is creating but not with two update queries.
    Also I created another INSTEAD OF trigger on the same View as:-
    CREATE OR REPLACE TRIGGER "trigger_name"
    INSTEAD OF INSERT ON "view_name"
    FOR EACH ROW
    BEGIN
    INSERT query;
    INSERT query;
    END;
    this trigger is created without any errors than why INSTEAD OF(FOR UPDATE) trigger is not creating.... can anybody help me out with this issue.....
    thxs
    regards,
    Kumar

    Hi again,
    everything is working very much fine(I mean instead of trigger with update as well as with insert) when I'm creating on apex workspace.... this is the issue with my development enviornment.... so this is the problem with development DB or something else?????
    thxs
    regards,
    Kumar

  • "instead of" trigger on a view with a condition

    I'm trying to create an instead-of trigger on a view but I want it all such that:
    1. It fires only for a certain condition.
    2. When the condition isn't met, I want the normal DML on the view to continue as it normally would.
    3. I want to avoid writing as much manual DML code as possible for long-term maintainability.
    My first attempt is like this:
    create or replace trigger PROPOSAL_PARTS_V_IRU
      instead of update on proposal_parts_v
      for each row
      WHEN :old.PART_MASTER_ID <> :new.PART_MASTER_ID
    BEGIN
      do_stuff_for_part_master_change;
    END;So when the OLD and NEW PART_MASTER_IDs have changed, I want special processing. Else, I want it to do whatever it normally does (let the view get updated and the database will manage the update of the underlying table).
    When compiling that I get "ORA-25004: WHEN clause is not allowed in INSTEAD OF triggers".
    OK I will accept that even though I want it to work.
    So my next attempt could be:
    create or replace trigger PROPOSAL_PARTS_V_IRU
      instead of update on proposal_parts_v
      for each row
    BEGIN
      IF :old.PART_MASTER_ID <> :new.PART_MASTER_ID THEN
        do_stuff_for_part_master_change;
      ELSE
        UPDATE proposal_parts -- Manually update the underlying table with manually-written DML but I hate having to do this in case the view or table columns change.
        SET...
        WHERE...
      END;So my question is...is there any syntax to do something like this?
    create or replace trigger PROPOSAL_PARTS_V_IRU
      instead of update on proposal_parts_v
      for each row
    BEGIN
      IF :old.PART_MASTER_ID <> :new.PART_MASTER_ID THEN
        do_stuff_for_part_master_change;
      ELSE
        update_row;
      END;...where "update_row" is some sort of built-in command that tells oracle to continue with the current update as if the trigger never existed.
    Back in the day I seem to remember that Oracle Forms had a trigger and syntax like this where you could intercept a DML and if under certain conditions it wasn't true, you could say "update_row" (or maybe it was "update_record?...whatever) and it meant "continue with update as if this instead-of trigger never existed".
    Is anything available like that for the DB now? I know in older versions no, but we are now on 11g...anything new come out like this?
    Otherwise I have to manually write an update statement and I'd rather not if I don't need to.
    Thanks!

    riedelme wrote:
    gti_matt wrote:
    I'm trying to create an instead-of trigger on a view but I want it all such that:
    1. It fires only for a certain condition.You can use IF Logic inside a trigger to do or not do anything. As long as it is a condition you can check you can code IF logic around it
    2. When the condition isn't met, I want the normal DML on the view to continue as it normally would.You will have to code all of your logic in the INSTEAD of trigger. The whole purpose of the INSTEAD OF trigger is to execute INSTEAD OF performing DML on the view. There is no way to go back to the "normal DML" when the INSTEAD OF trigger exists.
    You can put all of the logic you will need in the INSTEAD OF trigger and use IF conditions. Use IF logic to code both your special and "normal" processing.
    3. I want to avoid writing as much manual DML code as possible for long-term maintainability.You will have to code the operative lines somewhere. Reusable functions and/or procedures in a package?Yep using an "IF" I knew about...no problem there.
    But was just looking for a cheap and easy way to say (for the "else" condition) to revert to normal DML processing. Sounds like in a DB trigger there is no such syntax I guess.
    This is an example from Oracle Forms, I was looking for a database equivalent of this(see http://sqltech.cl/doc/dev2000/help/fbhelp18.htm):
    Built-in Subprograms for On-Event Triggers For most of the transactional On-event triggers, there is a corresponding built-in subprogram.
    On-Event Trigger
    Corresponding Built-in
    On-Delete
    DELETE_RECORD
    On-Insert
    INSERT_RECORD
    On-Update
    UPDATE_RECORD
    When you call one of these built-in subprograms from its corresponding transactional trigger, Form Builder performs the default processing that it would have done normally at that point in the transaction.
    For example, if you call the INSERT_RECORD procedure from an On-Insert trigger, Form Builder performs the default processing for inserting a record in the database during a commit operation.
    When these built-ins are issued from within their corresponding transactional triggers, they are known as do-the-right-thing built-ins. That is, they do what Form Builder would normally have done at that point if no trigger had been present. Thus, an On-Insert trigger that calls the INSERT_RECORD procedure is functionally equivalent to not having an On-Insert trigger at all. Such a trigger is explicitly telling Form Builder to do what it would have done by default anyway.Note that the author calls them the "do-the-right-thing" built-ins. That's what I was looking for but on the DB side. Sounds like Oracle didn't come up with that (yet)?

  • Storing XML using XSU, object VIEW and INSTEAD OF trigger

    Here is the point:
    I've got 2 tables which are linked:
    CREATE TABLE dept (
    deptno NUMBER PRIMARY KEY,
    deptname VARCHAR2(20)
    CREATE TABLE emp (
    empno NUMBER PRIMARY KEY,
    empname VARCHAR2(20),
    deptno NUMBER REFERENCES dept(deptno)
    I've got the following message, which I want to insert in the tables using XSU (I already have a PL/SQL stored procedure which work perfectly for insertion into 1 table, using DBMS_XMLSave.insertXML or xmlgen.insertXML):
    <DEPT>
    <DEPTNO>10</DEPTNO>
    <DEPTNAME>IT</DEPTNAME>
    <EMP>
         <EMPNO>1</EMPNO>
         <EMPNAME>John</EMPNAME>
    </EMP>
    <EMP>
         <EMPNO>1</EMPNO>
         <EMPNAME>Phil</EMPNAME>
    </EMP>
    </DEPT>
    So I've created the following object:
    CREATE TYPE emp_t AS OBJECT
    empno NUMBER,
    empname VARCHAR2(20)
    CREATE TYPE emplist_t AS TABLE OF emp_t;
    CREATE TYPE dept_t AS OBJECT
    deptno NUMBER,
    deptname VARCHAR2(20),
    emplist emplist_t
    Now I understand that I should create an object VIEW and an INSTEAD OF trigger (That's what I read many times),
    but I don't know how to structure the view and the trigger.
    Could you help? (Example of a similar context, piece of code)
    Thanks a lot
    Marion

    Hi John,
    I have exactly the same issue as you experienced back in January. I have a complex data modelling requirement which requires the need to pivot rows into columns using ROW_NUMBER() and PARTITION clauses. To hide the complexity from the middle tier, I have created a database view and appropriate INSTEAD OF triggers and mapped my EO to the view. I have overriden the lock() method on the EO implementation class (to avoid ORA-02014) and would like to try the same solution you used with the pl/sql call to lock the record.
    My question is, how did you manage the release of the lock if the transaction was not rolled back or committed by your application i.e. if the user closed the browser for instance.
    In my naivity, I would like to think that the BC4J framework would release any locks for the database session when it found the servlet session to be terminated however my concern is that the lock would persist and cause complications.
    Any assistance greatly appreciated (if you would be willing to supply your lock() method and pl/sql procedure logic I would be even more grateful!).
    Many thanks,
    Dave
    London

  • View with Instead of Trigger - ORA-01031

    I am having trouble with a form based on a view that uses an instead of trigger.
    When I attempt to update a complex view that uses instead of triggers in an APEX form, I get the following message:
    ORA-20001: Error in DML: p_rowid=21388, ... ORA-01031: insufficient privileges
    The view works correctly when updates are executed from SQL Plus.
    The view "VW" is based on several tables in the application schema "X", which is parsed by APEX, and several tables in another schema "Z". I have explicitly granted select permission on the tables in schema "Z" to schema "X", but this doesn't resolve the error.
    Any idea how to fix this problem? From reading other posts, it sounds like the only issue should be explicit grants on the tables in other schemas. I do not attempt to update the tables in schema "Z", and do not have update permissions to those tables.
    Sinerely, Justin

    Justin,
    you might try to grant the views to the FLOWS_xxxxx user, which performs the Apex processes.
    Dik Dral

  • Instead of trigger example - INSERT works but UPDATE and DELETE does not?

    Below is a demostration script of what I am trying to troubleshoot. Tests are done on 10gR2;
    conn system/system
    drop table tt purge ;
    create table tt nologging as select * from all_users ;
    alter table tt add constraint pk_tt_user_id primary key (user_id) nologging ;
    analyze table tt compute statistics for table for all indexed columns ;
    conn hr/hr
    drop database link dblink ;
    create database link dblink
    connect to system identified by system
    using 'xe.turkcell' ;
    select * from global_name@dblink ;
    drop view v_tt ;
    create view v_tt as select username, user_id, created from tt@dblink order by 2 ;
    select count(*) from v_tt ;
    COUNT(*)
    13
    drop sequence seq_pk_tt_user_id ;
    create sequence seq_pk_tt_user_id
    minvalue 1000 maxvalue 99999
    increment by 1;
    create synonym tt for tt@dblink ;
    CREATE OR REPLACE PROCEDURE prc_update_tt(old_tt v_tt%ROWTYPE, new_tt v_tt%ROWTYPE) IS
    BEGIN
    IF old_tt.user_id != new_tt.user_id THEN
    RETURN; -- primary key
    END IF;
    IF old_tt.user_id IS NOT NULL AND new_tt.user_id IS NULL THEN
    DELETE FROM tt
    WHERE user_id = nvl(old_tt.user_id,
    -99);
    RETURN;
    END IF;
    IF (old_tt.username IS NULL AND new_tt.username IS NOT NULL) OR
    (old_tt.username IS NOT NULL AND new_tt.username != old_tt.username) THEN
    UPDATE tt
    SET username = new_tt.username
    WHERE user_id = nvl(old_tt.user_id,
    -99);
    END IF;
    IF (old_tt.created IS NULL AND new_tt.created IS NOT NULL) OR
    (old_tt.created IS NOT NULL AND new_tt.created != old_tt.created) THEN
    UPDATE tt
    SET created = new_tt.created
    WHERE user_id = nvl(old_tt.user_id,
    -99);
    END IF;
    END prc_update_tt;
    CREATE OR REPLACE PROCEDURE prc_insert_tt(old_tt v_tt%ROWTYPE, new_tt v_tt%ROWTYPE) IS
    new_tt_user_id NUMBER;
    BEGIN
    SELECT seq_pk_tt_user_id.NEXTVAL INTO new_tt_user_id FROM dual;
    INSERT INTO tt
    (username, user_id, created)
    VALUES
    (new_tt.username, new_tt_user_id, new_tt.created);
    END prc_insert_tt;
    CREATE OR REPLACE PROCEDURE prc_delete_tt(old_tt v_tt%ROWTYPE, new_tt v_tt%ROWTYPE) IS
    BEGIN
    DELETE FROM tt
    WHERE user_id = nvl(old_tt.user_id,
    -99);
    END prc_delete_tt;
    CREATE OR REPLACE TRIGGER trg_iof_v_tt
    INSTEAD OF UPDATE OR INSERT OR DELETE ON v_tt
    FOR EACH ROW
    DECLARE
    new_tt v_tt%ROWTYPE;
    old_tt v_tt%ROWTYPE;
    BEGIN
    dbms_output.put_line('INSTEAD OF TRIGGER fired');
    dbms_output.put_line(':NEW.user_id ' || :NEW.user_id);
    dbms_output.put_line(':OLD.user_id ' || :OLD.user_id);
    dbms_output.put_line(':NEW.username ' || :NEW.username);
    dbms_output.put_line(':OLD.username ' || :OLD.username);
    dbms_output.put_line(':NEW.created ' || :NEW.created);
    dbms_output.put_line(':OLD.created ' || :OLD.created);
    new_tt.user_id := :NEW.user_id;
    new_tt.username := :NEW.username;
    new_tt.created := :NEW.created;
    old_tt.user_id := :OLD.user_id;
    old_tt.username := :OLD.username;
    old_tt.created := :OLD.created;
    IF inserting THEN
    prc_insert_tt(old_tt,
    new_tt);
    ELSIF updating THEN
    prc_update_tt(old_tt,
    new_tt);
    ELSIF deleting THEN
    prc_delete_tt(old_tt,
    new_tt);
    END IF;
    END trg_iof_v_tt;
    set serveroutput on
    set null ^
    insert into v_tt values ('XXX', -1, sysdate) ;
    INSTEAD OF TRIGGER fired
    :NEW.user_id -1
    :OLD.user_id
    :NEW.username XXX
    :OLD.username
    :NEW.created 30/01/2007
    :OLD.created
    1 row created.
    commit ;
    select * from v_tt where username = 'XXX' ;
    USERNAME USER_ID CREATED
    XXX 1000 31/01/2007          <- seems to be no problem with insert part but
    update v_tt set username = 'YYY' where user_id = 1000 ;
    INSTEAD OF TRIGGER fired
    :NEW.user_id
    :OLD.user_id
    :NEW.username YYY
    :OLD.username
    :NEW.created
    :OLD.created
    1 row updated.
    commit ;
    select count(*) from v_tt where username = 'YYY' ;
    COUNT(*)
    0               <- here is my first problem with update part, Oracle said "1 row updated."
    delete from v_tt where user_id = 1000 ;
    INSTEAD OF TRIGGER fired
    :NEW.user_id
    :OLD.user_id
    :NEW.username
    :OLD.username
    :NEW.created
    :OLD.created
    1 row deleted.
    commit ;
    select count(*) from v_tt ;
    COUNT(*)
    14               <- here is my second problem with delete part, Oracle said "1 row deleted."
    Any comments will be welcomed, thank you.
    Message was edited by:
    TongucY
    changed "-1" values to "1000" in the where clause of delete and update statements.
    it was a copy/paste mistake, sorry for that.

    What table do you process in your procedures ? You don't use DBLINK to
    reference remote table in your procedures.
    Seems, you have table "TT" in "HR" schema too.
    Look:
    SQL> create table tt nologging as select * from all_users where rownum <=3;
    Table created.
    SQL> select * from tt;
    USERNAME                          USER_ID CREATED
    SYS                                     0 25-APR-06
    SYSTEM                                  5 25-APR-06
    OUTLN                                  11 25-APR-06
    SQL> conn scott/tiger
    Connected.
    SQL> create database link lk65 connect to ... identified by ... using 'nc65';
    Database link created.
    SQL> select * from tt@lk65;
    USERNAME                          USER_ID CREATED
    SYS                                     0 25-APR-06
    SYSTEM                                  5 25-APR-06
    OUTLN                                  11 25-APR-06
    SQL> create view v_tt as select username, user_id, created from tt@lk65 order by 2;
    View created.
    SQL> select * from v_tt;
    USERNAME                          USER_ID CREATED
    SYS                                     0 25-APR-06
    SYSTEM                                  5 25-APR-06
    OUTLN                                  11 25-APR-06
    SQL> create sequence seq_pk_tt_user_id
      2  minvalue 1000 maxvalue 99999
      3  increment by 1;
    Sequence created.
    SQL> CREATE OR REPLACE PROCEDURE prc_insert_tt(old_tt v_tt%ROWTYPE, new_tt v_tt%ROWTYPE) IS
      2  new_tt_user_id NUMBER;
      3  BEGIN
      4  SELECT seq_pk_tt_user_id.NEXTVAL INTO new_tt_user_id FROM dual;
      5  INSERT INTO tt
      6  (username, user_id, created)
      7  VALUES
      8  (new_tt.username, new_tt_user_id, new_tt.created);
      9  END prc_insert_tt;
    10  /
    Warning: Procedure created with compilation errors.
    SQL> show error
    Errors for PROCEDURE PRC_INSERT_TT:
    LINE/COL ERROR
    5/1      PL/SQL: SQL Statement ignored
    5/13     PL/SQL: ORA-00942: table or view does not exist
    SQL> edit
    Wrote file afiedt.buf
      1  CREATE OR REPLACE PROCEDURE prc_insert_tt(old_tt v_tt%ROWTYPE, new_tt v_tt%ROWTYPE) IS
      2  new_tt_user_id NUMBER;
      3  BEGIN
      4  SELECT seq_pk_tt_user_id.NEXTVAL INTO new_tt_user_id FROM dual;
      5  INSERT INTO tt@lk65
      6  (username, user_id, created)
      7  VALUES
      8  (new_tt.username, new_tt_user_id, new_tt.created);
      9* END prc_insert_tt;
    SQL> /
    Procedure created.Rgds.

  • How can I retrieve the condition in an update or delete using instead of trigger

    I have 2 tables, on which a view is created. To distinguish the tables within the view trigger, a column "source" had been added in the view creation. I want to be able to delete row(s) in table t1 or table t2 through the view, depending on a condition. The problem is that I don't know how I can get back the delete condition IN the INSTEAD of trigger :
    CREATE TABLE t1(m NUMBER, n VARCHAR2(10), o date);
    CREATE TABLE t2(a NUMBER, b VARCHAR2(10), c date);
    -- The view is created based on the 2 tables.
    CREATE OR REPLACE VIEW vt12 AS
    SELECT 't1' source, m, n, o
    FROM t1
    UNION
    SELECT 't2' source, a, b, c
    FROM t2;
    -- The trigger will fire whenever INSERT is performed on the tables through the view
    create or replace trigger tvt12 instead of insert or delete on vt12
    begin
    if inserting then
    if :new.source = 't1' then
    insert into t1 values (:new.m, :new.n, :new.o);
    else
    -- will insert a default value of -1 for the fourth column "d"
    insert into t2(a,b,c,d) values (:new.m, :new.n, :new.o, -1);
    end if;
    elsif deleting then
    -- We don't know the condition for the deletion, so all rows from the
    -- table from which the current row is coming will be deleted
    if :old.source = 't1' then
    delete t1;
    else
    delete t2;
    end if;
    end if;
    end;
    show error
    insert into vt12 values ('t1',1,'1',sysdate);
    insert into vt12 values ('t2',2,'2',sysdate+1);
    insert into vt12 values ('t1',3,'3',sysdate+2);
    insert into vt12 values ('t2',4,'4',sysdate+3);
    insert into vt12 values ('t1',5,'5',sysdate+4);
    insert into vt12 values ('t2',6,'6',sysdate+5);
    commit;
    select * from vt12;
    select * from t1;
    select * from t2;
    delete vt12 where m = 1;
    commit;
    select * from vt12;
    select * from t1;
    select * from t2;
    When I execute this script, the delete statement seems to recognize that the condition is affecting a row in table t1, and therefore deletes all rows from the table, as specified in the delete statement of the trigger... But, what I want to do is ONLY to delete the row affected by the original condition. So my question is to know how I can get back the original condition for the delete, and still use it in the trigger, that will be executed INSTEAD of the delete statement.. I checked in the doc, and everywhere an example of INSTEAD OF trigger can be found, but it's always and only using an INSTEAD OF INSERT trigger, which doesn't need a condition.
    Can anyone help ?
    null

    I've never faced this case myself, but from the documentation it would seem that the INSTEAD OF DELETE is also a FOR EACH ROW trigger. Therefore, you don't really have to worry about the actual "where" clause of the original "delete" operation: Oracle has it all parsed for you, so you just need to redirect, in turn, each view record being deleted to the appropriate table.
    In extenso: for your
    delete vt12 where m = 1;
    => the INSTEAD OF trigger fires once for all records in vt12 where m=1, and I would guess that you trigger code should look like:
    begin
    delete from t1 where m = :old.m and n = :old.n and o = :old.o;
    delete from t2 where a = :old.m and b = :old.n and c = :old.o;
    end;
    It's a bit of overkill compared to the "where" clause of the original "delete" statement, but it should do the job...
    BTW, if by any luck you do have some primary key on tables t1 and t2 (say: columns o and c respectively), then obviously you can make the thing simpler:
    begin
    delete from t1 where o = :old.o;
    delete from t2 where c = :old.o;
    end;
    HTH - Didier

  • INSTEAD OF trigger on view to update a table. error in 4.2apex tabular rpt

    I have created a view (LANDINGS_VIEW') that I am hoping to use to add/modify data over several tables. I am using INSTEAD OF trigger to update/insert into the underlying tables. I am receiving the error:
    •ORA-01858: a non-numeric character was found where a numeric was expected ORA-06512: at "SAFIS.LANDINGS_V_IO_UPD_TRG", line 4 ORA-04088: error during execution of trigger 'SAFIS.LANDINGS_V_IO_UPD_TRG' (Row 1)I am only setting PRICE = 300.
    any thoughts? Am I setting this up propertly? thanks for your help!!
    Karen
    The LANDING_VIEW is set up as follows:
    -- Start of DDL Script for View SAFIS.LANDINGS_VIEW
    -- Generated 03-May-2013 10:25:38 from [email protected]
    CREATE OR REPLACE VIEW landings_view (
       landing_seq,
       dealer_rpt_id,
       unit_measure,
       reported_quantity,
       landed_pounds,
       dollars,
       disposition_code,
       grade_code,
       species_itis,
       market_code,
       price,
       area_fished,
       sub_area_fished,
       lease_num,
       gear_code,
       de,
       ue,
       dc,
       uc,
       local_area_code,
       fins_attached,
       explanation,
       late_report,
       modified_data,
       nature_of_sale,
       hms_area_code,
       sale_price,
       deleted )
    AS
    select l.LANDING_SEQ,
           l.DEALER_RPT_ID,
           l.UNIT_MEASURE,
           l.REPORTED_QUANTITY,
           l.LANDED_POUNDS,
           l.DOLLARS,
           l.DISPOSITION_CODE,
           l.GRADE_CODE,
           l.SPECIES_ITIS,
           l.MARKET_CODE,
           l.PRICE,
           l.AREA_FISHED,
           l.SUB_AREA_FISHED,
           l.LEASE_NUM,
           l.GEAR_CODE,
           l.DE,
           l.UE,
           l.DC,
           l.UC,
           l.LOCAL_AREA_CODE,
           a.fins_attached,
           a.explanation,
           a.late_report,
           a.modified_data,
           a.nature_of_sale,
           a.hms_area_code,
           a.sale_price,
           a.deleted
      from landings l,
           landings_hms a
      where  l.dealer_rpt_id = v('P110_DEALER_RPT_ID') and
            l.dealer_rpt_id = a.dealer_rpt_id(+) and
            l.landing_seq = a.landing_seq(+)
    -- Triggers for LANDINGS_VIEW
    CREATE OR REPLACE TRIGGER landings_v_io_upd_trg
    INSTEAD OF
      UPDATE
    ON landings_view
    REFERENCING NEW AS NEW OLD AS OLD
    DECLARE
       v_first_day   date;
       BEGIN
    update landings set landing_seq = :old.landing_seq,
                              dealer_rpt_id = :old.dealer_rpt_id,
                              unit_measure = :new.unit_measure,
                              reported_quantity = :new.reported_quantity,  
                            --  landed_pounds = :new.landed_pounds,
                              dollars = :new.dollars,
                              disposition_code= :new.disposition_code, 
                              grade_code = :new.grade_code,
                              species_itis =  :new.species_itis,
                               market_code = :new.market_code,
                              price =  :new.price,
                              area_fished = :new.area_fished,
                              sub_area_fished = :new.sub_area_fished,
                           --   lease_num = :new.lease_num,
                              gear_code = :new.gear_code,
                              de = :new.de,
                              ue = :new.ue,
                              dc = :new.ue,
                              uc = :new.uc,
                              local_area_code =  :new.local_area_code ;     
        /*  update landings_hms  set dealer_rpt_id = :old.dealer_rpt_id,
                                 landing_seq = :old.landing_seq,
                                 fins_attached = :new.fins_attached,
                                 explanation = :new.explanation,
                                 late_report = :new.late_report,
                                 modified_data = :new.modified_data,
                                 nature_of_sale = :new.nature_of_sale,
                                 hms_area_code = :new.hms_area_code,
                                 sale_price = :new.sale_price,
                                 de = sysdate,
                                 ue = :new.ue,
                                 dc = :new.dc,
                                 uc = :new.uc ;                         
    end;
    -- End of DDL Script for Trigger SAFIS.LANDINGS_KEH_V_IO_TRG
    CREATE OR REPLACE TRIGGER landings_v_io_trg
    INSTEAD OF
      INSERT
    ON landings_view
    REFERENCING NEW AS NEW OLD AS OLD
    DECLARE
       v_first_day   date;
       BEGIN
    insert into landings_keh (landing_seq,
                              dealer_rpt_id,
                              unit_measure,
                              reported_quantity,
                              landed_pounds,
                              dollars,
                              disposition_code,
                              grade_code,
                              species_itis,
                              market_code,
                              price,
                              area_fished,
                              sub_area_fished,
                              lease_num,
                              gear_code,
                              de,
                              ue,
                              dc,
                              uc,
                              local_area_code)      
       values ( landings_seq.NEXTVAL,
                :new.dealer_rpt_id,
                :new.unit_measure,
                :new.reported_quantity,
                :new.landed_pounds,
                :new.dollars,
                :new.disposition_code,
                :new.grade_code,
                :new.species_itis,
                :new.market_code,
                :new.price,
                :new.area_fished,
                :new.sub_area_fished,
                :new.lease_num,
                :new.gear_code,
                sysdate,
                :new.ue,
                :new.dc,
                :new.uc,
                :new.local_area_code)  ;
       insert into landings_hms (dealer_rpt_id,
                                 landing_seq,
                                 fins_attached,
                                 explanation,
                                 late_report,
                                 modified_data,
                                 nature_of_sale,
                                 hms_area_code,
                                 sale_price,
                                 de,
                                 ue,
                                 dc,
                                 uc,
                                 deleted)
           values (:new.dealer_rpt_id,
                   landings_seq.CURRVAL,
                   :new.fins_attached,
                   :new.explanation,
                   :new.late_report,
                   :new.modified_data,
                   :new.nature_of_sale,
                   :new.hms_area_code,
                   :new.sale_price,
                   sysdate,
                   :new.ue,
                   :new.dc,
                   :new.uc,
                   :new.deleted);
    end;
    -- End of DDL Script for Trigger SAFIS.LANDINGS_KEH_V_IO_TRG
    -- End of DDL Script for View SAFIS.LANDINGS_VIEWbtw, I have succefully run the following update in sqlplus.
    update landings set landing_seq = 8604583,
    dealer_rpt_id = 2660038,
    unit_measure = 'LB',
    reported_quantity = 3,
    -- landed_pounds = :new.landed_pounds,
    dollars = 900,
    disposition_code= '001',
    grade_code = '10',
    species_itis = '160200',
    market_code = 'UN',
    price = 30,
    area_fished = null,
    sub_area_fished =null,
    -- lease_num = :new.lease_num,
    gear_code = '050',
    de = sysdate,
    ue = 'keh',
    dc = null,
    uc = 'keh',
    local_area_code = null
    where landing_seq = 8604583; I am using apex 4.2
    Edited by: KarenH on May 3, 2013 10:29 AM
    Edited by: KarenH on May 3, 2013 10:31 AM
    Edited by: KarenH on May 3, 2013 11:04 AM
    Edited by: KarenH on May 3, 2013 4:09 PM

    could it be so simple?
    when I created the tabular form on my view, LANDINGS_VIEW, the APPLYmru was automatically generated, referencing the view name LANDINGS_VIEW. I modified that to indicate the table name (LANDINGS). I am not certain why that would work, but it seems to so far.
    this post was helpful: Re: instead of trigger on view
    I am now testing to make certain both the underlying tables can be updated, LANDINGS and LANDINGS_HMS

  • Insert order by records into a view with a instead of trigger

    Hi all,
    I have this DML query:
    INSERT INTO table_view t (a,
                              b,
                              c,
                              d,
                              e)
          SELECT   a,
                   b,
                   c,
                   d,
                   e
            FROM   table_name
        ORDER BY   dtable_view is a view with an INSTEAD OF trigger and table_name is a table with my records to be inserted.
    I need the ORDER BY clause because in my trigger i call a procedure who treat each record and insert into a table, used in the view. I need to garantee these order.
    If i put an other SELECT statement outside, like this:
    INSERT INTO table_view t (a,
                              b,
                              c,
                              d,
                              e)
          SELECT   a,
                   b,
                   c,
                   d,
                   e
            FROM   table_name
        ORDER BY   dIt works. But I can put these new SELECT because these query is created automatic by Oracle Data Integrator.
    What I'm asking you is if there any solution to this problem without changing anything in the Oracle Data Integrator. Or, in other words, if there is any simple solution other than to add a new SELECT statement.
    Thanks in advance,
    Regards.

    Sorry... copy+paste error :)
    INSERT INTO table_view t (a,
                              b,
                              c,
                              d,
                              e)
        SELECT   *
          FROM   (  SELECT   a,
                             b,
                             c,
                             d,
                             e
                      FROM   table_name
                  ORDER BY   d)I need to insert him by a D column order, because my trigger needs to validate each record and insert him. I have some restrictions. For example, my records are:
    2     1     2006     M
    1     2     2007 M
    1     3     2007     S 2007
    1     2     2007     S 2007
    2     1     2009     S
    2     1     2009     S
    I want to insert the 'M' records first and then the 'S' records because the 'S' records only makes sense in target table is exists 'M' records
    Regards,
    Filipe Almeida

Maybe you are looking for

  • Very slow internet after installing 10.5.3

    Hello all, this is the very first time I have encountered any problems with my Macbook and I am hoping I can get some help here. About a month ago I came home from college and hooked my Macbook up to the wireless router at home, everything was runnin

  • Rearrange Playlists in Mobile App

    When you press "Edit" on the Playlist section of the app, it should pop up the rearrange symbol beside the Offline Sync Button, that way I'm able to rearrange playlists how I like instead of having to do it on my PC.

  • How to use ZSLFN transaction type

    Dear Experts, We are using standard service desk functionality and we have two transaction types named SLFN & ZLFN.We have a BW & ECC system connected to our solution manager.My requirement is that the BW system should use SLFN transaction type and E

  • Identify missing files ("The file could not be opened")

    Hello, I purposely deleted photos outside of LR. The photos are still in the catalog. When I attempt to develop a photo in the catalog which I forgot was deleted outside of LR the message "The file could not be opened" appears after a short delay. Th

  • Where on my MAC are "PAGES" Templates Stored

    This question has been asked before - but there was NEVER a good answer. I created a new "Template" using PAGES. I want to find this "Template" that was supposedly stored in "My Templates" - which cannot be found using "FINDER". I need to capture a c