Oracle存储过程及函数

记工作中部分存储过程及函数使用场景

  1. 根据某人身份证号和其涉案信息递归挖掘关联人员(不重复)
--------------------------------------------
-- 创建oracle字符数组类型   added by wyk 2018-07-26
--------------------------------------------
CREATE OR REPLACE TYPE VARCHAR_ARRAY IS TABLE OF VARCHAR2(40);
/
------------------------------------------------
-- 创建挖掘涉黑人员亲密度关系函数   added by wyk 2018-07-26
------------------------------------------------
CREATE OR REPLACE 
FUNCTION FUNC_DIG_SHEHEI_PERSON(SFZH_IN IN VARCHAR2) RETURN VARCHAR_ARRAY AS
SFZHARR VARCHAR_ARRAY;
BEGIN
  SFZHARR := VARCHAR_ARRAY();
  SFZHARR := FUNC_DIG_SHEHEI_PERSON_TEMP(SFZH_IN,SFZHARR);
	IF SFZHARR.COUNT > 0 THEN
		FOR I IN SFZHARR.FIRST..SFZHARR.LAST LOOP
			IF SFZHARR(I) = SFZH_IN THEN SFZHARR.DELETE(I); END IF;
		END LOOP;
	END IF;
  RETURN SFZHARR;
END FUNC_DIG_SHEHEI_PERSON;
/
----------------------------------------------------------------
-- 创建挖掘涉黑人员亲密度关系函数(主函数,用来递归挖掘)   added by wyk 2018-07-26
----------------------------------------------------------------
CREATE OR REPLACE 
FUNCTION FUNC_DIG_SHEHEI_PERSON_TEMP(SFZH_IN IN VARCHAR2,SFZHARR IN VARCHAR_ARRAY) RETURN VARCHAR_ARRAY
AS
NUM NUMBER;
INDEX_ARR NUMBER;
SFZHARR_COPY VARCHAR_ARRAY;
BEGIN
INDEX_ARR := 0;
SFZHARR_COPY := SFZHARR;
DECLARE CURSOR RELATE_SFZHS IS SELECT DISTINCT(SFZH) FROM PERSON_SAXX WHERE SAXX_JYAQ IN (SELECT SAXX_JYAQ FROM PERSON_SAXX WHERE SFZH = SFZH_IN) AND SFZH != SFZH_IN;
  RELATE_SFZH VARCHAR2(20);
  BEGIN 
				IF NOT RELATE_SFZHS%ISOPEN THEN OPEN RELATE_SFZHS;END IF;
						FETCH RELATE_SFZHS INTO RELATE_SFZH;
									WHILE RELATE_SFZHS%FOUND
											LOOP
													NUM := 0;
													IF SFZHARR_COPY.COUNT > 0 THEN
															FOR I IN SFZHARR_COPY.FIRST..SFZHARR_COPY.LAST LOOP
																IF SFZHARR_COPY(I) = RELATE_SFZH THEN
																		NUM := 1;
																END IF;
															END LOOP;
													END IF;
													IF NUM = 0 THEN
															IF SFZHARR_COPY.COUNT = 0 THEN 
																	SFZHARR_COPY.EXTEND(1);SFZHARR_COPY(1) := RELATE_SFZH;
															ELSE
																	INDEX_ARR := SFZHARR_COPY.COUNT+1;
																	SFZHARR_COPY.EXTEND(1);
																	SFZHARR_COPY(INDEX_ARR) := RELATE_SFZH;
															END IF;
															SFZHARR_COPY := FUNC_DIG_SHEHEI_PERSON_TEMP(RELATE_SFZH,SFZHARR_COPY);
													END IF;
											FETCH RELATE_SFZHS INTO RELATE_SFZH;
										END LOOP;
						CLOSE RELATE_SFZHS;
END;
	RETURN SFZHARR_COPY;
END;

  1. 根据区域经纬度范围查询范围内警情信息,并将关联信息存入关联表
----------------------------------------------------------------
-- 治安乱点区域关联警情存储过程   added by wyk 2018-09-17
----------------------------------------------------------------
CREATE OR REPLACE 
PROCEDURE PRD_PUBLIC_DISORDER_JQ(JOB_START_TIME IN DATE, JOB_END_TIME IN DATE)
AS
INSERT_SQL CLOB ;
BEGIN
	DECLARE CURSOR DISORDER_IDS IS SELECT ID FROM FKWW_PUBLIC_DISORDER;
	DISORDER_ID VARCHAR2(40);
	AREA_WKT VARCHAR2(4000);
	AREA_WKT_SUBSTR VARCHAR2(4000);
	LONGITUDE_MAX NUMBER;
	LONGITUDE_MIN NUMBER;
	LATITUDE_MAX NUMBER;
	LATITUDE_MIN NUMBER;
	START_TIME VARCHAR2(20);
	END_TIME VARCHAR2(20);
	BEGIN
			SELECT TO_CHAR(JOB_START_TIME,'yyyy-MM-dd HH24:mi:ss') INTO START_TIME FROM DUAL;
			SELECT TO_CHAR(JOB_END_TIME,'yyyy-MM-dd HH24:mi:ss') INTO END_TIME FROM DUAL;
			OPEN DISORDER_IDS;
			FETCH DISORDER_IDS INTO DISORDER_ID;
			WHILE DISORDER_IDS % FOUND
					LOOP
						SELECT AREA_WKT INTO AREA_WKT FROM FKWW_PUBLIC_DISORDER WHERE ID = DISORDER_ID;
						IF AREA_WKT IS NULL THEN 
								AREA_WKT_SUBSTR := NULL;
						ELSE
								AREA_WKT_SUBSTR := SUBSTR(AREA_WKT, 10, length(AREA_WKT)-11);
								SELECT TO_NUMBER(MAX(SUBSTR(SPLIT_CODE, 0, INSTR(SPLIT_CODE, ' ')))) INTO LONGITUDE_MAX FROM (
										SELECT REGEXP_SUBSTR (AREA_WKT_SUBSTR,'[^,]+',1,L) AS SPLIT_CODE FROM DUAL,
										(SELECT LEVEL L FROM DUAL CONNECT BY LEVEL <= LENGTH (AREA_WKT_SUBSTR) - LENGTH (REPLACE (AREA_WKT_SUBSTR,','))+1) B
										WHERE L <= LENGTH (AREA_WKT_SUBSTR));
								SELECT TO_NUMBER(MIN(SUBSTR(SPLIT_CODE, 0, INSTR(SPLIT_CODE, ' ')))) INTO LONGITUDE_MIN FROM (
										SELECT REGEXP_SUBSTR (AREA_WKT_SUBSTR,'[^,]+',1,L) AS SPLIT_CODE FROM DUAL,
										(SELECT LEVEL L FROM DUAL CONNECT BY LEVEL <= LENGTH (AREA_WKT_SUBSTR) - LENGTH (REPLACE (AREA_WKT_SUBSTR,','))+1) B
										WHERE L <= LENGTH (AREA_WKT_SUBSTR));
								SELECT TO_NUMBER(MAX(SUBSTR(SPLIT_CODE, INSTR(SPLIT_CODE, ' ')+1,LENGTH(SPLIT_CODE)))) INTO LATITUDE_MAX FROM (
										SELECT REGEXP_SUBSTR (AREA_WKT_SUBSTR,'[^,]+',1,L) AS SPLIT_CODE FROM DUAL,
										(SELECT LEVEL L FROM DUAL CONNECT BY LEVEL <= LENGTH (AREA_WKT_SUBSTR) - LENGTH (REPLACE (AREA_WKT_SUBSTR,','))+1) B
										WHERE L <= LENGTH (AREA_WKT_SUBSTR));
								SELECT TO_NUMBER(MIN(SUBSTR(SPLIT_CODE, INSTR(SPLIT_CODE, ' ')+1,LENGTH(SPLIT_CODE)))) INTO LATITUDE_MIN FROM (
										SELECT REGEXP_SUBSTR (AREA_WKT_SUBSTR,'[^,]+',1,L) AS SPLIT_CODE FROM DUAL,
										(SELECT LEVEL L FROM DUAL CONNECT BY LEVEL <= LENGTH (AREA_WKT_SUBSTR) - LENGTH (REPLACE (AREA_WKT_SUBSTR,','))+1) B
										WHERE L <= LENGTH (AREA_WKT_SUBSTR));
								INSERT_SQL :=		'INSERT INTO FKWW_PUBLIC_DISORDER_JQ SELECT '''||DISORDER_ID||''' AS DISORDER_ID,JJDBH FROM JCJB WHERE
								LONGITUDE IS NOT NULL
								AND LATITUDE IS NOT NULL
								AND LONGITUDE > '||LONGITUDE_MIN||'
								AND LONGITUDE < '||LONGITUDE_MAX||'
								AND LATITUDE > '||LATITUDE_MIN||'
								AND LATITUDE < '||LATITUDE_MAX||'
								AND
								SDO_GEOM.RELATE (
																	SDO_GEOM.SDO_GEOMETRY (
																		2001,
																		4326,
																		MDSYS.SDO_POINT_TYPE (LONGITUDE, LATITUDE, NULL),
																		NULL,
																		NULL
																	),
																	''ANYINTERACT'',
																	SDO_GEOM.SDO_GEOMETRY (
																		'''||AREA_WKT||''',
																		4326
																	),
																	0.00001
																) = ''TRUE''';
								IF JOB_START_TIME IS NOT NULL THEN
										INSERT_SQL := INSERT_SQL||' AND BJSJ >= TO_DATE('''||START_TIME||''',''yyyy-MM-dd hh24:mi:ss'')';
								END IF;
								IF JOB_END_TIME IS NOT NULL THEN
										INSERT_SQL := INSERT_SQL||' AND BJSJ <= TO_DATE('''||END_TIME||''',''yyyy-MM-dd hh24:mi:ss'')';
								END IF;
								INSERT_SQL := INSERT_SQL||' MINUS SELECT * FROM FKWW_PUBLIC_DISORDER_JQ';
								EXECUTE IMMEDIATE INSERT_SQL;
						END IF;
			FETCH DISORDER_IDS INTO DISORDER_ID ;
			END LOOP;
			CLOSE DISORDER_IDS;
	END;
END;
  1. 警情重定位时,重新关联乱点区域存储过程
----------------------------------------------------------------
-- 警情重定位时,重新关联乱点区域存储过程   added by wyk 2018-09-30
----------------------------------------------------------------
CREATE OR REPLACE 
PROCEDURE PRD_JQ_RESET_POINT (JJDBH IN VARCHAR2, LONGITUDE IN NUMBER, LATITUDE IN NUMBER)
AS INSERT_SQL CLOB ;
BEGIN
	  DECLARE CURSOR DISORDER_IDS IS SELECT ID FROM FKWW_PUBLIC_DISORDER;
		DELETE_SQL VARCHAR2(4000);
		DISORDER_ID VARCHAR2(40);
		AREA_WKT VARCHAR2(4000);
		AREA_WKT_SUBSTR VARCHAR2(4000);
		LONGITUDE_MAX NUMBER;
		LONGITUDE_MIN NUMBER;
		LATITUDE_MAX NUMBER;
		LATITUDE_MIN NUMBER;
BEGIN
			--先删除关联数据,重定位后再添加
			DELETE_SQL := 'DELETE FROM FKWW_PUBLIC_DISORDER_JQ WHERE JJDBH = '''||JJDBH||'''';
			EXECUTE IMMEDIATE DELETE_SQL;
			OPEN DISORDER_IDS;
			FETCH DISORDER_IDS INTO DISORDER_ID;
			WHILE DISORDER_IDS % FOUND
					LOOP
						SELECT AREA_WKT INTO AREA_WKT FROM FKWW_PUBLIC_DISORDER WHERE ID = DISORDER_ID;
						IF AREA_WKT IS NULL THEN 
								AREA_WKT_SUBSTR := NULL;
						ELSE
								AREA_WKT_SUBSTR := SUBSTR(AREA_WKT, 10, length(AREA_WKT)-11);
								SELECT TO_NUMBER(MAX(SUBSTR(SPLIT_CODE, 0, INSTR(SPLIT_CODE, ' ')))) INTO LONGITUDE_MAX FROM (
										SELECT REGEXP_SUBSTR (AREA_WKT_SUBSTR,'[^,]+',1,L) AS SPLIT_CODE FROM DUAL,
										(SELECT LEVEL L FROM DUAL CONNECT BY LEVEL <= LENGTH (AREA_WKT_SUBSTR) - LENGTH (REPLACE (AREA_WKT_SUBSTR,','))+1) B
										WHERE L <= LENGTH (AREA_WKT_SUBSTR));
								SELECT TO_NUMBER(MIN(SUBSTR(SPLIT_CODE, 0, INSTR(SPLIT_CODE, ' ')))) INTO LONGITUDE_MIN FROM (
										SELECT REGEXP_SUBSTR (AREA_WKT_SUBSTR,'[^,]+',1,L) AS SPLIT_CODE FROM DUAL,
										(SELECT LEVEL L FROM DUAL CONNECT BY LEVEL <= LENGTH (AREA_WKT_SUBSTR) - LENGTH (REPLACE (AREA_WKT_SUBSTR,','))+1) B
										WHERE L <= LENGTH (AREA_WKT_SUBSTR));
								SELECT TO_NUMBER(MAX(SUBSTR(SPLIT_CODE, INSTR(SPLIT_CODE, ' ')+1,LENGTH(SPLIT_CODE)))) INTO LATITUDE_MAX FROM (
										SELECT REGEXP_SUBSTR (AREA_WKT_SUBSTR,'[^,]+',1,L) AS SPLIT_CODE FROM DUAL,
										(SELECT LEVEL L FROM DUAL CONNECT BY LEVEL <= LENGTH (AREA_WKT_SUBSTR) - LENGTH (REPLACE (AREA_WKT_SUBSTR,','))+1) B
										WHERE L <= LENGTH (AREA_WKT_SUBSTR));
								SELECT TO_NUMBER(MIN(SUBSTR(SPLIT_CODE, INSTR(SPLIT_CODE, ' ')+1,LENGTH(SPLIT_CODE)))) INTO LATITUDE_MIN FROM (
										SELECT REGEXP_SUBSTR (AREA_WKT_SUBSTR,'[^,]+',1,L) AS SPLIT_CODE FROM DUAL,
										(SELECT LEVEL L FROM DUAL CONNECT BY LEVEL <= LENGTH (AREA_WKT_SUBSTR) - LENGTH (REPLACE (AREA_WKT_SUBSTR,','))+1) B
										WHERE L <= LENGTH (AREA_WKT_SUBSTR));
								IF LONGITUDE >= LONGITUDE_MIN AND LONGITUDE <= LONGITUDE_MAX AND LATITUDE >= LATITUDE_MIN AND LATITUDE <= LATITUDE_MAX THEN
										INSERT_SQL := 'INSERT INTO FKWW_PUBLIC_DISORDER_JQ SELECT '''||DISORDER_ID||''','''||JJDBH||''' FROM DUAL
													WHERE	SDO_GEOM.RELATE (
																			SDO_GEOM.SDO_GEOMETRY (
																				2001,
																				4326,
																				MDSYS.SDO_POINT_TYPE ('||LONGITUDE||', '||LATITUDE||', NULL),
																				NULL,
																				NULL
																			),
																			''ANYINTERACT'',
																			SDO_GEOM.SDO_GEOMETRY (
																				'''||AREA_WKT||''',
																				4326
																			),
																			0.00001
																		) = ''TRUE''';									
										EXECUTE IMMEDIATE INSERT_SQL;
								END IF;
						END IF;
			FETCH DISORDER_IDS INTO DISORDER_ID ;
			END LOOP;
			CLOSE DISORDER_IDS;
	END;
END;
  1. 治安乱点区域黄赌毒警情分析函数(利用管道输出)
----------------------------------------------------------------
-- 治安乱点区域黄赌毒警情分析函数   added by wyk 2018-09-21
----------------------------------------------------------------
CREATE TYPE ROW_TOPIC_TYPE AS OBJECT (COL1 VARCHAR2(100),COL2 NUMBER);
CREATE TYPE TABLE_TOPIC_TYPE AS TABLE OF ROW_TOPIC_TYPE;

CREATE OR REPLACE 
FUNCTION FUNC_COUNT_TOPIC_TYPE (ORDER_ID IN VARCHAR2,TOPIC_TYPE IN VARCHAR2,START_TIME VARCHAR2,END_TIME VARCHAR2)
--ORDER_ID:乱点区域Id  TOPIC_TYPE:警情类型('00010001000000000000,00010000000000000000,00030000000000000000')
--START_TIME:开始时间  END_TIME:结束时间
RETURN TABLE_TOPIC_TYPE PIPELINED IS V ROW_TOPIC_TYPE;--以管道形式输出
BEGIN
	DECLARE CURSOR TYPE_ARRS IS SELECT REGEXP_SUBSTR (TOPIC_TYPE,'[^,]+',1,L) FROM DUAL,
										(SELECT LEVEL L FROM DUAL CONNECT BY LEVEL <= LENGTH (TOPIC_TYPE) - LENGTH (REPLACE (TOPIC_TYPE,','))+1) B
										WHERE L <= LENGTH (TOPIC_TYPE);
	TYPE_ITEM VARCHAR2(30);
	BEGIN
			OPEN TYPE_ARRS;
			FETCH TYPE_ARRS INTO TYPE_ITEM;
			WHILE TYPE_ARRS % FOUND
					LOOP
							IF SUBSTR(TYPE_ITEM,5)='0000000000000000' THEN
									FOR THISROW IN (
													SELECT SUBSTR(JQ_TYPE,0,4)||'0000000000000000' AS JQ_TYPE,COUNT(1) AS COUNT FROM 
													(SELECT J.JQ_TYPE,J.BJSJ FROM (SELECT * FROM FKWW_PUBLIC_DISORDER_JQ WHERE DISORDER_ID = ORDER_ID) T
													LEFT JOIN JCJB J ON T.JJDBH=J.JJDBH) WHERE JQ_TYPE LIKE SUBSTR(TYPE_ITEM,0,4)||'%'
													AND BJSJ >= TO_DATE(START_TIME,'yyyy-MM-dd HH24:mi:ss')
													AND BJSJ <= TO_DATE(END_TIME,'yyyy-MM-dd HH24:mi:ss')
													GROUP BY SUBSTR(JQ_TYPE,0,4)
											)
											LOOP
													V := ROW_TOPIC_TYPE(THISROW.JQ_TYPE,THISROW.COUNT);
													PIPE ROW(V);
											END LOOP;
							ELSE IF SUBSTR(TYPE_ITEM,9)='000000000000' THEN
									FOR THISROW IN (
													SELECT SUBSTR(JQ_TYPE,0,8)||'000000000000' AS JQ_TYPE,COUNT(1) AS COUNT FROM 
													(SELECT J.JQ_TYPE,J.BJSJ FROM (SELECT * FROM FKWW_PUBLIC_DISORDER_JQ WHERE DISORDER_ID = ORDER_ID) T
													LEFT JOIN JCJB J ON T.JJDBH=J.JJDBH) WHERE JQ_TYPE LIKE SUBSTR(TYPE_ITEM,0,8)||'%' 
													AND BJSJ >= TO_DATE(START_TIME,'yyyy-MM-dd HH24:mi:ss')
													AND BJSJ <= TO_DATE(END_TIME,'yyyy-MM-dd HH24:mi:ss')
													GROUP BY SUBSTR(JQ_TYPE,0,8)
											)
											LOOP
													V := ROW_TOPIC_TYPE(THISROW.JQ_TYPE,THISROW.COUNT);
													PIPE ROW(V);
											END LOOP;
							ELSE IF SUBSTR(TYPE_ITEM,9)='000000000000' THEN
									FOR THISROW IN (
													SELECT SUBSTR(JQ_TYPE,0,8)||'000000000000' AS JQ_TYPE,COUNT(1) AS COUNT FROM 
													(SELECT J.JQ_TYPE,J.BJSJ FROM (SELECT * FROM FKWW_PUBLIC_DISORDER_JQ WHERE DISORDER_ID = ORDER_ID) T
													LEFT JOIN JCJB J ON T.JJDBH=J.JJDBH) WHERE JQ_TYPE LIKE SUBSTR(TYPE_ITEM,0,8)||'%' 
													AND BJSJ >= TO_DATE(START_TIME,'yyyy-MM-dd HH24:mi:ss')
													AND BJSJ <= TO_DATE(END_TIME,'yyyy-MM-dd HH24:mi:ss')
													GROUP BY SUBSTR(JQ_TYPE,0,8)
											)
											LOOP
													V := ROW_TOPIC_TYPE(THISROW.JQ_TYPE,THISROW.COUNT);
													PIPE ROW(V);
											END LOOP;
							ELSE IF SUBSTR(TYPE_ITEM,13)='00000000' THEN
									FOR THISROW IN (
													SELECT SUBSTR(JQ_TYPE,0,12)||'00000000' AS JQ_TYPE,COUNT(1) AS COUNT FROM 
													(SELECT J.JQ_TYPE,J.BJSJ FROM (SELECT * FROM FKWW_PUBLIC_DISORDER_JQ WHERE DISORDER_ID = ORDER_ID) T
													LEFT JOIN JCJB J ON T.JJDBH=J.JJDBH) WHERE JQ_TYPE LIKE SUBSTR(TYPE_ITEM,0,12)||'%' 
													AND BJSJ >= TO_DATE(START_TIME,'yyyy-MM-dd HH24:mi:ss')
													AND BJSJ <= TO_DATE(END_TIME,'yyyy-MM-dd HH24:mi:ss')
													GROUP BY SUBSTR(JQ_TYPE,0,12)
											)
											LOOP
													V := ROW_TOPIC_TYPE(THISROW.JQ_TYPE,THISROW.COUNT);
													PIPE ROW(V);
											END LOOP;
							ELSE IF SUBSTR(TYPE_ITEM,17)='0000' THEN
									FOR THISROW IN (
													SELECT SUBSTR(JQ_TYPE,0,16)||'0000' AS JQ_TYPE,COUNT(1) AS COUNT FROM 
													(SELECT J.JQ_TYPE,J.BJSJ FROM (SELECT * FROM FKWW_PUBLIC_DISORDER_JQ WHERE DISORDER_ID = ORDER_ID) T
													LEFT JOIN JCJB J ON T.JJDBH=J.JJDBH) WHERE JQ_TYPE LIKE SUBSTR(TYPE_ITEM,0,16)||'%' 
													AND BJSJ >= TO_DATE(START_TIME,'yyyy-MM-dd HH24:mi:ss')
													AND BJSJ <= TO_DATE(END_TIME,'yyyy-MM-dd HH24:mi:ss')
													GROUP BY SUBSTR(JQ_TYPE,0,16)
											)
											LOOP
													V := ROW_TOPIC_TYPE(THISROW.JQ_TYPE,THISROW.COUNT);
													PIPE ROW(V);
											END LOOP;
							ELSE IF TYPE_ITEM IS NOT NULL THEN
											FOR THISROW IN (
													SELECT JQ_TYPE,COUNT(1) AS COUNT FROM 
													(SELECT J.JQ_TYPE,J.BJSJ FROM (SELECT * FROM FKWW_PUBLIC_DISORDER_JQ WHERE DISORDER_ID = ORDER_ID) T
													LEFT JOIN JCJB J ON T.JJDBH=J.JJDBH) WHERE JQ_TYPE = TYPE_ITEM 
													AND BJSJ >= TO_DATE(START_TIME,'yyyy-MM-dd HH24:mi:ss')
													AND BJSJ <= TO_DATE(END_TIME,'yyyy-MM-dd HH24:mi:ss')
													GROUP BY JQ_TYPE
											)
											LOOP
													V := ROW_TOPIC_TYPE(THISROW.JQ_TYPE,THISROW.COUNT);
													PIPE ROW(V);
											END LOOP;
							END IF;
							END IF;
							END IF;
							END IF;
							END IF;
							END IF;
					FETCH TYPE_ARRS INTO TYPE_ITEM;
					END LOOP;
			CLOSE TYPE_ARRS;
	END;
	RETURN;
END;
  1. 判断案件或警情是否已提请合成,如果未提请合成,则判断关联的案件或警情是否已提请合成
--------------------------------------------------------------------
--   判断案件或警情是否已提请合成,如果未提请合成,则判断关联的案件或警情是否已提请合成 added by wyk 2018-09-19
--------------------------------------------------------------------
CREATE OR REPLACE 
FUNCTION "FUNC_GET_HCYP_STATE" (CASE_ID_IN IN VARCHAR2,JJDBH_IN IN VARCHAR2)
RETURN NUMBER
AS HC_STATE NUMBER;CASE_CODE_TEMP VARCHAR2(50);
BEGIN
	IF CASE_ID_IN IS NULL THEN
			SELECT MAX(IS_DELETE) INTO HC_STATE FROM VIRTUAL_CASE WHERE CASE_ID = (SELECT CASE_ID FROM CASE WHERE CASE_CODE = 'Q'||JJDBH_IN);
			IF HC_STATE = 0 THEN RETURN 1;--本身已提请合成
			ELSE IF HC_STATE = 1 THEN RETURN 2;--本身已删除合成
			ELSE IF HC_STATE IS NULL THEN
			DECLARE CURSOR IS_DELETES IS SELECT IS_DELETE FROM VIRTUAL_CASE  WHERE CASE_ID IN (SELECT case_id FROM CASE_ASSOCIATE_JQ WHERE jjdbh = JJDBH_IN );
								IS_DELETE NUMBER;
					BEGIN 
								IF NOT IS_DELETES%ISOPEN THEN OPEN IS_DELETES;END IF;
										FETCH IS_DELETES INTO IS_DELETE;
													WHILE IS_DELETES%FOUND
															LOOP IF IS_DELETE = 0 THEN CLOSE IS_DELETES;RETURN 3;--关联的案件已提请合成
																	 ELSE IF IS_DELETE = 1 THEN RETURN 4;END IF;--关联的案件已删除合成
																	 END IF;FETCH IS_DELETES INTO IS_DELETE;END LOOP;CLOSE IS_DELETES;RETURN 0;     
				  END;
			END IF;
			END IF;
			END IF;
	ELSE
				SELECT MAX(IS_DELETE) INTO HC_STATE FROM VIRTUAL_CASE WHERE CASE_ID = CASE_ID_IN;
				IF HC_STATE = 0 THEN RETURN 1;--本身已提请合成
				ELSE IF HC_STATE = 1 THEN RETURN 2;--本身已删除合成
				ELSE IF HC_STATE IS NULL THEN
						DECLARE CURSOR IS_DELETES IS SELECT IS_DELETE FROM VIRTUAL_CASE  WHERE CASE_ID IN (SELECT CASE_ID FROM CASE WHERE CASE_CODE IN (SELECT 'Q'||JJDBH FROM CASE_ASSOCIATE_JQ WHERE CASE_ID = CASE_ID_IN));
								IS_DELETE NUMBER;
						BEGIN 
								IF NOT IS_DELETES%ISOPEN THEN OPEN IS_DELETES;END IF;
										FETCH IS_DELETES INTO IS_DELETE;
													WHILE IS_DELETES%FOUND
															LOOP IF IS_DELETE = 0 THEN CLOSE IS_DELETES;RETURN 5;--关联的警情已提请合成
																	 ELSE IF IS_DELETE = 1 THEN RETURN 6;END IF;--关联的警情已删除合成
																	 END IF;FETCH IS_DELETES INTO IS_DELETE;END LOOP;CLOSE IS_DELETES;RETURN 0;     
						END;
				END IF;
				END IF;
				END IF;
	END IF;
END;
-- 0:未提请合成
-- 1:本身已提请合成
-- 2:本身已删除合成
-- 3:关联的案件已提请合成
-- 4:关联的案件已删除合成
-- 5:关联的警情已提请合成
-- 6:关联的警情已删除合成
  1. A数据定时迁移
----------------------------------------------------------------
-- A数据定时迁移(TB_INOUT_RESULT表保留5天数据)   added by wyk 2018-12-21
----------------------------------------------------------------
CREATE OR REPLACE 
PROCEDURE PRD_TB_INOUT_RESULT_BAK AS
INSERT_SQL VARCHAR2(200);
DELETE_SQL VARCHAR2(200);
BEGIN
	INSERT_SQL := 'INSERT INTO TB_INOUT_RESULT_BAK SELECT * FROM TB_INOUT_RESULT WHERE DATETIME >= to_char(TRUNC(SYSDATE-5),''yyyy-MM-dd hh24:mi:ss'') AND DATETIME < to_char(TRUNC(SYSDATE-4),''yyyy-MM-dd hh24:mi:ss'')';
	EXECUTE IMMEDIATE INSERT_SQL;
	DELETE_SQL := 'DELETE FROM TB_INOUT_RESULT WHERE DATETIME >= to_char(TRUNC(SYSDATE-5),''yyyy-MM-dd hh24:mi:ss'') AND DATETIME < to_char(TRUNC(SYSDATE-4),''yyyy-MM-dd hh24:mi:ss'')';
	EXECUTE IMMEDIATE DELETE_SQL;
END;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值