plsql classic example

MAKE_ALL_SAMPLE_BY_MONTH_WTH PROCEDURE (pMonth VARCHAR2, PCYCLE VARCHAR2) the AS
VBSCODE VARCHAR2 (10); - operating region
VMONTH VARCHAR2 (10); - execution date
VSSMONTH VARCHAR2 (6); - to your date data
VSAMPLECONDSEQ INT; - a sample of SEQ
VPROCNAME JC_M_RULE.PROCNAME% TYPE; - the rules of procedure names
VSQL VARCHAR2 (1000); - running SQL variables
VSEQ NUMBER (10); --SEQ change
vMRUN BOOLEAN; - whether through online rules
VZXRUN BOOLEAN; - special rules whether performed
VPARPROLE VARCHAR2 (2); - drawn from marketing data, default data level.
VPROBLEM JC_M_RULE_PROBLEM_JOIN.PROBLEM_TYPE% TYPE; - REGULATIONS type
VRULEID JC_M_RULE.ID% TYPE; - Rule ID
VCYCLE JC_M_RULE.RULE_CYCLE the TYPE%; - execute cycle
VJCFS JC_M_RULE.FRACTION% TYPE; - basic score
GRADEFLAG BOOLEAN; - scoring rules state execution
- query each business problem area households rules
CURSOR C iS
S.PROCNAME the SELECT,
C.SEQ,
C.BSCODE,
C.SUBJECTID,
S.FRACTION,
S.RULE_CYCLE
the FROM JC_M_SAMPLECOND C, JC_M_RULE S, P JC_M_RULE_PROBLEM_JOIN
the WHERE C.SUBJECTID = S.ID
the AND S.VALIDTAG = 'the Y' - - Enabling
the AND P.RULE_ID = S.ID
the AND P.PROBLEM_TYPE = VPROBLEM - rule user issues
the AND the LENGTH (S.PROCNAME)> 0
the AND the LENGTH (C.BSCODE) = 2
the AND C.BSCODE <> '52 is' / * units 52 reject data * /
the AND C.PARAROLE = VPARPROLE
the AND S.RULE_CALL = '01' - analysis of marketing
the ORDER BY S.PROCNAME, C.BSCODE;

the BEGIN

VPARPROLE: = '01'; - draw data from marketing the default data level.
VPROBLEM: = '1'; - problem families Rules
VMRUN: = FALSE; - not carried out online rules
VZXRUN: = FALSE;


The LENGTH pMonth the IS NULL OR the IF (pMonth) <= 0 THEN
the SELECT the TO_CHAR (SYSDATE, 'YYYYMM') the INTO VSSMONTH the FROM the DUAL;
the ELSE
VSSMONTH: = pMonth;
the END the IF;

- updating the rule information each business area
APPEND_SAMPLECOND (VPROBLEM);

- Clear information was first scoring rules
; dELETE FROM JC_M_PF_WTH_RULE_TEMP T1 WHERE T1.DETAILTYPE = VPROBLEM

detailed data deleted disable rules - / *
DELETE_STOPRULE_DATA_WTH (); * /

- rules of the respective business area of circulation
the oPEN C;
lOOP
C the FETCH
the INTO VPROCNAME, VSAMPLECONDSEQ, VBSCODE, VRULEID, VJCFS, VCYCLE;
the EXIT the WHEN NOTFOUND% C;
the BEGIN
--PCYCLE not empty, and the parameters are not the same PCYCLE VCYCLE and, out of the current cycle (rule specifies only the running frequency)
the IF the LENGTH ! (PCYCLE)> 0 the AND PCYCLE the IS PCYCLE the NOT NULL = VCYCLE the AND THEN
the CONTINUE;
IF END;

- whether the current rule to be executed. If you do not perform return empty, if you do, return date of execution.
VMONTH: = GET_RULE_CYCLE (VRULEID, VCYCLE, pMonth);

- no date, the current rules do not perform, out of this cycle.
The LENGTH the IF (VMONTH) = 0 THEN OR VMONTH the IS NULL
the CONTINUE;
the END the IF;

- initialization sample information, modifying = FINISHTAG 'N', the CNT = 0
the IF INIT_SAMPLEDCOND (VSAMPLECONDSEQ) = FALSE THEN
the CONTINUE;
the END the IF;

the EXCEPTION
the WHEN the OTHERS THEN
LOG_ERROR (SQLCODE,
SQLERRM variables,,
'PKG_RULECALL.MAKE_ALL_SAMPLE_BY_MONTH_WTH (operating rules) error! = sample of SEQ [' ||
VSAMPLECONDSEQ || ', rule ID = [' || VRULEID || ' , company = [' ||
VBSCODE || ' ] ');
the CONTINUE;
the END;

the BEGIN

- delete the current rule data in question in the schedule
DELETE_SAMPLED_WTH the IF (VSAMPLECONDSEQ) = FALSE THEN
the CONTINUE;
the END the IF;

- Check again if the current rule to disable
the IF RULE_VALIDTAG_STATE (VRULEID) = FALSE THEN
the CONTINUE;
the END the IF;

- splicing execution code calls a stored procedure that topic
VSQL: = ' the CALL '|| || VPROCNAME' ( '' '|| || VBSCODE' '', '' '||
VMONTH ||' '', '|| the TO_CHAR (VSAMPLECONDSEQ) ||', '' '||
VPARPROLE || '' ')';

/ * - splicing stored procedure call to the corresponding topic execution code (bind variable)
VSQL: = 'the cALL' ||:. 1 || '(' '' ||: 2 || ' '', '' '||
: ||. 3' '', '|| the TO_CHAR (:. 4) ||', '' '||
: ||. 5' '') '
the EXECUTE IMMEDIATE VSQL the USING VPROCNAME, VBSCODE,VMONTH, VSAMPLECONDSEQ, VPARPROLE; * /
- log sample generation rule
LOG_SAMPLE_BEGIN (VSEQ, VBSCODE, VSAMPLECONDSEQ, VSQL);

the EXECUTE IMMEDIATE VSQL;

- to submit the sample data
a COMMIT;

the IF INSTR (the UPPER (VPROCNAME), 'PKG_YX.')> 0 THEN
vmrun: = TRUE; - performed online rules
ELSIF INSTR (UPPER (VPROCNAME), 'PKG_ZX.')> 0 THEN
VZXRUN: = TRUE; - special rules executed
the END the IF;

- filter white list
FILTER_HBMD_WTH (VSAMPLECONDSEQ, - a sample of SEQ
VRULEID, - rules ID
VMONTH, - date
VBSCODE, - operating region
VPROCNAME, - rule procedure name
VCYCLE, - classification rules (operating cycle)
VJCFS); - basic score

- filtered invalid user
DELETE_CANCELLATION_WTH (VSAMPLECONDSEQ);

- condition records modified samples and sample data has been completed flag
UPDATE_SAMPLEDCOND (VSAMPLECONDSEQ,
VBSCODE,
VRULEID,
pMonth,
VPROBLEM,
VPARPROLE);

- inserting the data threshold level
INSERT_LEVEL_DATA_WTH (VRULEID, VBSCODE);

- recording executed rule ID, for subsequent score calculation rule
the INSERT the INTO JC_M_PF_WTH_RULE_TEMP (RULE_ID, DETAILTYPE) the VALUES (VRULEID, VPROBLEM);

- log updated in real time, each recording region extraction rule number
LOG_SAMPLE_END (VSEQ, VSAMPLECONDSEQ);

the EXCEPTION
the WHEN the OTHERS THEN
LOG_SAMPLE_ERROR (VSEQ, SYSDATE, SQLERRM variables,);
the END;

the END LOOP;
the CLOSE C;

- if the rule executed, perform the following code.
THEN OR VZXRUN vmrun the IF
- The combined user problems SAMPLED SAMPLE table to the table, a user table SAMPLE record, the subject matter described problems plurality of combined.
The BEGIN
LOG_SAMPLE_BEGIN (VSEQ, NULL, NULL, 'MERGE_SAMPLE_WTH');
MERGE_SAMPLE_WTH (VSEQ);
LOG_SAMPLE_END (VSEQ, NULL);
the EXCEPTION
the WHEN the OTHERS THEN
LOG_SAMPLE_ERROR (VSEQ, SYSDATE, SQLERRM variables,);
The END;

- Calendar problems when inserted summarized historical data
the BEGIN
--LOG_SAMPLE_BEGIN (VSEQ, NULL, NULL, 'OLD_SAMPLE_WTH'); been written in the log OLD_SAMPLE_WTH
OLD_SAMPLE_WTH (VSSMONTH, vmrun, VZXRUN, VSEQ); - History Record the date is the current date
- LOG_SAMPLE_END (VSEQ, NULL);
EXCEPTION
the WHEN the OTHERS THEN
LOG_SAMPLE_ERROR (VSEQ, SYSDATE, SQLERRM);
END;

- the implementation of transaction data (updated every transaction done with the data in a report this month, purpose: making large screen and detailed statistics on the corresponding)
PKG_YDSJ.SUM_YDSJ_ALL_BY;

- score calculation rules household
GRADEFLAG: = FALSE;
the FOR GRADERULE the iN (the SELECT JC_M_PF_WTH_RULE_TEMP the DISTINCT RULE_ID the WHERE DETAILTYPE = VPROBLEM the FROM) LOOP
the IF RULE_GRADE_DEFINITE_WTH (GRADERULE.RULE_ID, VSSMONTH) = THEN TRUE
GRADEFLAG: = TRUE;
the END the IF;
the END LOOP;
DELETE FROM JC_M_PF_WTH_RULE_TEMP; - delete a rule scoring rule information

- if there are rules calculated scoring, users need to re-aggregated score.
GRADEFLAG = TRUE THEN IF
RULE_GRADE_MERGE_WTH (VSSMONTH);
END IF;

END IF;
EXCEPTION
the WHEN the OTHERS THEN
LOG_ERROR (SQLCODE,
SQLERRM,
'PKG_RULECALL.MAKE_ALL_SAMPLE_BY_MONTH_WTH (operating rules, find the problem user data (with a month)) error!');
ROLLBACK;
END;

Guess you like

Origin www.cnblogs.com/kingwei55555/p/12127880.html