A stored procedure that counts the annual payroll of an irregular column

Source: Internet
Author: User
Tags end insert modify sql
Stored Procedures | statistics
This stored procedure successfully implements row and column conversion statistics

The salary data is the vertical table, that is, one employee's salary corresponds to the record of several salary columns

Create or Replace procedure PRC_RS_GZNDBB (p_table in varchar2) is
/*===================================================================================================
Name: PRC_RS_GZNDBB (Procedure)
Parameters: Incoming: p_table varchar2
Call: Prc_yd_shtztjyh return:
Function: Statistic Employee Payroll Annual Report
Back: Insert the statistic results into the p_table table
Author:
Written Time: 2005-2-21
Modify Person:
Modify Content:
Modified time:
=====================================================================================================*/
V_lmmc varchar2 (20);--Column name
V_sql VARCHAR2 (1000);
--Define a cursor for a payroll column
Cursor CUR_LMMC is
SELECT DISTINCT LMMC
From TMP_GZTJLSB;
Begin
--Defining dynamic SQL
v_sql:= ' select Rydm,xm ';
--traverse the payroll and spell the inserted SQL
For Cur_lmmc_rec in Cur_lmmc loop
V_LMMC:=CUR_LMMC_REC.LMMC;
v_sql:=v_sql| | ', ' | | SUM (decode (LMMC ' | |), ', ' | | v_lmmc| | ', je ') ' | | ' '|| V_LMMC;
End Loop;
v_sql:=v_sql| | ' from TMP_GZTJLSB GROUP by RYDM,XM ';
Execute immediate ' insert INTO ' | | p_table| | ' '|| V_sql;
Commit
End PRC_RS_GZNDBB;



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.