'How to extract next word after substring that is of variable length? - SQL
I have text in one column col resembling,
{insert random junk text here} FROM db_name.table_name {insert random junk text here}
I need to extract db_name.table_name and have that stored in a column by itself. Note that db_name.table_name is of variable length.
What I've tried:
SELECT substring(col, strpos('FROM ', col), strpos(' ', col) - strpos('FROM ', col) + len(' '))
This simply just extracts the first character of junk in the column. If someone can help me out with this, that would be great!
Edge Case
In some instances, there may be multiple FROM keywords. Here I need to extract all three db_name.table_names in separate rows.:
{insert random junk text here} FROM db_name1.table_name1 {insert random junk text here} FROM db_name1.table_name2 {insert random junk text here} FROM db_name1.table_name3 {insert random junk text here}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
