I've got this working, but I'm wondering if there is a more elegant, simpler way to do it.
I have a script that gathers table names from SQL scripts. Sometimes, my script will pick up a fully qualified column name, and so I want to strip off the column name, leaving just the table name. For my tables and columns, the naming convention looks like this:
SCHEMA.OWNER.SOME_TABLE_NAME.SOME_COLUMN
Given that, I would want to yield this:
SCHEMA.OWNER.SOME_TABLE_NAME
Here's how I've done that:
I notice that in my naming convention, if a period follows an underscore, then that period marks the beginning of a column name. I parse through the string in order to find that condition. When I do, I SEPARATE the string using a period as my delimiter, then I just put all but the last item in the array back together, then strip off the final period, like so:
Code: Select all
Let>myvar=SCHEMA.OWNER.SOME_TABLE_NAME.SOME_COLUMN
Let>newstr=
RegEx>[^a-zA-Z0-9 -],myvar,0,m,nm,1,,mynewvar
Repeat>nm
If>m_%nm%=.
Let>v_pd_flag=1
Endif
If>m_%nm%=_
If>v_pd_flag=1
Separate>myvar,.,v_parts
Let>j=1
Repeat>j
Concat>newstr,v_parts_%j%
Concat>newstr,.
Add>j,1
Until>j=v_parts_count
Let>nm=1
EndIf
EndIf
Add>nm,-1
Until>nm<2
Let>newstr2={copy(%newstr%,1,length(%newstr%)-1)}
MessageModal>newstr2
Thanks in advance.