Re: 3/4 to .75
Date: Fri, 25 Feb 2000 07:42:35 +0100
Message-ID: <8958ef$5gd$1_at_vkhdsu24.hda.hydro.com>
Oracle has its built-in parser. You can use DBMS_SQL to convert your expression to a number (following example not tested):
FUNCTION parse_expression(p_expression IN VARCHAR2) RETURN NUMBER IS
l_crs PLS_INTEGER; l_dummy PLS_INTEGER: l_number NUMBER;
BEGIN
l_crs := dbms_sql.open_cursor;
BEGIN
dbms_sql.parse(l_crs, 'BEGIN :value := ' || p_expression || ' END;',
dbms_sql.V7);
dbms_sql.bind_variable(l_crs, 'value', l_number);
l_dummy := dbms_sql.execute(l_crs);
dbms_sql.variable_value(l_crs, 'value', l_number);
dbms_sql.close_cursor(l_crs);
EXCEPTION
WHEN OTHERS THEN -- e.g. division by zero, value error, not a number,
...
- don't forget to close the cursor
dbms_sql.close_cursor(l_crs);
- and return the error message to the calling application RAISE; END;
END; Marc
Jeff Smelser wrote in message ...
>I am trying to convert 3/4 to .75.. Its harder than it seems, or at least
>for me! :)
>
>When I do select to_number(3/4) from dual, it works. Add ' ' around the
>3/4 and no go. Problem is, I am receiinge all these fractions as
>characters, and can't find a way to convert it to number as decimal..
>
>Thanks in advance,
>Jeff
>
>
Received on Fri Feb 25 2000 - 07:42:35 CET