Hello,
I'm trying to take this sql script string and break it up into column rows to start. We are scripting out the sql from oracle but we want to create scripts that are formatted a specific way.
CREATE TABLE "TEMP" ("TEMPID" NUMBER(7,0), "TESTID" NUMBER(6,0), "TYPE" VARCHAR2(5), "STARTDT" DATE, "SOURCE" VARCHAR2(5), "TITLE" VARCHAR2(6), CONSTRAINT "TEMP_PK" PRIMARY KEY ("TEMPID") ENABLE, CONSTRAINT "TEMP_FK" FOREIGN KEY ("KEYID") REFERENCES "KEY" ("ID") ENABLE) ;
Output:
TABNm COLNm COLType
TEMP TEMPID NUMBER(7,0)
TEMP TESTID NUMBER(6,0)
TEMP TYPE VARCHAR2(5)
TEMP STARTDT DATE
TEMP SOURCE VARCHAR2(5)
TEMP TITLE VARCHAR2(6)
This is what I have so far. I try to isolate just the variables and then take a count of double quotes and divide it by 2 to get the number of variables, but I'm not sure how to move each variable into a separate row.
data x ;
set raw ;
if f1=1 then do ;
tabname=scan(line,2,'"') ;
ParenPos=find(line,'(') ;
x=substr(line,ParenPos) ;
EndPos=find(x,'CONSTRAINT') ;
if EndPos = 0 then EndPos=find(x,';') ;
y=substr(x,1,EndPos-1) ;
VarCnt=count(y,'"')/2 ;
end ;
run ;
... View more