Here is the requested code:
VIEW: (When the UNION below is commented out, the package runs as expected)
CREATE OR REPLACE FORCE VIEW "MY_ADMIN"."V_NOTIFICATIONS" AS
SELECT N_ID,
NOTIFICATION_TYPE,
CASE WHEN NOTIFICATION_DESC = 'C' THEN 'Copy' ELSE 'Send to' END NOTIFICATION_DESC,
CASE WHEN CONTACT_TYPE = 'D' THEN 'Department' ELSE 'Contact' END CONTACT_TYPE,
A.AU_USER_ID,
A.CONTACT_NAME,
D.DEPARTMENT_ID,
D.DEPT_DESC
FROM NOTIFICATIONS AN,
(SELECT A1.AU_USER_ID,
AU.FIRST_NAME || ' ' || AU.LAST_NAME CONTACT_NAME
FROM APP_USERS_CONTACT_INFO A1,
APPLICATION_USERS AU
WHERE A1.AU_USER_ID = AU.USER_ID
/*UNION
SELECT 0,
NULL
FROM DUAL*/) A,
(SELECT DEPARTMENT_ID,
DESCRIPTION DEPT_DESC
FROM DEPARTMENTS
UNION
SELECT 0 DEPARTMENT_ID,
NULL DEPT_DESC
FROM DUAL) D
WHERE NVL(AN.AU_USER_ID,0) = A.AU_USER_ID
AND NVL(AN.D_DEPARTMENT_ID,0) = D.DEPARTMENT_ID;
PACKAGE:
CREATE OR REPLACE PACKAGE NOTIFICATIONS_PKG AS
PROCEDURE INSERT_NOTIFICATION(P_N_ROW V_NOTIFICATIONS%ROWTYPE);
END NOTIFICATIONS_PKG;
/
CREATE OR REPLACE PACKAGE BODY NOTIFICATIONS_PKG AS
PROCEDURE INSERT_NOTIFICATION(P_N_ROW V_NOTIFICATIONS%ROWTYPE) IS
L_NOTIFICATION_DESC VARCHAR2(1);
L_CONTACT_TYPE VARCHAR2(1);
BEGIN
CASE P_N_ROW.NOTIFICATION_DESC
WHEN 'Copy' THEN
L_NOTIFICATION_DESC := 'C';
ELSE
L_NOTIFICATION_DESC := 'S';
END CASE;
CASE P_N_ROW.CONTACT_TYPE
WHEN 'Department' THEN
L_CONTACT_TYPE := 'D';
ELSE
L_CONTACT_TYPE := 'C';
END CASE;
INSERT INTO NOTIFICATIONS VALUES (
P_N_ROW.N_ID,
P_N_ROW.NOTIFICATION_TYPE,
L_NOTIFICATION_DESC,
L_CONTACT_TYPE,
NVL(P_N_ROW.AU_USER_ID, 0),
NVL(P_N_ROW.DEPARTMENT_ID, 0),
APP_GLOBAL_PKG.GET_AUDIT);
END INSERT_AGREEMENT_NOTIFICATION;
END AGREEMENT_NOTIFICATIONS_PKG;
The trigger is setup just to pass information to this package to insert the row. Upon trying to run the following line of code I receive the ORA-01031 error:
INSERT INTO V_AGREEMENT_NOTIFICATIONS VALUES (5781, 'Collateral Request', 'Send to', 'Contact', 797, '797T', 0, null);