Home » SQL & PL/SQL » SQL & PL/SQL » Insert, delete and update At a time (Oracle 11g, windows)
| Insert, delete and update At a time [message #644132] |
Wed, 28 October 2015 08:22  |
 |
Vijay55
Messages: 16 Registered: October 2015
|
Junior Member |
|
|
Dear All,
I want to do insertion, updation and deletion of records on a table at the same time with the help of merge query. I have formed the procedure and executed , it will do insertion and updation correctly. But i don't know how to handle the deletion suppose if the record is not available in my input(as collection).
Could any one tell me how to handle delete condition here. Thank you in advance.
Below is the my procedure and program call
procedure SP_EDIT_FN_GROUP(
PI_ARW_FN_GRP_ID IN NUMBER,
PI_FN_GRP_NAME IN VARCHAR2,
PI_FN_GRP_DESC IN VARCHAR2,
PI_ACTIVE IN VARCHAR2,
PI_RPTG_OBJ_ID IN NUMBER,
PI_FN_GRP_DETAILS IN FN_GRP_COLL,
PI_USER IN VARCHAR2,
x_return_code OUT NOCOPY NUMBER,
x_return_msg OUT NOCOPY VARCHAR2
)
IS
L_ARW_FN_GRP_ID number;
L_ARW_PGM_OBJ_ID number;
BEGIN
FOR I IN PI_FN_GRP_DETAILS.FIRST..PI_FN_GRP_DETAILS.LAST
LOOP
MERGE INTO ARW_RUN_FUNCTIONAL_GROUP A
USING (select distinct ARW_FN_GRP_ID from ARW_RUN_FUNCTIONAL_GROUP where PI_ARW_FN_GRP_ID=ARW_FN_GRP_ID) b--(SELECT ARW_FN_GRP_ID,ARW_PGM_OBJ_ID,EXECUTION_ORDER FROM ARW_RUN_FUNCTIONAL_GROUP where ARW_FN_GRP_ID=PI_ARW_FN_GRP_ID ) B
ON (A.ARW_FN_GRP_ID=b.ARW_FN_GRP_ID AND A.ARW_PGM_OBJ_ID=PI_FN_GRP_DETAILS(i).ARW_PGM_OBJ_ID)
WHEN MATCHED THEN
UPDATE SET
ARW_FN_GRP_NAME = PI_FN_GRP_NAME,
ARW_FN_GRP_DESC_TXT= PI_FN_GRP_DESC,
EXECUTION_ORDER = PI_FN_GRP_DETAILS(I).EXECUTION_ORDER,
ACTIVE = PI_ACTIVE,
MODIFIED_BY = PI_USER,
MODIFIED_ON = SYSTIMESTAMP
WHERE ARW_FN_GRP_ID= PI_ARW_FN_GRP_ID
WHEN NOT MATCHED THEN
INSERT (ARW_FN_GRP_ID,
ARW_PGM_OBJ_ID ,
PGM_COMPANY_ID,
PGM_LSH_OBJ_ID ,
PGM_LSH_OBJ_VER ,
ARW_FN_GRP_NAME ,
ARW_FN_GRP_DESC_TXT,
EXECUTION_ORDER ,
ACTIVE ,
CREATED_BY ,
CREATED_ON ,
MODIFIED_BY ,
MODIFIED_ON )
VALUES
(PI_ARW_FN_GRP_ID,
PI_FN_GRP_DETAILS(I).ARW_PGM_OBJ_ID,
PI_FN_GRP_DETAILS(I).PGM_COMPANY_ID,
PI_FN_GRP_DETAILS(I).PGM_LSH_OBJ_ID,
PI_FN_GRP_DETAILS(I).PGM_LSH_OBJ_VER,
PI_FN_GRP_NAME,
PI_FN_GRP_DESC,
PI_FN_GRP_DETAILS(I).EXECUTION_ORDER,
PI_ACTIVE,
PI_USER,
SYSTIMESTAMP,
PI_USER,
SYSTIMESTAMP);
END LOOP;
x_return_code:=0;
x_return_msg:='Functional Group '||PI_FN_GRP_NAME||' details has been modified successfully';
EXCEPTION
WHEN NO_dATA_FOUND THEN
x_return_code := 1;
x_return_msg := 'no data found from insert query.';
DBMS_OUTPUT.PUT_LINE('Return Code:= '||x_return_code||' Return Msg:='||x_return_msg);
WHEN OTHERS THEN
x_return_code := 1;
x_return_msg := 'OTHER ERROR'||SQLERRM||' '||SQLCODE;
DBMS_OUTPUT.PUT_LINE('Return Code:= '||x_return_code||' Return Msg:='||x_return_msg);
END SP_EDIT_FN_GROUP;
Program Call:
SET SERVEROUTPUT ON;
DECLARE
l_ret_code varchar2(1);
l_ret_status varchar2(4000);
BEGIN
PKG_BATCH_RUN_MACHINE.SP_EDIT_FN_GROUP
(
PI_ARW_FN_GRP_ID =>7,
PI_FN_GRP_NAME =>'FN_GROUP_3',
PI_FN_GRP_DESC =>'OUR Third FUNCTIONAL GROUP111',
PI_ACTIVE =>'Y',
PI_FN_GRP_DETAILS =>FN_GRP_COLL(fn_grp_type(7,11086,724,646744418,3)
,fn_grp_type(8,11756,724,646744318,1)
,fn_grp_type(10,11374,724,646747882,1)
,fn_grp_type(9,12045,724,646751937,2)
),
PI_RPTG_OBJ_ID => 10752,
PI_USER =>'ARW',
x_return_code =>l_ret_code,
x_return_msg =>l_ret_status
);
DBMS_OUTPUT.PUT_LINE('Return Code:= '||l_ret_code||' Return Msg:='||l_ret_status);
END;
/
SHOW ERRORS
Thank you in advance!!
|
|
|
|
|
|
|
|
|
|
| Re: Insert, delete and update At a time [message #644146 is a reply to message #644144] |
Wed, 28 October 2015 09:10  |
 |
BlackSwan
Messages: 26766 Registered: January 2009 Location: SoCal
|
Senior Member |
|
|
>When i try the same to delete the records from existing table by writing DELETE statement in when matched clause, i couldn't do.
I tried to make my car go, but I couldn't do.
Tell me how to make my car go.
Statement above 100% devoid of any actionable detail.
How can we reproduce what you report?
How do we know what correct results should be?
How will you or I know when correct answer has been posted here?
|
|
|
|
Goto Forum:
Current Time: Mon Jul 13 10:29:17 CDT 2026
|