Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Import query from file into procedure
    primarykey
    data
    text
    <p>I am generating a procedure to check for all data issues like duplicates in database tables.So the format is as such explained below:</p> <pre><code>CREATE TABLE &lt;test_table&gt; --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&lt;&gt;1 and TEST_LEVEL&lt;&gt;2 and TEST_LEVEL&lt;&gt;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:='&lt;table_to_be_tested&gt;'; 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 &lt;table_to_be_tested&gt;) x where occurrence &gt; 1; IF V_EXP_RESULT = V_ACT_RESULT THEN V_QUERY_STATUS:='PASS'; ELSE V_QUERY_STATUS:='FAIL'; END IF; END IF; Insert into &lt;test_table&gt; --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; </code></pre> <p>Now i have two questions i have done everything except storing the values <code>TEST_LEVEL</code>,<code>START_WID</code>,<code>END_WID</code> in the which i commented in the procedure because one using them i was getting compiler error. Question 1:-How to store <code>TEST_LEVEL</code>,<code>START_WID</code>,<code>END_WID</code> in the (Answered with help of @Swapna answer.) Question 2:-I will be running multiple queries on different tables and storing them in <code>V_ACT_RESULT</code> so i was think if there is a way to save all queries in some text file and then just import them here with some script.If anyone knows how to do this please elaborate.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload