Oracle批量生成版本

-- 批量生成版本
DECLARE
fk_str VARCHAR2(2000) := '';
BEGIN
FOR i IN 23 .. 25 loop
fk_str := LOWER(RAWTOHEX(SYS_GUID()));

INSERT INTO ekp.KMS_KNOWLEDGE_BASE_DOC
(
			FD_ID,
			FD_KNOWLEDGE_TYPE,
			DOC_SUBJECT,
			DOC_STATUS,
			DOC_CREATOR_ID,
			DOC_CREATE_TIME,
			DOC_PUBLISH_TIME,
			OUTER_AUTHOR,
			FD_DESCRIPTION,
			DOC_DEPT_ID,
			DOC_IS_INTRODUCED,
			DOC_INTR_COUNT,
			DOC_EVAL_COUNT,
			DOC_SCORE,
			DOC_READ_COUNT,
			FD_HISTORY_COUNT,
			FD_TOTAL_COUNT,
			DOC_IS_NEW_VERSION,
			AUTH_AREA_ID,
			DOC_CATEGORY_ID,
			DOC_DELETE_FLAG,
			DOC_DELETE_TIME,
			DOC_DELETE_BY,
			DOC_ORIGIN_DOCID,
			AUTH_READER_FLAG,
			AUTH_ATT_NODOWNLOAD,
			AUTH_ATT_NOCOPY,
			AUTH_ATT_NOPRINT,
			FD_SET_TOP_TIME,
			DOC_IS_INDEX_TOP,
			FD_SET_TOP_LEVEL,
			FD_SET_TOP_REASON,
			FD_TOP_CATEGORY_ID,
			DOC_EFFECTIVE_TIME,
			DOC_FAILURE_TIME,
			DOC_EXPIRE_TIME,
			FD_CHANGE_READER_FLAG,
			FD_CHANGE_EDITOR_FLAG,
			FD_CHANGE_ATT
		) 
      SELECT fk_str AS FD_ID,
             2 as FD_KNOWLEDGE_TYPE,
             'chenchen' AS DOC_SUBJECT,
             30 AS DOC_STATUS,
             '17185ecd7917d8c2ebd65da4ef4be9de' AS DOC_CREATOR_ID,
             SYSDATE AS DOC_CREATE_TIME,
             SYSDATE AS DOC_PUBLISH_TIME,
             NULL AS OUTER_AUTHOR,
             NULL AS FD_DESCRIPTION,
             NULL AS DOC_DEPT_ID,
             NULL AS DOC_IS_INTRODUCED,
             0 AS DOC_INTR_COUNT,
             0 AS DOC_EVAL_COUNT,
             NULL AS DOC_SCORE,
             0 AS DOC_READ_COUNT,
             i AS FD_HISTORY_COUNT,
             0 AS FD_TOTAL_COUNT,
             0 AS DOC_IS_NEW_VERSION,
             NULL AUTH_AREA_ID,
             '1718606a287042ae2e808f74262a007a' AS DOC_CATEGORY_ID,
             0 AS DOC_DELETE_FLAG,
             NULL AS DOC_DELETE_TIME,
             NULL AS DOC_DELETE_BY,
             null AS DOC_ORIGIN_DOCID,
             0 AS AUTH_READER_FLAG,
             0 AS AUTH_ATT_NODOWNLOAD,
             0 AS AUTH_ATT_NOCOPY,
             0 AS AUTH_ATT_NOPRINT,
             NULL AS FD_SET_TOP_TIME,
             0 AS DOC_IS_INDEX_TOP,
             NULL AS FD_SET_TOP_LEVEL,
             NULL AS FD_SET_TOP_REASON,
             NULL AS FD_TOP_CATEGORY_ID,
             NULL AS DOC_EFFECTIVE_TIME,
             NULL AS DOC_FAILURE_TIME,
             NULL AS DOC_EXPIRE_TIME,
             0 AS FD_CHANGE_READER_FLAG,
             0 AS FD_CHANGE_EDITOR_FLAG,
             0 AS FD_CHANGE_ATT
        FROM ekp.KMS_KNOWLEDGE_BASE_DOC
       WHERE FD_ID = '17186071c75669e57040f864d03840b4';

INSERT INTO ekp.KMS_WIKI_MAIN
(
				FD_FK_ID,
				DOC_CONTENT,
				FD_HTML_CONTENT,
				FD_CONTENT_TYPE,
				FD_VERSION,
				FD_FIRST_ID,
				FD_PARENT_ID,
				FD_LAST_EDITION,
				DOC_ALTEROR_ID,
				DOC_ALTER_TIME,
				FD_REASON,
				FD_LAST_MODIFIED_TIME,
				DOC_RECOMMEND_TIME,
				FD_NUMBER,
				EXTEND_FILE_PATH,
				EXTEND_DATA_XML,
				FD_TEMPLATE_ID,
				DOC_SOURCE_ID
			)
      SELECT fk_str AS FD_FK_ID,
             DOC_CONTENT,
             FD_HTML_CONTENT,
             FD_CONTENT_TYPE,
             trunc(i / 10,2) AS FD_VERSION,
             '17186071c75669e57040f864d03840b4' AS FD_FIRST_ID,
             (SELECT FD_FK_ID
                FROM (SELECT FD_FK_ID, FD_LAST_MODIFIED_TIME
                        FROM ekp.KMS_WIKI_MAIN
                       where FD_FIRST_ID='17186071c75669e57040f864d03840b4'
                       ORDER BY ROWNUM DESC)
               WHERE ROWNUM <= 1) AS FD_PARENT_ID,
             2 AS FD_LAST_EDITION,
             '16bfab163cf160360f2ecb048e48abed' AS DOC_ALTEROR_ID,
             SYSDATE AS DOC_ALTER_TIME,
             i AS FD_REASON,
             SYSDATE AS FD_LAST_MODIFIED_TIME,
             NULL AS DOC_RECOMMEND_TIME,
             i AS FD_NUMBER,
             NULL AS EXTEND_FILE_PATH,
             '<?xml version="1.0" encoding="UTF-8"?><java version="1.7.0_79" class="java.beans.XMLDecoder"> <object class="java.util.HashMap"/></java>' AS EXTEND_DATA_XML,
             NULL AS FD_TEMPLATE_ID,
             NULL AS DOC_SOURCE_ID
        FROM ekp.KMS_WIKI_MAIN
       WHERE FD_FK_ID = '17186071c75669e57040f864d03840b4';
END loop;
END;

SQLServer版

declare @begin int
declare @loopIndex int
declare @fk_str nvarchar(50)
set @begin=11            --循环开始次数
set @loopIndex = 15       --循环结束次数
begin
	while @begin<=@loopIndex
		begin

		set @fk_str = LOWER(REPLACE(NEWID(),'-',''))

	  		INSERT INTO KMS_KNOWLEDGE_BASE_DOC (
			FD_ID,
			FD_KNOWLEDGE_TYPE,
			DOC_SUBJECT,
			DOC_STATUS,
			DOC_CREATOR_ID,
			DOC_CREATE_TIME,
			DOC_PUBLISH_TIME,
			OUTER_AUTHOR,
			FD_DESCRIPTION,
			DOC_DEPT_ID,
			DOC_IS_INTRODUCED,
			DOC_INTR_COUNT,
			DOC_EVAL_COUNT,
			DOC_SCORE,
			DOC_READ_COUNT,
			FD_HISTORY_COUNT,
			FD_TOTAL_COUNT,
			DOC_IS_NEW_VERSION,
			AUTH_AREA_ID,
			DOC_CATEGORY_ID,
			DOC_DELETE_FLAG,
			DOC_DELETE_TIME,
			DOC_DELETE_BY,
			DOC_ORIGIN_DOCID,
			AUTH_READER_FLAG,
			AUTH_ATT_NODOWNLOAD,
			AUTH_ATT_NOCOPY,
			AUTH_ATT_NOPRINT,
			FD_SET_TOP_TIME,
			DOC_IS_INDEX_TOP,
			FD_SET_TOP_LEVEL,
			FD_SET_TOP_REASON,
			FD_TOP_CATEGORY_ID,
			DOC_EFFECTIVE_TIME,
			DOC_FAILURE_TIME,
			DOC_EXPIRE_TIME,
			FD_CHANGE_READER_FLAG,
			FD_CHANGE_EDITOR_FLAG,
			FD_CHANGE_ATT
		) SELECT
			@fk_str AS FD_ID,
			2 AS FD_KNOWLEDGE_TYPE,
			'辅助分类测试' AS DOC_SUBJECT,
			30 AS DOC_STATUS,
			'1183b0b84ee4f581bba001c47a78b2d9' AS DOC_CREATOR_ID,
			GETDATE() AS DOC_CREATE_TIME,
			GETDATE() AS DOC_PUBLISH_TIME,
			NULL AS OUTER_AUTHOR,
			NULL AS FD_DESCRIPTION,
			'16d6c71dc67b65b9890ee56425788df2' AS DOC_DEPT_ID,
			NULL AS DOC_IS_INTRODUCED,
			0 AS DOC_INTR_COUNT,
			0 AS DOC_EVAL_COUNT,
			NULL AS DOC_SCORE,
			0 AS DOC_READ_COUNT,
			@BEGIN AS FD_HISTORY_COUNT,
			0 AS FD_TOTAL_COUNT,
			0 AS DOC_IS_NEW_VERSION,
			NULL AUTH_AREA_ID,
			'1720240be60e730894e5862415dabec1' AS DOC_CATEGORY_ID,
			0 AS DOC_DELETE_FLAG,
			NULL AS DOC_DELETE_TIME,
			NULL AS DOC_DELETE_BY,
			'17607a09d58aaf806a761084c789b9d9' AS DOC_ORIGIN_DOCID,
			0 AS AUTH_READER_FLAG,
			0 AS AUTH_ATT_NODOWNLOAD,
			0 AS AUTH_ATT_NOCOPY,
			0 AS AUTH_ATT_NOPRINT,
			NULL AS FD_SET_TOP_TIME,
			0 AS DOC_IS_INDEX_TOP,
			NULL AS FD_SET_TOP_LEVEL,
			NULL AS FD_SET_TOP_REASON,
			NULL AS FD_TOP_CATEGORY_ID,
			NULL AS DOC_EFFECTIVE_TIME,
			NULL AS DOC_FAILURE_TIME,
			NULL AS DOC_EXPIRE_TIME,
			0 AS FD_CHANGE_READER_FLAG,
			0 AS FD_CHANGE_EDITOR_FLAG,
			0 AS FD_CHANGE_ATT
		FROM
			KMS_KNOWLEDGE_BASE_DOC
		WHERE
			FD_ID = '175df5a56b577ca0be757b94325b688c' ; 

		INSERT INTO KMS_WIKI_MAIN (
				FD_FK_ID,
				DOC_CONTENT,
				FD_HTML_CONTENT,
				FD_CONTENT_TYPE,
				FD_VERSION,
				FD_FIRST_ID,
				FD_PARENT_ID,
				FD_LAST_EDITION,
				DOC_ALTEROR_ID,
				DOC_ALTER_TIME,
				FD_REASON,
				FD_LAST_MODIFIED_TIME,
				DOC_RECOMMEND_TIME,
				FD_NUMBER,
				EXTEND_FILE_PATH,
				EXTEND_DATA_XML,
				FD_TEMPLATE_ID,
				DOC_SOURCE_ID
			)SELECT
				@fk_str AS FD_FK_ID,
				DOC_CONTENT,
				FD_HTML_CONTENT,
				FD_CONTENT_TYPE,
				cast(@BEGIN*1.0/10 as decimal(18,1)) AS FD_VERSION,
				'175df5a56b577ca0be757b94325b688c' AS FD_FIRST_ID,
				(
					SELECT
						TOP 1 FD_FK_ID
					FROM
						KMS_WIKI_MAIN
                                        where  FD_FIRST_ID='175df5a56b577ca0be757b94325b688c'
					ORDER BY
						fd_last_modified_time DESC
				) AS FD_PARENT_ID,
				2 AS FD_LAST_EDITION,
				'1183b0b84ee4f581bba001c47a78b2d9' AS DOC_ALTEROR_ID,
				GETDATE() AS DOC_ALTER_TIME,
				@BEGIN AS FD_REASON,
				GETDATE() AS FD_LAST_MODIFIED_TIME,
				NULL AS DOC_RECOMMEND_TIME,
				@BEGIN AS FD_NUMBER,
				NULL AS EXTEND_FILE_PATH,
				'<?xml version="1.0" encoding="UTF-8"?><java version="1.7.0_79" class="java.beans.XMLDecoder"><object class="java.util.HashMap"/></java>' AS EXTEND_DATA_XML,
				NULL AS FD_TEMPLATE_ID,
				NULL AS DOC_SOURCE_ID
			FROM
				KMS_WIKI_MAIN
			WHERE
				FD_FK_ID = '175df5a56b577ca0be757b94325b688c' ;

			set @begin=@begin+1;
			continue;
		end
end
print @loopIndex
posted @ 2020-11-25 16:24  灯塔下的守望者  阅读(103)  评论(0编辑  收藏  举报