Upload
prasad-chandane
View
566
Download
5
Embed Size (px)
Citation preview
What is a stored procedure, and
how does it fit into OTM?• It is separate from OTM – it lives in the
database and works with OTM.
3
OTM DATABASE
Agents Stored Procedure
Disclaimer
• This is one organization’s experience
• It worked for us
• It has significant impact and requires database expertise
• It may not work for you – proceed at your own risk
• There may be a better way to do it
4
When to consider using a stored
procedure in an agent– Need to improve performance
– Need to simplify maintenance
– Agent has a non-trivial amount of SQL Activity (DSU’s primarily)
– Multiple DSUs occur in logical grouping(s)
– Multiple variations of an agent or group of agents
– There is limited need to communicate information with the agent
5
How to implement – Overview • Determine functionality to move to the stored
procedure
• Determine information needed by the stored procedure
• Write and test the stored procedure outside of the agent
• Create a version of the agent that uses the stored procedure
6
Identifying portions of agent to
implement in stored procedure• Multiple statements grouped by logic that
don’t have to be in an agent (DSU’s, Assign Variable, Set Ref Num)
• Restructure the agent to group DSU’s, etc. together, separate from agent-specific actions
• Stored Procedure does not return value(s) –it either works or errors
7
Implementation of the Stored
Procedure• Input Value(s) – e.g., $gid
• Use Blocking and Exceptions
• Use COMMIT for INSERT / UPDATE statements
• Conditionals
• Debug, Execution Time, and other functionality
8
Calling the stored procedure
from the agent• Use the Stored Procedure Statement Type
in Direct SQL Update
• SQL Statement to call the Stored Procedure:CALL GLOGOWNER.OSPK_SHIPMENT_CREATED.P1($GID)
• Passing values to the Stored Procedure
• No return values
9
Factors to Watch For• KISS – Don’t write a constitution when a paragraph
will do
• Execution Speed
• “Hidden” Functionality – stored procedure won’t be visible from OTM interface
• OTM agent built-in functionality is not present in the Stored Procedures
• External Processes not included in LOGs
10
Pitfalls to Avoid
• Need to manually perform OTM-provided
functionality
• Avoid Concurrency
• Follow Software Implementation Best
Practices
11
Example Stored Procedure CodeCREATE OR REPLACE PACKAGE BODY GLOGOWNER.OSPK_SHIPMENT_CREATED
AS
PROCEDURE p1(
p_gid VARCHAR2)
IS
--
v_dttm DATE := SYSDATE;
v_user VARCHAR2(50) := vpd.get_gl_user();
--
BEGIN
--
BEGIN
INSERT
INTO shipment_refnum VALUES
(
p_gid,
'OMS.EQ_GROUP',
( SELECT eg.equipment_group_name FROM shipment s, equipment_group eg
WHERE s.first_equipment_group_gid = eg.equipment_group_gid
AND s.shipment_gid = p_gid
),
'OMS', v_user, v_dttm, '', ''
);
COMMIT;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001,'EQ_GROUP : '||SUBSTR(SQLERRM,1,200));
END;
--
15
Example Stored Procedure CodeBEGIN
INSERT
INTO shipment_refnum VALUES
(
p_gid,
'OMS.ORDER_RELEASES',
(SELECT listagg(o.order_release_xid, ', ') WITHIN GROUP (
ORDER BY o.order_release_xid)
FROM order_release o,
view_shipment_order_release vsor
WHERE o.order_release_gid = vsor.order_release_gid
AND vsor.shipment_gid = p_gid
),
'OMS',
v_user,
v_dttm,
'',
''
);
COMMIT;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001,'ORDER_RELEASES : '||SUBSTR(SQLERRM,1,200));
END;
--
16
Example Stored Procedure CodeBEGIN
INSERT
INTO shipment_refnum VALUES
(
p_gid,
'OMS.ITEM_DESCRIPTION',
(SELECT NVL(
(SELECT listagg(orr.order_release_refnum_value, ', ') WITHIN GROUP (
ORDER BY orr.order_release_gid)
FROM order_release_refnum orr,
order_release o,
view_shipment_order_release vsor
WHERE o.order_release_gid = orr.order_release_gid
AND orr.order_release_refnum_qual_gid = 'OMS.ITEM_DESCRIPTION'
AND o.order_release_gid = vsor.order_release_gid
AND vsor.shipment_gid = p_gid
),'NO_DESCRIPTION')
FROM dual
),
'OMS',
v_user,
v_dttm,
'',
''
);
COMMIT;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001,'ITEM_DESCRIPTION : '||SUBSTR(SQLERRM,1,200));
END;
--
17
Example Stored Procedure CodeBEGIN
INSERT INTO shipment_remark VALUES
( p_gid, 1,
'OMS.SHIPMENT_COST_DETAIL',
( SELECT 'Total: ' || ROUND(s.total_actual_cost,2) ||' USD; ' || listagg(
ct.description || CASE sc.cost_type WHEN 'A' THEN ' ' ||sc.accessorial_code_gid
END ||': ' || ROUND(COST,2) ||' USD' ||' {'
|| NVL(scd.detail,NVL(sc.adjustment_reason_gid,' - no detail')),'}, ')
WITHIN GROUP ( ORDER BY sc.shipment_cost_seqno) ||'}'
FROM shipment s, cost_type ct, shipment_cost sc
LEFT OUTER JOIN shipment_cost_detail scd
ON sc.shipment_cost_seqno = scd.shipment_cost_seqno
WHERE sc.cost_type = ct.cost_type_gid
AND sc.shipment_gid = s.shipment_gid
AND sc.cost_type <> 'O'
AND sc.shipment_gid = p_gid
GROUP BY s.total_actual_cost
), 'OMS', v_user, v_dttm, '', '' );
COMMIT;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001,'SHIPMENT_COST_DETAIL : '||SUBSTR(SQLERRM,1,200));
END;
--
END p1;
. . .
--
END ospk_shipment_created;
18