Python: How to Sort SQL statements in a text file? -


The output given below is from Oracle; Where it creates a "Create table" statement using the supply package, I feed them in the Pathon Duff tool HTML IDM, which uses Fleifib under the cover. There are several "change table obstruction" orders in each table, which add different obstacles.

The problem is that there is no explicit command of the "Optical Table" command, and instruct me to generate the output file again, before I run the comparison, I need help in doing this is; Using the ideal dragon, SED or awk.

The rule will be followed by a "Create a table" with each row, as long as "Add a fixed point" containing the next line "Create table"

sort each row

This is a sample of my production Create the table T1 (BOOK_ID number not NULL enabled, LOCATION_ID number is NULL enabled, NAME VARCHAR2 (255) No NULL enabled, LEGAL_ENTITY VARCHAR2 (255) No zero enabled, status chain (1) to enable the tap); Optional Table T1 Add Insert T1_CHK_1 Check (Status 'A', 'I', 'T')) enabled; Add optional T1 T1 contract T1_PK primary key (BOOK_ID) enabled; Optional Table T1 Add Contract T1_AK_1 Unique (NAME) enabled; Optional Table T1 Add Insert T1_FK_1 Foreign Key (LOCATION_ID) Reference T6 (LOCATION_ID) enabled; Create table T2 (BUCKET_ID NUMBER zero not enabled, DATA_LOAD_SESSION_ID NUMBER, IS_LOCKED CHAR (1) tap enabled, LOCK_DATE_TIME DATE); Optional Table T2 Add Merge CKC_IS_LOCKED_BUCKET check ('T', 'F' IS_LOCKED) enabled; Add optional table T2 to contract T2_PK primary key (BUCKET_ID) enabled; Add table T2 barrier T2_FK_2 foreign key (RRDB_STAGING_TABLE_ID) to enable reference T4 (RRDB_STAGING_TABLE_ID); Create table T3 (, VALUE_DATE DATE NODE_ID number, RESULT_UID VARCHAR2 (255), LATEST_EOD_SING_VAL_RESULT_ID number not enabled NULL) change table T3 Add barrier T3_PK primary key (VALUE_DATE, NODE_ID, RESULT_UID) enabled;

desired product: the only difference is "Add barrier" lines

  create table T1 (BOOK_ID number not NULL enabled order, LOCATION_ID number is not Void enabled, named VARCHAR2 (255) Zero enabled, legal desired VARCHAR2 (255) zero enabled, position order (1) to enable zero); Optional Table T1 Add Contract T1_AK_1 Unique (NAME) enabled; Optional Table T1 Add Insert T1_CHK_1 Check (Status 'A', 'I', 'T')) enabled; Optional Table T1 Add Insert T1_FK_1 Foreign Key (LOCATION_ID) Reference T6 (LOCATION_ID) enabled; Add optional T1 T1 contract T1_PK primary key (BOOK_ID) enabled; Create table T2 (BUCKET_ID NUMBER zero not enabled, DATA_LOAD_SESSION_ID NUMBER, IS_LOCKED CHAR (1) tap enabled, LOCK_DATE_TIME DATE); Optional Table T2 Add Merge CKC_IS_LOCKED_BUCKET check ('T', 'F' IS_LOCKED) enabled; Add table T2 barrier T2_FK_2 foreign key (RRDB_STAGING_TABLE_ID) to enable reference T4 (RRDB_STAGING_TABLE_ID); Add optional table T2 to contract T2_PK primary key (BUCKET_ID) enabled; Create table T3 (, VALUE_DATE DATE NODE_ID number, RESULT_UID VARCHAR2 (255), LATEST_EOD_SING_VAL_RESULT_ID number not enabled NULL) change table T3 Add barrier T3_PK primary key (VALUE_DATE, NODE_ID, RESULT_UID) enabled; "Text" itemprop = "text"> 

After all this loads for a string, then split up on "," of SQL commands Loop array to create an array and create a new sorted array. Send with CREATE TABLE bits and slice ALTER table statement in a separate list. Type () expand it to change list and result array. Your work is done, '; \ N'.join (result_array) + ';. '


Comments