1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
|
drop table myApprovedScoutRule purge;
create table myApprovedScoutRule(sid char(1), ruletext char(1), defaultpriority char(1), issorule char(1),isignored char(1));
insert into myApprovedScoutRule values('a','b','c','d','e');
insert into myApprovedScoutRule values('z','z','z','z','z');
commit;
CREATE OR REPLACE PROCEDURE UpdateApprovedScoutRule
(
p_SID IN myApprovedScoutRule.SID%TYPE,
p_RuleText IN myApprovedScoutRule.RuleText%TYPE,
p_DefaultPriority IN myApprovedScoutRule.DefaultPriority%TYPE,
p_IsSoRule IN myApprovedScoutRule.IsSoRule%TYPE,
p_IsIgnored IN myApprovedScoutRule.IsIgnored%TYPE
)
AS
BEGIN
MERGE INTO myApprovedScoutRule asr
USING (SELECT p_sid sid,
p_ruletext RuleText,
p_DefaultPriority DefaultPriority,
p_IsSoRule IsSoRule,
p_IsIgnored IsIgnored FROM dual) asr2
ON (asr2.SID = asr.SID)
WHEN MATCHED THEN
--UPDATE EXISTING RULE
UPDATE
SET
asr.RuleText = p_RuleText,
asr.DefaultPriority = p_DefaultPriority,
asr.IsSoRule = p_IsSoRule,
asr.IsIgnored = p_IsIgnored
WHERE asr.SID = p_SID
WHEN NOT MATCHED THEN
--INSERT NEW RULE
INSERT
(asr.SID,
asr.RuleText,
asr.DefaultPriority,
asr.IsSoRule,
asr.IsIgnored)
VALUES
(p_SID,
p_RuleText,
p_DefaultPriority,
p_IsSoRule,
p_IsIgnored
);
COMMIT;
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR (-20001,
p_SID || ':$:' ||
p_RuleText || ':$:' ||
p_DefaultPriority || ':$:' ||
p_IsSoRule || ':$:' ||
SQLERRM, TRUE) ;
END UpdateApprovedScoutRule;
/
show errors
exec updateapprovedscoutrule('a','a','a','a','a');
exec updateapprovedscoutrule('b','b','b','b','b');
select * from myApprovedScoutRule;
|