1动态SQL,嵌套游标,INSTR,SendMailPROCEDURE send_detail_mail(
  2动态SQL,嵌套游标,INSTR,SendMail        p_single_user   IN   VARCHAR2,
  3动态SQL,嵌套游标,INSTR,SendMail        p_admin_user    IN   VARCHAR2,
  4动态SQL,嵌套游标,INSTR,SendMail        p_current_day   IN   DATE )
  5动态SQL,嵌套游标,INSTR,SendMail    IS
  6动态SQL,嵌套游标,INSTR,SendMail        conn                         UTL_SMTP.connection;
  7动态SQL,嵌套游标,INSTR,SendMail        v_current_day                DATE;
  8动态SQL,嵌套游标,INSTR,SendMail        v_html_header                VARCHAR28000 );
  9动态SQL,嵌套游标,INSTR,SendMail        v_html_body                  VARCHAR28000 );
 10动态SQL,嵌套游标,INSTR,SendMail        v_html_tail                  VARCHAR22000 );
 11动态SQL,嵌套游标,INSTR,SendMail        v_mail_suject                VARCHAR2255 );
 12动态SQL,嵌套游标,INSTR,SendMail        v_user_name                  VARCHAR260 );
 13动态SQL,嵌套游标,INSTR,SendMail        v_user_nick_name             VARCHAR260 );
 14动态SQL,嵌套游标,INSTR,SendMail        v_user_mail_address          VARCHAR2100 );
 15动态SQL,嵌套游标,INSTR,SendMail        v_html_log                   VARCHAR21000 );
 16动态SQL,嵌套游标,INSTR,SendMail        v_ro_site_group              VARCHAR2100 );
 17动态SQL,嵌套游标,INSTR,SendMail        v_ns_site_group              VARCHAR2100 );
 18动态SQL,嵌套游标,INSTR,SendMail        v_product_line_group         VARCHAR2200 );
 19动态SQL,嵌套游标,INSTR,SendMail        v_user_group                 VARCHAR2200 );
 20动态SQL,嵌套游标,INSTR,SendMail        v_get_mail_data_sql_string   VARCHAR2500 );
 21动态SQL,嵌套游标,INSTR,SendMail        v_ro_site                    VARCHAR2100 );
 22动态SQL,嵌套游标,INSTR,SendMail        v_ns_site                    VARCHAR2100 );
 23动态SQL,嵌套游标,INSTR,SendMail        v_mail_data                  CLOB;
 24动态SQL,嵌套游标,INSTR,SendMail        v_get_mail_data_sql          VARCHAR2500 );
 25动态SQL,嵌套游标,INSTR,SendMail        v_send_mail_sql              VARCHAR2500 );
 26动态SQL,嵌套游标,INSTR,SendMail    BEGIN
 27动态SQL,嵌套游标,INSTR,SendMail        ----initial v_currentday
 28动态SQL,嵌套游标,INSTR,SendMail        v_current_day := NVL( TRUNC( p_current_day ), TRUNC( SYSDATE - 1 ));
 29动态SQL,嵌套游标,INSTR,SendMail        v_html_header := '';
 30动态SQL,嵌套游标,INSTR,SendMail        v_html_tail :=
 31动态SQL,嵌套游标,INSTR,SendMail               '<ul><font class="inf">'
 32动态SQL,嵌套游标,INSTR,SendMail            || '<li>slow moving ratio =  over 15 days inventory qty / total in warehouse inventory qty(not include MIT)</li>'
 33动态SQL,嵌套游标,INSTR,SendMail            || '<li>ADS days (Historic) =inventory qty*30/ prior 30 ship qty</li>'
 34动态SQL,嵌套游标,INSTR,SendMail            || '<li>ADS days (Forecast)=inventory qty*28/ next 4-week forecast </li>'
 35动态SQL,嵌套游标,INSTR,SendMail            || '<li>NFP : No Forecast Provided or available on Demand Forecast System</li>'
 36动态SQL,嵌套游标,INSTR,SendMail            || '<li>Resource : EIS/DFS</li>'
 37动态SQL,嵌套游标,INSTR,SendMail            || '<li>For BQP business model concern, we put BQP finish goods in service warehouse in "Non-Saleable" section on this report</li></ul><br>'
 38动态SQL,嵌套游标,INSTR,SendMail            || ' <FONT face=Arial color=#000080 size=2><STRONG>Information Support Department</STRONG></FONT><br>'
 39动态SQL,嵌套游标,INSTR,SendMail            || ' <FONT face=Arial color=#000080 size=2><STRONG>'
 40动态SQL,嵌套游标,INSTR,SendMail            || TO_CHAR( SYSDATE, 'YYYY-MM-DD' )
 41动态SQL,嵌套游标,INSTR,SendMail            || '</STRONG></FONT>';
 42动态SQL,嵌套游标,INSTR,SendMail        v_mail_suject :=
 43动态SQL,嵌套游标,INSTR,SendMail                       'Inventory Alert : Over-aged inventory-Action Required';
 44动态SQL,嵌套游标,INSTR,SendMail        v_html_log := '';
 45动态SQL,嵌套游标,INSTR,SendMail 
 46动态SQL,嵌套游标,INSTR,SendMail        --send mail by mail group
 47动态SQL,嵌套游标,INSTR,SendMail        DECLARE
 48动态SQL,嵌套游标,INSTR,SendMail            CURSOR cur_detailed_group
 49动态SQL,嵌套游标,INSTR,SendMail            IS
 50动态SQL,嵌套游标,INSTR,SendMail                SELECT '''' || REPLACE( ro_site,
 51动态SQL,嵌套游标,INSTR,SendMail                                        ',',
 52动态SQL,嵌套游标,INSTR,SendMail                                        ''',''' ) || '''',
 53动态SQL,嵌套游标,INSTR,SendMail                       '''' || REPLACE( ns_site,
 54动态SQL,嵌套游标,INSTR,SendMail                                        ',',
 55动态SQL,嵌套游标,INSTR,SendMail                                        ''',''' ) || '''',
 56动态SQL,嵌套游标,INSTR,SendMail                       '''' || REPLACE( product_line,
 57动态SQL,嵌套游标,INSTR,SendMail                                        ',',
 58动态SQL,嵌套游标,INSTR,SendMail                                        ''',''' ) || '''',
 59动态SQL,嵌套游标,INSTR,SendMail                       '''' || REPLACEuser_id,
 60动态SQL,嵌套游标,INSTR,SendMail                                        ',',
 61动态SQL,嵌套游标,INSTR,SendMail                                        ''',''' ) || ''''
 62动态SQL,嵌套游标,INSTR,SendMail                  FROM eis_hq_invhl_mail_group
 63动态SQL,嵌套游标,INSTR,SendMail                 WHERE report_type = 'Detailed';
 64动态SQL,嵌套游标,INSTR,SendMail        BEGIN
 65动态SQL,嵌套游标,INSTR,SendMail            OPEN cur_detailed_group;
 66动态SQL,嵌套游标,INSTR,SendMail 
 67动态SQL,嵌套游标,INSTR,SendMail            LOOP
 68动态SQL,嵌套游标,INSTR,SendMail                FETCH cur_detailed_group
 69动态SQL,嵌套游标,INSTR,SendMail                 INTO v_ro_site_group, v_ns_site_group, v_product_line_group,
 70动态SQL,嵌套游标,INSTR,SendMail                      v_user_group;
 71动态SQL,嵌套游标,INSTR,SendMail 
 72动态SQL,嵌套游标,INSTR,SendMail                EXIT WHEN cur_detailed_group%NOTFOUND;
 73动态SQL,嵌套游标,INSTR,SendMail 
 74动态SQL,嵌套游标,INSTR,SendMail                --get ro_site, ns_site
 75动态SQL,嵌套游标,INSTR,SendMail                DECLARE
 76动态SQL,嵌套游标,INSTR,SendMail                    CURSOR cur_ns_site
 77动态SQL,嵌套游标,INSTR,SendMail                    IS
 78动态SQL,嵌套游标,INSTR,SendMail                        SELECT DISTINCT ro_site, ns_site
 79动态SQL,嵌套游标,INSTR,SendMail                                   FROM eis_hq_invhl_mail_data
 80动态SQL,嵌套游标,INSTR,SendMail                                  WHERE report_type = 'Detailed'
 81动态SQL,嵌套游标,INSTR,SendMail                                    AND INSTR( v_ns_site_group, ns_site ) > 0;
 82动态SQL,嵌套游标,INSTR,SendMail                BEGIN
 83动态SQL,嵌套游标,INSTR,SendMail                    OPEN cur_ns_site;
 84动态SQL,嵌套游标,INSTR,SendMail 
 85动态SQL,嵌套游标,INSTR,SendMail                     --EXECUTE IMMEDIATE v_sql;
 86动态SQL,嵌套游标,INSTR,SendMail                     --BEGIN
 87动态SQL,嵌套游标,INSTR,SendMail                    -- OPEN cur_mail_site;
 88动态SQL,嵌套游标,INSTR,SendMail                    LOOP
 89动态SQL,嵌套游标,INSTR,SendMail                        FETCH cur_ns_site
 90动态SQL,嵌套游标,INSTR,SendMail                         INTO v_ro_site, v_ns_site;
 91动态SQL,嵌套游标,INSTR,SendMail 
 92动态SQL,嵌套游标,INSTR,SendMail                        EXIT WHEN cur_ns_site%NOTFOUND;
 93动态SQL,嵌套游标,INSTR,SendMail                         -- DBMS_OUTPUT.put_line( v_ro_site || ' ----------- '
 94动态SQL,嵌套游标,INSTR,SendMail                        --                        || v_ns_site );
 95动态SQL,嵌套游标,INSTR,SendMail                          --Saleable
 96动态SQL,嵌套游标,INSTR,SendMail                          --title
 97动态SQL,嵌套游标,INSTR,SendMail                        v_get_mail_data_sql :=
 98动态SQL,嵌套游标,INSTR,SendMail                               'select STRING_AGGREGATE_FUN(mail_data) from eis_hq_invhl_mail_data where ns_site = '''
 99动态SQL,嵌套游标,INSTR,SendMail                            || v_ns_site
100动态SQL,嵌套游标,INSTR,SendMail                            || '''and wh_type = ''Saleable''and report_type = ''Detailed'' and product_line in ('
101动态SQL,嵌套游标,INSTR,SendMail                            || v_product_line_group
102动态SQL,嵌套游标,INSTR,SendMail                            || ') group by ns_site';
103动态SQL,嵌套游标,INSTR,SendMail 
104动态SQL,嵌套游标,INSTR,SendMail                        --DBMS_OUTPUT.put_line( v_product_line_group );
105动态SQL,嵌套游标,INSTR,SendMail                        --DBMS_OUTPUT.put_line( v_sql );
106动态SQL,嵌套游标,INSTR,SendMail                        EXECUTE IMMEDIATE v_get_mail_data_sql
107动态SQL,嵌套游标,INSTR,SendMail                                     INTO v_mail_data;
108动态SQL,嵌套游标,INSTR,SendMail                    --Non-Saleable
109动态SQL,嵌套游标,INSTR,SendMail                    --title
110动态SQL,嵌套游标,INSTR,SendMail 
111动态SQL,嵌套游标,INSTR,SendMail                    -- DBMS_OUTPUT.put_line( v_product_line );
112动态SQL,嵌套游标,INSTR,SendMail                    END LOOP;
113动态SQL,嵌套游标,INSTR,SendMail                --DBMS_OUTPUT.put_line( v_ro_site || ' ----------- ' || v_ns_site );
114动态SQL,嵌套游标,INSTR,SendMail                END;
115动态SQL,嵌套游标,INSTR,SendMail 
116动态SQL,嵌套游标,INSTR,SendMail                           
117动态SQL,嵌套游标,INSTR,SendMail                DECLARE
118动态SQL,嵌套游标,INSTR,SendMail                    CURSOR cur_send_mail
119动态SQL,嵌套游标,INSTR,SendMail                    IS
120动态SQL,嵌套游标,INSTR,SendMail                        SELECT DISTINCT email, attribute2
121动态SQL,嵌套游标,INSTR,SendMail                                   FROM wscuser
122动态SQL,嵌套游标,INSTR,SendMail                                  WHERE INSTR( v_user_group, userid ) > 0;
123动态SQL,嵌套游标,INSTR,SendMail                BEGIN
124动态SQL,嵌套游标,INSTR,SendMail                    OPEN cur_send_mail;
125动态SQL,嵌套游标,INSTR,SendMail 
126动态SQL,嵌套游标,INSTR,SendMail                    LOOP
127动态SQL,嵌套游标,INSTR,SendMail                        FETCH cur_send_mail
128动态SQL,嵌套游标,INSTR,SendMail                         INTO v_user_mail_address, v_user_nick_name;
129动态SQL,嵌套游标,INSTR,SendMail 
130动态SQL,嵌套游标,INSTR,SendMail                        EXIT WHEN cur_send_mail%NOTFOUND;
131动态SQL,嵌套游标,INSTR,SendMail                        conn :=
132动态SQL,嵌套游标,INSTR,SendMail                            eis_mail_pkg.begin_mail
133动态SQL,嵌套游标,INSTR,SendMail                                     ( sender =>           'e@163.com',
134动态SQL,嵌套游标,INSTR,SendMail                                       recipients =>       'Sammy@163.com',
135动态SQL,嵌套游标,INSTR,SendMail                                       subject =>          'EIS INVHL',
136动态SQL,嵌套游标,INSTR,SendMail                                       mime_type =>        'text/html;charset=utf-8' );
137动态SQL,嵌套游标,INSTR,SendMail                        eis_mail_pkg.write_mb_text( conn, v_html_tail );
138动态SQL,嵌套游标,INSTR,SendMail                        eis_mail_pkg.end_mail( conn );
139动态SQL,嵌套游标,INSTR,SendMail                    END LOOP;
140动态SQL,嵌套游标,INSTR,SendMail                END;
141动态SQL,嵌套游标,INSTR,SendMail            END LOOP;
142动态SQL,嵌套游标,INSTR,SendMail        END;
143动态SQL,嵌套游标,INSTR,SendMail    END;
144动态SQL,嵌套游标,INSTR,SendMail
145动态SQL,嵌套游标,INSTR,SendMail

相关文章: