I have a merge query like this
MERGE INTO dept a
USING (
SELECT 50 deptno
, 'ENGINEERING' dname
, 'WEXFORD' loc
FROM dual
) b
ON (a.deptno = b.deptno)
WHEN NOT MATCHED THEN
INSERT VALUES (b.deptno, b.dname, b.loc)
WHEN MATCHED THEN
UPDATE SET a.loc = 'WEXFORD, PA';
I need output like:
INSERT VALUES (b.deptno,b.dname,b.loc)
UPDATE SET a.loc='WEXFORD,pA'
Can I achieve this by using substring any another simple way to do this.
As I understand it, you don’t particularly care about executing the query, you only want to extract certain parts of the query text, right? Your best bet would be formulating a regular expressions describing those parts, matching them against the input string, and printing the relevant parts of each match you find.
A simple example would be this:
This simple example expects insert parts to contain spaces exactly as stated in the expression, and to be followed a single list of parenthesized arguments. The update is expected to continue to the end of the query. See the Pattern documentation on how to formulate regular expressions.
If you want to deal with strings, which might contain parentheses, semicolons and even words that look like SQL commands, things will become more difficult. And if you at some point should reqire detection of arbitrary levels of nested parenthesis, then this cannot be expressed using regular expressions at all.