Extract words from a string and use them as variables [message #682742] |
Fri, 13 November 2020 10:45 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
![](http://www.gravatar.com/avatar/1d630362c0f9b8a094ff506ac8194332?s=64&d=mm&r=g) |
Haykel_bh
Messages: 5 Registered: November 2020
|
Junior Member |
|
|
Hi,
Is it possible to extract words from a string and use them as variables?
Example:
DECLARED
- I want to extract recunit_a and recunit_b and use them as variables afterwards.
vv_where_clause VARCHAR2 (1000): = 'recunit_a = rec_unit_b';
BEGIN
recunit_a: = 10;
rec_unit_b: = 20;
END;
|
|
|
Re: Extract words from a string and use them as variables [message #682743 is a reply to message #682742] |
Fri, 13 November 2020 12:43 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
![](http://www.gravatar.com/avatar/d29f577f753cb4b873212fd5ed0da4cd?s=64&d=mm&r=g) |
EdStevens
Messages: 1376 Registered: September 2013
|
Senior Member |
|
|
Haykel_bh wrote on Fri, 13 November 2020 10:45Hi,
Is it possible to extract words from a string and use them as variables?
Example:
DECLARED
- I want to extract recunit_a and recunit_b and use them as variables afterwards.
vv_where_clause VARCHAR2 (1000): = 'recunit_a = rec_unit_b';
BEGIN
recunit_a: = 10;
rec_unit_b: = 20;
END;
The simple answer to your exact question "extract words from a string and use them (assign to) variables is 'yes'. Typically you would use 'regular expressions' to do this. Perhaps instead of regular expressions, a simple instr() function, though that is less flexible.
But your presented code strongly suggests there is more to your question. It looks like you want to assign the text of a WHERE clause to a string, and then use that in a sql statement. If that is what you want, then you will have to construct your sql statement as a variable string, then use dynamic sql to execute it. And in what appears to be your case, that is probably a bad idea.
Also, your syntax for assigning a value to a variable is wrong. In pl/sql, the assignment operator is ':=' a colon followed by an equal sign, with no intervening space.
All in all, you appear to be asking a classic 'x-y question'.
|
|
|
|
|
|
|