Oracle gets clean, built-in DDL statements with no other storage, tablespace, segment properties

Source: Internet
Author: User

A colleague in the morning information how to get to the build table statement and is not with storage that kind of SQL.
Oracle provides itself with a function dbms_metadata. GET_DDL, but the built-in statement contains properties for storage, table space, and some other segments.

See this obtained DDL statement and want to get the build statement by using an Oracle function to intercept it.

The idea is:
1. Get the Build Table statement ABC by GET_DDL
2. Replace the Pctfree ' in ABC with '; '
3. Calculate '; ' The location
4. Use substr to intercept ABC, from the beginning to '; ' The length

SQL is as follows:

SELECTSUBSTR (REPLACE(Dbms_metadata. GET_DDL ('TABLE','SALES','SH'),                      'PCTFREE',                      ';'),              1, INSTR (REPLACE(Dbms_metadata. GET_DDL ('TABLE','SALES','SH'),                            'PCTFREE',                            ';'),                    ';',                    1))   fromDUAL;

At first I did think that the problem had been solved,

However, when the statement contains indexed properties, there will be problems, because the index itself has pctfree and other related properties, so the interception when the direct interception of the wrong,

Finally no way, or honestly use the function to solve it.

Ideas:
1. Set properties for closing storage, table spaces, and some other segments first
2. Use GET_DDL to get the build statement
3. Finally do some small processing

The functions are as follows:

CREATE OR REPLACE FUNCTIONFUN_GET_TABLE_DDL (P_schemainch VARCHAR2, P_table_nameinch VARCHAR2) RETURNClob isV_clob CLOB;BEGINDbms_metadata. Set_transform_param (Dbms_metadata. Session_transform,'STORAGE', FALSE); Dbms_metadata. Set_transform_param (Dbms_metadata. Session_transform,'tablespace', FALSE); Dbms_metadata. Set_transform_param (Dbms_metadata. Session_transform,'segment_attributes', FALSE); SELECTDbms_metadata. GET_DDL ('TABLE', P_table_name, P_schema) intoV_clob fromDUAL; V_clob:= REPLACE(V_clob,'"'); IFINSTR (V_clob,'PRIMARY KEY',1,1)<> 0  ThenV_clob:= REPLACE(V_clob,';',');'); END IF; RETURNV_clob; EXCEPTION whenOTHERS ThenRAISE;END;

Use

Oracle gets clean, built-in DDL statements with no other storage, tablespace, segment properties

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.