Solve math PL / SQL functions

I need to solve a math equation / function in pl / sql.
What math operations / functions are available in oracle pl / sql that can help me solve a math function as follows:

(3.5/(1+x))+(3.5/(1+x)^2)+(3.5/(1+x)^3)+(3.5/(1+x)^4)+(100/(1+x)^4)=101.55

I need a function to resolve this statement and find out the value of x .

Something like this is what I'm looking for

Any help? Thanks.

+8
math sql oracle plsql
source share
2 answers

Alas, the Oracle database is not a mathematical tool. It has many arithmetic and statistical functions , but it does not have built-in functions that can interpret equations. I'm sorry.


Coincidentally, Mark (AKA Odie_63 ) recently published a reverse Polish notation calculator that he wrote in PL / SQL. He doesn’t do exactly what you want, but I am including a link in the interest of any seekers who might stumble upon this topic in the future. More details

+7
source share

As APC said, there are no built-in functions for this. But you can use the WolframAlpha API from PL / SQL:

 declare v_equation varchar2(32767) := '(3.5/(1+x))+(3.5/(1+x)^2)+(3.5/(1+x)^3)+(3.5/(1+x)^4)+(100/(1+x)^4)=101.55'; v_escaped_url varchar2(32767); v_uri httpuritype; v_xml xmltype; v_count number := 1; begin --Escape the URL. --I used chr(38) for ampersand, in case your IDE think it a substitution variable v_escaped_url := 'http://api.wolframalpha.com/v2/query?appid=EQGHLV-UYUEYY9ARU'||chr(38)||'input=' ||utl_url.escape(v_equation, escape_reserved_chars => true) ||chr(38)||'format=plaintext'; --Create an HTTPURIType, and get the XML v_uri := httpuritype.createUri(v_escaped_url); v_xml := v_uri.getXML; --Complex solutions while v_xml.existsNode('/queryresult/pod[@title="Complex solutions"]/subpod['||v_count||']') = 1 loop dbms_output.put_line(v_xml.extract('/queryresult/pod[@title="Complex solutions"]/subpod['||v_count||']/plaintext/text()').getStringVal()); v_count := v_count + 1; end loop; --Real solutions v_count := 1; while v_xml.existsNode('/queryresult/pod[@title="Real solutions"]/subpod['||v_count||']') = 1 loop dbms_output.put_line(v_xml.extract('/queryresult/pod[@title="Real solutions"]/subpod['||v_count||']/plaintext/text()').getStringVal()); v_count := v_count + 1; end loop; end; / 

Results:

 x = -1.00006-0.996229 i x = -1.00006+0.996229 i x = -1.99623 x = 0.0308219 

There are many potential drawbacks to this approach. It will be very slow, and the API is not free. My example works because I used my free developer, but it is only good for a small number of calls.

+4
source share

All Articles