我正在生成一个程序来检查所有数据问题,例如数据库表中的重复项。因此格式如下所述:
CREATE TABLE <test_table> --table i created to save the procedure test results
(
RUN_ID number,
QUERY_ID NUMBER,
QUERY_NAME VARCHAR(1000),
QUERY_STATUS VARCHAR(10),
MAIN_TABLE_NAME VARCHAR(500),
EXP_RESULT VARCHAR(4000),
ACT_RESULT VARCHAR(4000),
RUN_ON_DT DATE,
TEST_LEVEL_GIVEN NUMBER,
START_TIME_WID NUMBER,
END_TIME_WID NUMBER,
TEST_QUERY VARCHAR(4000),
QUERY_DESC VARCHAR(4000),
Comments VARCHAR(4000)
)
create or replace
PROCEDURE PROC_TESTING (TEST_LEVEL IN NUMBER DEFAULT 0 , START_WID IN NUMBER DEFAULT 0, END_WID NUMBER DEFAULT 0) IS
--TEST_LEVEL=0 IS TO RUN ALL QUERIES : FULL PROCEDURE
--TEST_LEVEL=1 IS FOR BASIC QUERIES
--TEST_LEVEL=2 IS FOR DIMENSION QUERIES
--TEST_LEVEL=3 IS FOR FACT QUERIES
--TEST_LEVEL=4 IS FOR .... QUERIES
--TEST_LEVEL=5 IS FOR .... QUERIES
V_RUN_ID NUMBER;
V_QUERY_ID NUMBER;
V_QUERY_NAME VARCHAR(1000);
V_QUERY_STATUS VARCHAR(10);
V_MAIN_TABLE_NAME VARCHAR(500);
V_EXP_RESULT VARCHAR(4000);
V_ACT_RESULT VARCHAR(4000);
V_RUN_ON_DT DATE;
V_TEST_QUERY VARCHAR(4000);
V_QUERY_DESC VARCHAR(4000);
V_COMMENTS VARCHAR(4000);
BEGIN
DBMS_OUTPUT.PUT_LINE( 'STARTING THE TESTING PROC ON ' || SYSDATE );
SELECT RUN_ID.NEXTVAL INTO V_RUN_ID FROM DUAL;
SELECT SYSDATE INTO V_RUN_ON_DT FROM DUAL;
IF TEST_LEVEL<>1 and TEST_LEVEL<>2 and TEST_LEVEL<>0
Then
DBMS_OUTPUT.PUT_LINE( 'Conditions not met' || SYSDATE );
return;
end if;
IF TEST_LEVEL=1 or TEST_LEVEL=2 or TEST_LEVEL=0
Then
V_QUERY_ID:=1;
V_QUERY_NAME:='Duplicates check';
V_MAIN_TABLE_NAME:='<table_to_be_tested>';
V_QUERY_DESC:='checking for duplicates';
-- Expected results
V_EXP_RESULT := 0;
-- Actual results
select count(*) into V_ACT_RESULT
from (select id1
, id2
, EFFECTIVE_FROM_DT
, EFFECTIVE_TO_DT
, update_dt
, row_number() over (partition by
id1
, id2
, EFFECTIVE_FROM_DT
, EFFECTIVE_TO_DT
order by integration_id ) as occurrence
from <table_to_be_tested>) x
where occurrence > 1;
IF V_EXP_RESULT = V_ACT_RESULT THEN
V_QUERY_STATUS:='PASS';
ELSE
V_QUERY_STATUS:='FAIL';
END IF;
END IF;
Insert into <test_table> --going to store all above explained values into this table
(
RUN_ID ,
QUERY_ID ,
QUERY_NAME ,
QUERY_STATUS ,
MAIN_TABLE_NAME ,
EXP_RESULT,
ACT_RESULT ,
RUN_ON_DT,
TEST_LEVEL_GIVEN,
START_TIME_WID,
END_TIME_WID,
TEST_QUERY ,
QUERY_DESC,
Comments )
values
(
V_RUN_ID ,
V_QUERY_ID ,
V_QUERY_NAME,
V_QUERY_STATUS ,
V_MAIN_TABLE_NAME ,
V_EXP_RESULT ,
V_ACT_RESULT ,
V_RUN_ON_DT ,
TEST_LEVEL,
START_WID,
END_WID,
V_TEST_QUERY ,
V_QUERY_DESC ,
V_COMMENTS );
END;
现在我有两个问题,除了存储值 TEST_LEVEL
,我已经完成了所有工作START_WID
,END_WID
我在过程中对此进行了评论,因为一个使用它们我得到了编译器错误。问题 1:-如何在(在 @Swapna 答案的帮助下回答。)问题 2:-我将在不同的表上运行多个查询并将它们存储在其中,TEST_LEVEL
所以START_WID
我想是否有办法保存所有在一些文本文件中查询,然后用一些脚本将它们导入这里。如果有人知道如何做到这一点,请详细说明。END_WID
V_ACT_RESULT