Multiplication Funtion In ORACLE [message #326540] |
Wed, 11 June 2008 23:19  |
subhadip.chanda
Messages: 64 Registered: May 2007
|
Member |
|
|
Hi,
I have a table structure like :-
Create table test(A varchar2(50),B NUMBER);
The data in that table is like that:-
A B
----------------------
2*3
2*4*5
4*5
column B contain no data.
I want to create a function which can be used in a select query,and the output should come like that :-
A B
----------------------
2*3 6
2*4*5 40
4*5 20
Means column B contains the resultant value of column A.
And the above output should come through a select statement.You can use any function inside the select statement.
How do I proceed?Please give some idea.
Regards,
Subhadip
|
|
|
|
|
|
|
Re: Multiplication Funtion In ORACLE [message #326556 is a reply to message #326555] |
Wed, 11 June 2008 23:52   |
Frank
Messages: 7901 Registered: March 2000
|
Senior Member |
|
|
If you want to interpret the contents of a column, you will have to write a procedure to do so.
You might look at dynamic sql, to see if you can construct a sql or a pl/sql block from it, where you catch the outcome.
No need to ask for an example, as you should start doing your own (home)work. We are only here to help, not to do it for you.
|
|
|
|
Re: Multiplication Funtion In ORACLE [message #326560 is a reply to message #326540] |
Thu, 12 June 2008 00:02   |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
I have no idea about solution in pure SQL, as it is not designed to be used for parsing expressions. Maybe some 3rd party package? Or some funky XML approach?
However you may write your own parser (quite difficult if you did not do it before) or use the Oracle one when calling the expression dynamically. Both approaches need the use of PL/SQL.
|
|
|
|
|
|
|
|
|
|
Re: Multiplication Funtion In ORACLE [message #570085 is a reply to message #326540] |
Mon, 05 November 2012 08:51   |
Solomon Yakobson
Messages: 3305 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
subhadip.chanda wrote on Thu, 12 June 2008 00:19I want to create a function which can be used in a select query,and the output should come like that
If OLAP option is installed:
select a,
dbms_aw.eval_number(a) b
from test
/
A B
-------------------------------------------------- ----------
2*3 6
2*4*5 40
4*5 20
SQL>
If not and you are on 11g:
select a,
xmlcast(xmlquery(a returning content) as number) b
from test
/
A B
-------------------------------------------------- ----------
2*3 6
2*4*5 40
4*5 20
SQL>
If not and you are on older version:
select a,
extractvalue(dbms_xmlgen.getxmltype('select ' || a || ' x from dual'),'/ROWSET/ROW/X') b
from test
/
A B
-------------------------------------------------- -----
2*3 6
2*4*5 40
4*5 20
SQL>
SY.
|
|
|
|
|
|
|
|