Oracle uses the transform function for dynamic row-to-column conversion of large batches of data (Code tutorial), oracle.pdf

Source: Internet
Author: User

Oracle uses the transform function for dynamic row-to-column conversion of large batches of data (Code tutorial), oracle.pdf

The company's business requirements require dynamic row-to-Column Analysis of a batch of data in large batches, and subqueries cannot be used in the exist function in, there is a way to achieve this through dynamic SQL concatenation. After finding a method on the Internet for a long time, I did not find a specific method, so I tried to implement it myself. The specific method is as follows.

Because dynamic row-to-column conversion is required, you must first use the wm_concat (distinct () function to identify the column name separately, and then use dbms_lob.substr () to convert the clob field to a string. Then the column names are dynamically spliced for query. You can create a view to store the query results and directly query the expected table. The specific code is as follows:

PROCEDURE P_FXJG AS v_LM VARCHAR2 (2000); vs_ SQL varchar2 (6000); vs_sql1 varchar2 (6000); BEGIN vs_sql1: = 'insert INTO LS_TEMP select partition (wm_concat (distinct (sf ))) from B _CLB a'; execute immediate vs_sql1; select sfbm into V_LM FROM LS_TEMP; vs_ SQL: = 'create or replace view V_FXJG as select * from (select. YH,. MC,. LX "BZ",. SF,. JG from B _CLB a) terminate (sum (JG) for SF in ('| V_LM |') '; execute immediate vs_ SQL; END;

Related Article

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.