doc-exports/docs/dws/tool/dws_mt_0158.html
Lu, Huayi 346ac31da9 DWS TG 8.1.3.200 VERSION
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Reviewed-by: Jiang, Beibei <beibei.jiang@t-systems.com>
Co-authored-by: Lu, Huayi <luhuayi@huawei.com>
Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
2023-08-28 09:20:17 +00:00

632 lines
33 KiB
HTML

<a name="EN-US_TOPIC_0000001188362596"></a><a name="EN-US_TOPIC_0000001188362596"></a>
<h1 class="topictitle1">Packages</h1>
<div id="body8662426"><p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p142931113195111">Packages are schema objects that group logically related PL/SQL types, variables, functions and procedures. In Oracle, each package consists of two parts: package specification and package body. The package specification may contain variables and REF CURSOR in variables. The package REF CURSORs are identified and migrated in the referred places. The functions and procedures in the package body are migrated into individual functions and procedures. The types and variables in the package body are migrated to each of the functions and procedures.</p>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p4445698820">If the schema names of the package specification and package body do not match, then the tool will log a schema name mismatch error to the <strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b1040735612307">DSCError.log</strong> file.</p>
<div class="fignone" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_fig1531917481910"><span class="figcap"><b>Figure 1 </b>Migration of PL/SQL packages</span><br><span><img id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_image63201161114839" src="figure/en-us_image_0000001233800845.png"></span></div>
<div class="p" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p1050535822219"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b17630193519545">Input - PL/SQL Packages </strong>(Package specifications and body)<pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen13506135814221">CREATE or REPLACE PACKAGE BODY pkg_get_empdet
IS
PROCEDURE get_ename(eno in number,ename out varchar2)
IS
BEGIN
SELECT ename || ',' || last_name
INTO ename
FROM emp
WHERE empno = eno;
END get_ename;
FUNCTION get_sal(eno in number) return number
IS
lsalary number;
BEGIN
SELECT salary
INTO lsalary
FROM emp
WHERE empno = eno;
RETURN lsalary;
END get_sal;
END pkg_get_empdet;
/</pre>
</div>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p950855813225"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b14895441185412">Output</strong> (The output contains separate functions and procedures for each of the functions and procedures in the package body of the input)</p>
<pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen204171720519">CREATE
or REPLACE PROCEDURE
pkg_get_empdet.get_ename ( eno in number ,ename out varchar2 ) IS
BEGIN
SELECT
ename || ',' || last_name INTO ename
FROM
emp
WHERE
empno = eno ;
END ;
/
CREATE
or REPLACE FUNCTION
pkg_get_empdet.get_sal ( eno in number )
return number IS lsalary number ;
BEGIN
SELECT
salary INTO lsalary
FROM
emp
WHERE
empno = eno ;
RETURN lsalary ;
END ;
/</pre>
<div class="p" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p51613045216"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b0159161110268">Input - PL/SQL Packages</strong><pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen4159121192616">CREATE OR replace VIEW vw_emp_name AS
Select pkg_get_empdet.get_sal(emp.empno) as empsal from emp;</pre>
</div>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p416531115264"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b1734101111413">Output</strong></p>
<pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen133461114416">CREATE
OR replace VIEW vw_emp_name AS (SELECT
pkg_get_empdet.get_sal (emp.empno) AS empsal
FROM
emp)
;
output:
set
package_name_list = 'func' ;
CREATE
OR REPLACE FUNCTION func1 ( i1 INT )
RETURN INT As TYPE r_rthpagat_list IS RECORD ( /* Record
information about cross-border RMB */
business parameters ( rthpagat ) rthpagat_REQUESTID
RMTS_REMITTANCE_PARAM.REQUESTID%TYPE ,rthpagat_PARAMTNAME
RMTS_REMITTANCE_PARAM.PARAMTNAME%TYPE ,rthpagat_PARAMNUM
RMTS_REMITTANCE_PARAM.PARAMNUM%TYPE ,rthpagat_PARAMSTAT
RMTS_REMITTANCE_PARAM.PARAMSTAT%TYPE ,rthpagat_REQTELLERNO RMTS_REMITTANCE_PARAM.REQTELLERNO%TYPE
,rthpagat_REQUESTTIME RMTS_REMITTANCE_PARAM.REQUESTTIME%TYPE
,rthpagat_HOSTERRNO RMTS_REMITTANCE_PARAM.HOSTERRNO%TYPE ,rthpagat_HOSTERRMSG
RMTS_REMITTANCE_PARAM.HOSTERRMSG%TYPE ,rthpagat_GATBANK
RMTS_REMITTANCE_PARAM.VALUE1%TYPE ,rthpagat_GATEEBANK
RMTS_REMITTANCE_PARAM.VALUE2%TYPE ,rthpagat_TELLER
RMTS_REMITTANCE_PARAM.VALUE3%TYPE ,rthpagat_DATE
RMTS_REMITTANCE_PARAM.VALUE4%TYPE ,rthpagat_BM_GATBANK
RMTS_REMITTANCE_PARAM.VALUE5%TYPE ,rthpagat_BM_GATEEBANK
RMTS_REMITTANCE_PARAM.VALUE6%TYPE ,rthpagat_BM_LMTEL
RMTS_REMITTANCE_PARAM.VALUE7%TYPE ,rthpagat_BM_LMDAT
RMTS_REMITTANCE_PARAM.VALUE8%TYPE ) ;
v1 r_rthpagat_list ;
BEGIN
END ;
/
reset
package_name_list ;</pre>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p12376175614019"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b19811183754214">Input -Function/Procedure With No Parameter</strong></p>
<div class="p" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p18807117134318">In case a procedure or function does not have any parameter or argument, put () after procedure or function name while calling the same procedure or function.<pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen19435155513421">CREATE OR REPLACE PACKAGE BODY SAD.bas_lookup_misc_pkg IS
g_pkg_name CONSTANT VARCHAR2(30) := 'bas_lookup_misc_pkg';
g_func_name VARCHAR2(30);
FUNCTION func_name
RETURN VARCHAR2
IS
l_func_name VARCHAR2(100);
BEGIN
l_func_name := g_pkg_name || '.' || g_func_name;
RETURN l_func_name;
END func_name;
------------------------------------------------------------------------------
PROCEDURE insert_fnd_data_change_logs(pi_table_name IN VARCHAR2,
pi_table_key_columns IN VARCHAR2,
pi_table_key_values IN VARCHAR2,
pi_column_name IN VARCHAR2,
pi_column_change_from_value IN VARCHAR2,
pi_column_change_to_value IN VARCHAR2,
pi_op_code IN NUMBER,
pi_description IN VARCHAR2,
po_error_msg OUT VARCHAR2)
IS
BEGIN
g_func_name := 'insert_fnd_data_change_logs_t';
EXCEPTION
WHEN OTHERS THEN
po_error_msg := 'Others Exception raise in ' || func_name || ',' || SQLERRM;
END insert_fnd_data_change_logs;
END SAD.bas_lookup_misc_pkg;
/</pre>
</div>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p4733195684014"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b12061059103817">Output</strong></p>
<pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen0622183323815">CREATE
OR REPLACE FUNCTION SAD.bas_lookup_misc_pkg#func_name
RETURN VARCHAR2
PACKAGE
IS
l_func_name VARCHAR2 ( 100 ) ;
MIG_PV_VAL_DUMMY_G_PKG_NAME VARCHAR2 ( 30 ) := MIG_ORA_EXT.MIG_FN_GET_PKG_VARIABLE ( 'SAD' ,'bas_lookup_misc_pkg' ,'g_pkg_name' ) ::VARCHAR2 ( 30 ) ;
MIG_PV_VAL_DUMMY_G_FUNC_NAME VARCHAR2 ( 30 ) := MIG_ORA_EXT.MIG_FN_GET_PKG_VARIABLE ( 'SAD' ,'bas_lookup_misc_pkg' ,'g_func_name' ) ::VARCHAR2 ( 30 ) ;
BEGIN
l_func_name := MIG_PV_VAL_DUMMY_G_PKG_NAME || '.' || MIG_PV_VAL_DUMMY_G_FUNC_NAME ;
MIG_ORA_EXT.MIG_FN_SET_PKG_VARIABLE ( 'SAD','bas_lookup_misc_pkg','g_pkg_name',MIG_PV_VAL_DUMMY_G_PKG_NAME ) ;
MIG_ORA_EXT.MIG_FN_SET_PKG_VARIABLE ( 'SAD','bas_lookup_misc_pkg','g_func_name',MIG_PV_VAL_DUMMY_G_FUNC_NAME ) ;
RETURN l_func_name ;
END ;
-------------------------------------------------------------------------------------------------
CREATE
OR REPLACE PROCEDURE SAD.bas_lookup_misc_pkg#insert_fnd_data_change_logs ( pi_table_name IN VARCHAR2
,pi_table_key_columns IN VARCHAR2
,pi_table_key_values IN VARCHAR2
,pi_column_name IN VARCHAR2
,pi_column_change_from_value IN VARCHAR2
,pi_column_change_to_value IN VARCHAR2
,pi_op_code IN NUMBER
,pi_description IN VARCHAR2
,po_error_msg OUT VARCHAR2 )
PACKAGE
IS
MIG_PV_VAL_DUMMY_G_FUNC_NAME VARCHAR2 ( 30 ) := MIG_ORA_EXT.MIG_FN_GET_PKG_VARIABLE ( 'SAD' ,'bas_lookup_misc_pkg' ,'g_func_name' ) ::VARCHAR2 ( 30 ) ;
BEGIN
MIG_PV_VAL_DUMMY_G_FUNC_NAME := 'insert_fnd_data_change_logs_t' ;
MIG_ORA_EXT.MIG_FN_SET_PKG_VARIABLE ( 'SAD','bas_lookup_misc_pkg','g_pkg_name',MIG_PV_VAL_DUMMY_G_PKG_NAME ) ;
MIG_ORA_EXT.MIG_FN_SET_PKG_VARIABLE ( 'SAD','bas_lookup_misc_pkg','g_func_name',MIG_PV_VAL_DUMMY_G_FUNC_NAME ) ;
EXCEPTION
WHEN OTHERS THEN
po_error_msg := 'Others Exception raise in ' || SAD.bas_lookup_misc_pkg#func_name() || ',' || SQLERRM ;
END ;
/</pre>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p1541057194011"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b19710173244212">Input - Package Body with no procedure and functions</strong></p>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p6890721124219">In case package body does not have any logic,for example, procedures and functions, DSC needs to remove all code from the same package. The output is basically blank.</p>
<pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen2348121216439">CREATE OR REPLACE PACKAGE BODY SAD.bas_subtype_pkg IS
BEGIN
NULL;
END bas_subtype_pkg;
/</pre>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p201741718184415"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b72351445103619">Input - SUBTYPE</strong></p>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p150452711376">With the SUBTYPE statement, PL/SQL allows you to define your own subtypes or aliases of predefined datatypes, sometimes referred to as abstract datatypes.</p>
<pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen84228441379">CREATE OR REPLACE PACKAGE "SAD"."BAS_SUBTYPE_PKG" IS
SUBTYPE CURRENCY IS BAS_PRICE_LIST_T.CURRENCY%TYPE;
END bas_subtype_pkg;
/
CREATE OR REPLACE PACKAGE BODY "SAD"."BAS_SUBTYPE_PKG" IS
BEGIN
NULL;
END bas_subtype_pkg;
/
--********************************************************************
CREATE OR REPLACE PACKAGE BODY SAD.bas_lookup_misc_pkg IS
FUNCTION get_currency(pi_price_type IN NUMBER) RETURN VARCHAR2 IS
v_currency bas_subtype_pkg.currency;
BEGIN
g_func_name := 'get_currency';
FOR rec_currency IN (SELECT currency FROM sad_price_type_v WHERE price_type_code = pi_price_type)
LOOP
v_currency := rec_currency.currency;
END LOOP;
RETURN v_currency;
END get_currency;
END SAD.bas_lookup_misc_pkg;
/</pre>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p13114131974416"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b20769141123818">Output</strong></p>
<pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen2473152163813">"SAD"."BAS_SUBTYPE_PKG" package will be blank after migration.
--**********************************************************
CREATE OR REPLACE FUNCTION SAD.bas_lookup_misc_pk#get_currency(pi_price_type IN NUMBER) RETURN VARCHAR2 IS
v_currency BAS_PRICE_LIST_T.CURRENCY%TYPE;
BEGIN
g_func_name := 'get_currency';
FOR rec_currency IN (SELECT currency FROM sad_price_type_v WHERE price_type_code = pi_price_type)
LOOP
v_currency := rec_currency.currency;
END LOOP;
RETURN v_currency;
END ;
/</pre>
<div class="note" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_note2040871017395"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p9409810193912">As the SUBTYPE not supported in GaussDB, the SUBTYPE variable used needs to be replaced with the actualy type.</p>
</div></div>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p314713013382"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b163611733122613">Input - sys.dbms_job</strong></p>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p8453191572614">The DBMS_JOB package schedules and manages jobs in the job queue.</p>
<pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen61619495262">CREATE OR replace PACKAGE BODY "SAD"."EIP_HTM_INTEGRATION_PKG"
IS
PROCEDURE Greate_import_instruction_job
IS
v_jobid NUMBER;
BEGIN
IF
bas_lookup_misc_pkg.Exits_run_job('eip_htm_integration_pkg.import_instruction_job') = 'N' THEN
sys.dbms_job.Submit(job =&gt; v_jobid,
what =&gt; 'begin
eip_htm_integration_pkg.import_instruction_job;
end;',
next_date =&gt; SYSDATE);
COMMIT;
END IF;
---
END greate_import_instruction_job;
END eip_htm_integration_pkg; </pre>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p205011105384"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b19744615132715">Output</strong></p>
<pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen151609361270">CREATE OR replace PROCEDURE
sad.Eip_htm_integration_pkg#greate_import_instruction_job
IS
v_jobid NUMBER;
BEGIN
IF Bas_lookup_misc_pkg#exits_run_job (
'eip_htm_integration_pkg.import_instruction_job') = 'N' THEN
dbms_job.Submit(job =&gt; v_jobid,
what =&gt; 'begin
eip_htm_integration_pkg.import_instruction_job;
end;',
next_date =&gt; SYSDATE);
/* COMMIT; */
NULL;
END IF;
---
END; </pre>
<div class="note" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_note41304112816"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p1513018110289">Remove the SYS schema while calling the package.</p>
</div></div>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p18110175063817"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b838020369374">Input - Procedure/Function variable</strong></p>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p11639104317376">The NULL constraint is not supported on variable declaration by Gauss, so it is recomended to comment the NULL keyword.</p>
<pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen1681618571375">CREATE OR REPLACE PACKAGE BODY SAD.sad_lookup_contract_pkg IS
FUNCTION CONTRACT_DISTRIBUTE_STATUS_S2(PI_CONTRACT_NUMBER IN VARCHAR2)
RETURN VARCHAR2 IS
L_CONTRACT_DISTRIBUTE_STATUS VARCHAR2(10) NULL;
BEGIN
IF CUR_CONTRACT.CONTRACT_STATUS = 0 THEN
L_CONTRACT_DISTRIBUTE_STATUS := 'Cancel';
ELSE
L_CONTRACT_DISTRIBUTE_STATUS := 'Active';
END IF;
RETURN L_CONTRACT_DISTRIBUTE_STATUS;
EXCEPTION
WHEN OTHERS THEN
L_CONTRACT_DISTRIBUTE_STATUS := NULL;
END CONTRACT_DISTRIBUTE_STATUS_S2;
END sad_lookup_contract_pkg;
/</pre>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p911657172716"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b25271704466">Output</strong></p>
<pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen136261842103817">CREATE OR replace FUNCTION sad_lookup_contract_pkg.Contract_distribute_status_s2 ( pi_contract_number IN VARCHAR2 )
RETURN VARCHAR2
IS
l_contract_distribute_statusvarchar2 ( 10 )
/* NULL */
;
BEGIN
IF cur_contract.contract_status = 0 THEN
l_contract_distribute_status := 'Cancel' ;
ELSE
l_contract_distribute_status := 'Active' ;
END IF ;
RETURN l_contract_distribute_status ;
EXCEPTION
WHEN OTHERS THEN
l_contract_distribute_status := NULL ;
END ;/</pre>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p11871222281"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b081913385312">Input - Configuration parameter addPackageNameList = true</strong></p>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p1317010521637">Hint to access objects from specific schema by system.</p>
<pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen0489671841">CREATE OR REPLACE PACKAGE BODY IC_STAGE.PKG_REVN_ARPU
AS
-----------
-----------
END PKG_REVN_ARPU;
/</pre>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p354611933814"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b1128612277415">Output</strong></p>
<pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen1236918341343">SET package_name_list = 'PKG_REVN_ARPU' ;
--------------
--------------
reset package_name_list ;</pre>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p16387162215419"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b1116814588413">Input - </strong><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b771778161">Configuration parameter addPackageNameList = false</strong></p>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p17802132217412">Hint to access objects from specific schema by system.</p>
<pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen67732093720">CREATE OR REPLACE PACKAGE BODY IC_STAGE.PKG_REVN_ARPU
AS
-----------
-----------
END PKG_REVN_ARPU;
/</pre>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p93771056719"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b1344512300720">Output</strong></p>
<pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen270015461773">SET SEARCH_PATH=PKG_REVN_ARPU,PUBLIC;</pre>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p1516016613719"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b2083142212151">Input -PACKAGE</strong></p>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p1248614251151">Hint that procedure and functions belongs to a package.</p>
<pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen14750340131518">CREATE OR REPLACE PACKAGE BODY SAD.sad_lookup_contract_pkg
IS
FUNCTION CONTRACT_DISTRIBUTE_STATUS_S2(PI_CONTRACT_NUMBER IN VARCHAR2)
RETURN VARCHAR2 IS
L_CONTRACT_DISTRIBUTE_STATUS VARCHAR2(10) ;
BEGIN
IF CUR_CONTRACT.CONTRACT_STATUS = 0 THEN
L_CONTRACT_DISTRIBUTE_STATUS := 'Cancel';
ELSE
L_CONTRACT_DISTRIBUTE_STATUS := 'Active';
END IF;
RETURN L_CONTRACT_DISTRIBUTE_STATUS;
EXCEPTION
WHEN OTHERS THEN
L_CONTRACT_DISTRIBUTE_STATUS := NULL;
END CONTRACT_DISTRIBUTE_STATUS_S2;
END sad_lookup_contract_pkg;
/</pre>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p17379232471"><strong id="EN-US_TOPIC_0000001188362596__b1838294544">Output</strong></p>
<pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen22982817161">CREATE OR replace FUNCTION sad_lookup_contract_pkg.Contract_distribute_status_s2 ( pi_contract_number IN VARCHAR2 )
RETURN VARCHAR2
PACKAGE
IS
l_contract_distribute_statusvarchar2 ( 10 ) ;
BEGIN
IF cur_contract.contract_status = 0 THEN
l_contract_distribute_status := 'Cancel' ;
ELSE
l_contract_distribute_status := 'Active' ;
END IF ;
RETURN l_contract_distribute_status ;
EXCEPTION
WHEN OTHERS THEN
l_contract_distribute_status := NULL ;
END ;
/</pre>
<div class="note" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_note1923716265162"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p1323832661613">You need to put the PACKAGE keyword while creating any procedure and function in front of the IS/AS statement.</p>
</div></div>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p16849832571"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b1324511814254">Input -Nested Procedure</strong></p>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p1836631792517">Creating a procedure inside a procedure is known as a nested procedure. The nested procedure is private and belongs to the parent procedure.</p>
<pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen109310389251">CREATE OR REPLACE PROCEDURE refresh_sw_product_amount(pi_stage_id IN NUMBER)
IS
v_product_amount sad_sw_product_amount_t.product_amount%TYPE;
FUNCTION get_sw_no
RETURN VARCHAR2
IS
v_xh NUMBER;
BEGIN
BEGIN
SELECT nvl(to_number(substrb(MAX(sw_no), 3, 4)), 0)
INTO v_xh
FROM sad.sad_sw_product_amount_t
WHERE pi_stage_id = pi_stage_id;
EXCEPTION WHEN OTHERS THEN
v_xh := 0;
END;
RETURN 'SW' || lpad(to_char(v_xh + 1), 4, '0') || 'Y';
END get_sw_no;
BEGIN
FOR rec_pu IN (SELECT t.*, sh.header_id
FROM asms.ht_stages t, asms.ht, sad.sad_distribution_headers_t sh
WHERE t.hth = ht.hth
AND sh.contract_number = t.hth
AND sh.stage_id = t.stage_id
AND ht.sw_track_flag = 'Y'
AND to_char(t.category_id) IN
(SELECT code
FROM asms.asms_lookup_values
WHERE type_code = 'CATEGORY_ID_EQUIPMENT'
AND enabled_flag = 'Y')
AND nvl(t.status, '-1') &lt;&gt; '0'
AND t.stage_id = pi_stage_id)
LOOP
SELECT nvl(SUM(nvl(product_amount, 0)), 0)
INTO v_product_amount
FROM sad.sad_products_t sp
WHERE sp.header_id = rec_pu.header_id
AND sp.sw_flag = 'Y';
END LOOP;
END refresh_sw_product_amount;</pre>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p147581441172412"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b6150143618274">Output</strong></p>
<pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen11706559162710">CREATE OR REPLACE FUNCTION get_sw_no(pi_stage_id IN NUMBER)
RETURN VARCHAR2 IS
v_xh NUMBER;
BEGIN
BEGIN
SELECT nvl(to_number(substrb(MAX(sw_no), 3, 4)), 0)
INTO v_xh
FROM sad.sad_sw_product_amount_t
WHERE pi_stage_id = pi_stage_id;
EXCEPTION WHEN OTHERS THEN
v_xh := 0;
END;
RETURN 'SW' || lpad(to_char(v_xh + 1), 4, '0') || 'Y';
END ;
/
--*****************************************************************************
CREATE OR REPLACE PROCEDURE refresh_sw_product_amount(pi_stage_id IN NUMBER)
IS
v_product_amount sad_sw_product_amount_t.product_amount%TYPE;
BEGIN
FOR rec_pu IN (SELECT t.*, sh.header_id
FROM asms.ht_stages t, asms.ht, sad.sad_distribution_headers_t sh
WHERE t.hth = ht.hth
AND sh.contract_number = t.hth
AND sh.stage_id = t.stage_id
AND ht.sw_track_flag = 'Y'
AND to_char(t.category_id) IN
(SELECT code
FROM asms.asms_lookup_values
WHERE type_code = 'CATEGORY_ID_EQUIPMENT'
AND enabled_flag = 'Y')
AND nvl(t.status, '-1') &lt;&gt; '0'
AND t.stage_id = pi_stage_id)
LOOP
SELECT nvl(SUM(nvl(product_amount, 0)), 0)
INTO v_product_amount
FROM sad.sad_products_t sp
WHERE sp.header_id = rec_pu.header_id
AND sp.sw_flag = 'Y';
END LOOP;
END;
/</pre>
<div class="note" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_note535172462817"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p1857819345288">When nested procedures/functions are implemented, the package variables in all procedures/functions must be processed.</p>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p457983422819">After migrating sub-procedures/functions, migrate the parent procedure/function.</p>
</div></div>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p19914529132511"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b837673575310">if pkgSchemaNaming = false</strong></p>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p17255183755310">if <strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b15773141293917">pkgSchemaNaming</strong> is set to<strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b165781773917"> false</strong>, PL RECORD migration should not have package name in the type name as its schema.</p>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p1433514173544"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b1649712395414">Input</strong></p>
<pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen9516204925310">CREATE OR REPLACE PACKAGE BODY SAD.sad_dml_product_pkg IS
PROCEDURE save_sad_product_line_amount(pi_stage_id IN NUMBER,
pi_product_line_code IN VARCHAR2,
po_error_msg OUT VARCHAR2) IS
TYPE t_line IS RECORD(
product_line VARCHAR2(30),
product_amount NUMBER);
TYPE tab_line IS TABLE OF t_line INDEX BY BINARY_INTEGER;
rec_line tab_line;
v_product_line_arr VARCHAR2(5000);
v_product_line VARCHAR2(30) ;
v_count INTEGER;
v_start INTEGER;
v_pos INTEGER;
BEGIN
v_count := 0;
v_start := 1;
v_product_line_arr := pi_product_line_code;
LOOP
v_pos := instr(v_product_line_arr, ',', v_start);
IF v_pos &lt;= 0
THEN
EXIT;
END IF;
v_product_line := substr(v_product_line_arr, v_start, v_pos - 1);
v_count := v_count + 1;
rec_line(v_count).product_line := v_product_line;
rec_line(v_count).product_amount := 0;
v_product_line_arr := substr(v_product_line_arr, v_pos + 1, length(v_product_line_arr));
END LOOP;
FOR v_count IN 1 .. rec_line.count
LOOP
UPDATE sad_product_line_amount_t spl
SET spl.product_line_amount = rec_line(v_count).product_amount
WHERE spl.stage_id = pi_stage_id
AND spl.product_line_code = rec_line(v_count).product_line;
IF SQL%NOTFOUND
THEN
INSERT INTO sad_product_line_amount_t
(stage_id, product_line_code, product_line_amount)
VALUES (pi_stage_id, rec_line(v_count).product_line, rec_line(v_count).product_amount);
END IF;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
po_error_msg := 'Others Exception raise in ' || func_name || ',' || SQLERRM;
END save_sad_product_line_amount;
END sad_dml_product_pkg;
/</pre>
<p id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_p1221317278538"><strong id="EN-US_TOPIC_0000001188362596__en-us_topic_0237712466_b6995101215546">Output</strong></p>
<pre class="screen" id="EN-US_TOPIC_0000001188362596__en-us_topic_0238518405_en-us_topic_0237362344_en-us_topic_0202727116_screen87651230155414">CREATE TYPE SAD.sad_dml_product_pkg#t_line AS
( product_line VARCHAR2 ( 30 )
, product_amount NUMBER ) ;
CREATE OR REPLACE PROCEDURE SAD.sad_dml_product_pkg#save_sad_product_line_amount
( pi_stage_id IN NUMBER
, pi_product_line_code IN VARCHAR2
, po_error_msg OUT VARCHAR2 )
PACKAGE
IS
TYPE tab_line IS VARRAY ( 10240 ) OF SAD.sad_dml_product_pkg#t_line ;
rec_line tab_line ;
v_product_line_arr VARCHAR2 ( 5000 ) ;
v_product_line VARCHAR2 ( 30 ) ;
v_count INTEGER ;
v_start INTEGER ;
v_pos INTEGER ;
BEGIN
v_count := 0 ;
v_start := 1 ;
v_product_line_arr := pi_product_line_code ;
LOOP
v_pos := instr( v_product_line_arr ,',' ,v_start ) ;
IF v_pos &lt;= 0 THEN
EXIT ;
END IF ;
v_product_line := SUBSTR( v_product_line_arr ,v_start ,v_pos - 1 ) ;
v_count := v_count + 1 ;
rec_line ( v_count ).product_line := v_product_line ;
rec_line ( v_count ).product_amount := 0 ;
v_product_line_arr := SUBSTR( v_product_line_arr ,v_pos + 1 ,length( v_product_line_arr ) ) ;
END LOOP ;
FOR v_count IN 1.. rec_line.count
LOOP
UPDATE sad_product_line_amount_t spl
SET spl.product_line_amount = rec_line ( v_count ).product_amount
WHERE spl.stage_id = pi_stage_id
AND spl.product_line_code = rec_line ( v_count ).product_line ;
IF SQL%NOTFOUND THEN
INSERT INTO sad_product_line_amount_t
( stage_id, product_line_code, product_line_amount )
VALUES ( pi_stage_id, rec_line ( v_count ).product_line
, rec_line ( v_count ).product_amount ) ;
END IF ;
END LOOP ;
EXCEPTION
WHEN OTHERS THEN
po_error_msg := 'Others Exception raise in ' || func_name || ',' || SQLERRM ;
END ;
/</pre>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_mt_0156.html">PL/SQL Packages</a></div>
</div>
</div>