Evaluating an expression stored as varchar

Hi,
I've declared a varchar variable and the data stored in that variable is an expression.
I need to evaluate the expression.
Is there any option to do so.
For example
v_s_expression:='10+5';
i need to evaluate and get the value into another variable.
i should get the result 15 in the variable v_n_result.
any methods?
Thanks in advance
Prasanth

first of all why?....
execute immediate 'select '||v_s_expression||' from dual' into res;like in
SQL> declare
  2     v_s_expression varchar2(10);
  3     res number;
  4  begin
  5     v_s_expression:='10+5';
  6     execute immediate 'select '||v_s_expression||' from dual' into res;
  7     dbms_output.put_line(res);
  8  end;
  9  /
15
PL/SQL procedure successfully completed.

Similar Messages

  • How can I convert the variable expression stored as string back to variable expression

    How can I convert the variable expression stored as string back to variable expression?
    I am storing the expression enterd in the TSExpresssionEditControl as simple string and want to convert back to expression since I want to get the data type of that expression.

    pritam,
    I'm not sure what you're trying to do exactly. If you are trying to get the value of a variable and you only have the name of value in a string, then you can use Evaluate() to get its value. If you want the data type, my advise is to use the GetPropertyObject() API method and just pass in the loop up string. Then you'll have a handle to the data object and then proceed from there.
    Regards,
    Song D
    Application Engineer
    National Instrument
    Regards,
    Song Du
    Systems Software
    National Instruments R&D

  • ABAP-Logic/Command: Execute An Expression Stored In A Variable

    Consider the following code - <b>Is it possible to execute the statement/expression stored in variables expression1, expression2 and expression3?</b> The result should be:
    sum = 5 , subname = 'First' & i_output should be sorted by lifnr and ebeln.
    *---DATA DECLARATIONS
    DATA: sum         TYPE i,
          op1         TYPE i,
          op2         TYPE i,
          name        TYPE string,
          subname     TYPE string,
          offset      TYPE i,
          expression1 TYPE string,
          expression2 TYPE string,
          expression3 TYPE string.
    DATA: BEGIN OF i_output OCCURS 0,
          lifnr TYPE lfa1-lifnr,
          ebeln TYPE ekko-ebeln,
          ebelp TYPE ekpo-ebelp,
          END OF i_output.
    *---BUILD EXPRESSION 1
    op1 = 2.
    op2 = 3.
    expression1 = 'sum = op1 + op2'.
    *---BUILD EXPRESSION 2
    name   = ' First Name'.
    offset = 5.
    expression2 = 'subname = name+1(offset)'.
    *---POPULATE ITAB I_OUTPUT
    MOVE: '111111' TO i_output-lifnr,
          'PO1'    TO i_output-ebeln,
          '010'    TO i_output-ebelp.
    APPEND i_output.
    MOVE: '111511' TO i_output-lifnr,
          'PO1'    TO i_output-ebeln,
          '020'    TO i_output-ebelp.
    APPEND i_output.
    MOVE: '111111' TO i_output-lifnr,
          'PO3'    TO i_output-ebeln,
          '010'    TO i_output-ebelp.
    APPEND i_output.
    MOVE: '114111' TO i_output-lifnr,
          'PO2'    TO i_output-ebeln,
          '010'    TO i_output-ebelp.
    APPEND i_output.
    MOVE: '111121' TO i_output-lifnr,
          'PO2'    TO i_output-ebeln,
          '020'    TO i_output-ebelp.
    APPEND i_output.
    CLEAR i_output.
    *---BUILD EXPRESSION 3
    expression3 = 'sort i_output by lifnr ebeln'.
    Thanks in advance!

    > You can achieve this by generating a subroutine pool
    > dynamically, passing the code lines (expressions) as
    > an internal table. Here is the syntax:
    >
    > GENERATE SUBROUTINE POOL itab NAME name.
    >
    > Hope this helps,
    > Bhanu
    Hey Banu, thanks!
    Message was edited by: Sam

  • Timestamp storing in Varchar. Performance issue?

    I have noticed in one of application, all date timestamp columns has been stored in Varchar. If i convert those date columns into timestamp datatype, will it again any performance in select queries?
    And size of varchar has created exactly same length of date.   Kindly advise will it make any difference? Appreciate if you could explain in-detailed.

    user530956 wrote:
    I have noticed in one of application, all date timestamp columns has been stored in Varchar. If i convert those date columns into timestamp datatype, will it again any performance in select queries?
    And size of varchar has created exactly same length of date.   Kindly advise will it make any difference? Appreciate if you could explain in-detailed.
    Any performance difference should be negligible.  This really isn't a performance issue, it is a design issue.  By not using the proper data type, the application has to jump through all kinds of hoops to deal with the fact that  the "timestamp" is fundamentally no different than the string "here's your sign".
    Of course such a change will require thorough application testing before going live.  But it is the right thing to do, to correct an abysmally bad design decision.

  • ORAMED-01101 :[Filter Expression Error]Error evaluating filter expression.

    I am a newbie with oracle soa suite 11g. I am trying to use file adapter to upload the csv file contents to database.
    My csv file looks like:
    employeeid,employeename,designation,managerempid
    1121,abc,mts,211
    1122,def,mts,232
    1123,xyz,abc,133
    The generated xml file during the xsd test is
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <Root-Element xmlns="http://TargetNamespace.com/EmpAdaptor">
    <emp>
    <employeeid>1121</employeeid>
    <employeename>suneetha</employeename>
    <designation>mts</designation>
    <managerempid>211</managerempid>
    </emp>
    <emp>
    <employeeid>1122</employeeid>
    <employeename>challa</employeename>
    <designation>mts</designation>
    <managerempid>232</managerempid>
    </emp>
    <emp>
    <employeeid>1123</employeeid>
    <employeename>xyz</employeename>
    <designation>abc</designation>
    <managerempid>133</managerempid>
    </emp>
    </Root-Element>
    and in the mediator, I have the filter expression as shown:
    $in.body/ns1:EmpDetails/ns1:Emp
    the d/b table i created is
    CREATE TABLE empdtls (EMPID NUMBER(5) PRIMARY KEY,ENAME VARCHAR2(15) NOT NULL,DESIG VARCHAR2(10),MGREMPID NUMBER(5));
    When I deployed it, the application throws the below fault
    Non Recoverable System Fault :
    ORAMED-01101:[Filter Expression Error]Error evaluating filter expression.Possible Fix:Please make sure filter expression is valid, otherwise contact oracle for support. Cause:ORAMED-01102:[Filter Expression Metadata Error]Error evaluating filter expression, "$in.body/ns1:EmpDetails/ns1:Emp"Possible Fix:Please make sure filter expression metadata is valid, otherwise contact oracle for support.
    I have been trying to fix this error for almost three days..
    Somebody please help me..

    Sorry the generated xml during test is
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <EmpDetails xmlns="http://TargetNamespace.com/ServiceName">
    <Emp>
    <employeeid>1121</employeeid>
    <employeename>suneetha</employeename>
    <designation>mts</designation>
    <managerempid>211</managerempid>
    </Emp>
    <Emp>
    <employeeid>1122</employeeid>
    <employeename>challa</employeename>
    <designation>mts</designation>
    <managerempid>232</managerempid>
    </Emp>
    <Emp>
    <employeeid>1123</employeeid>
    <employeename>xyz</employeename>
    <designation>abc</designation>
    <managerempid>133</managerempid>
    </Emp>
    </EmpDetails>

  • OSB insert in not evaluating the expression

    I am using insert in the proxy service of OSB and and my expression is like this:
    Expression : <fcs:appId>$body/*/appId/node()</fcs:appId>
    My problem is that it's not evaluating the expression. It's inserting this as text ($body/*/appId/node()).
    Any idea, why?

    I assume you want to get the value of the tag appid, then the correct expression is <fcs:appId>{$body/*/appId/text()}</fcs:appId>
    In case there is namespace defined with your xml tag then you should be using it as <fcs:appId>{$body/*/*:appId/text()}</fcs:appId>
    Thanks,
    Patrick
    Edited by: Patrick Taylor on May 25, 2011 8:15 PM

  • Binding assignment is not available:Error in the evaluation of expression

    Hi All,
    I have created Workflow to send an Email using Requested Start date concept of a Task.This is for sending a E-mail to the customer when contract end date-60 Days.
    I have done all Bindings and I am getting The date and time from BOR which I am using to triger an Event.
    I am getting these type of Errors:
    Source (expression '&BUS2000137.TIME&') of binding assignment is not available
    Source (expression '&BUS2000137.DATE&') of binding assignment is not available
    Error in the evaluation of expression '<???>&BUS2000137.DATE&' for item '1'
    Unable to determine the value of component ''
    Error in the evaluation of expression '<???>&BUS2000137.TIME&' for item '1'
    Unable to determine the value of component ''
    Looking for Inputs.
    Regard's,
    Lokesh

    Hi Adrash/Rick,
    Object type  ZBS2000137
    Attributes
    ZBS2000137.Time    Time to send mail --> Is nothing but OBJECT-TIME = SY-UZEIT
    ZBS2000137.Date    60 days before contract end date  --> Is nothing but  OBJECT-DATE =  LS_APPOINTMENT-DATE_FROM - 60.
    Methods
    ZBS2000137.Method1       Sending Mail
    Events
    ZBS2000137.Released      Contract Line Item Released
    ie I want to excute the task with same DATE and TIME, the same I have mentioned in "
    Requested Strat Tab with Expression as below
    Refer.date/time EXP Expression
    Date &BUS2000137.DATE&     60 days before contract end date
    Time &BUS2000137.TIME&      Time to send mail
    Note: If I am testing the Workflow from T-code: SWUS it is working fine.
    Regard's,
    Lokesh.

  • How does one evaluate an expression stored as a VARCHAR 2 in a table?

    I am attempting to write a single SQL statement that will select three columns of data from a table and based on the value of a string in one column perform a calculation using the other two columns. Here is an example. TableX contains three columns. For simplicity sake let's say Col1 and Col2 are Number(5) and Col3 is a VARCHAR2(25).
    TableX
    Col1 Col2 Col3
    5 7 Col1+Col2
    10 3 Col1*Col2
    20 5 Col1/Col2
    I would like to write an SQL statement like 'select Col1, Col2, evaluate(Col3) as "Eval" from TableX' and get the following result set back.
    Col1 Col2 Eval
    5 7 12
    10 3 30
    20 5 4
    Is there an Oracle provided function like the hypothetical evaluate() provided above that will do this?
    One potential solution would be to write a stored procedure that accepts the three columns as parameters and then performs an execute immediate and returns the result. However, I would like a more dynamic utility so I don't have to be resticted to a preset number of columns (3 in this example).
    Any ideas would be greatly appreciated.
    Thanks,
    Matt

    Matthew:
    There is no evaluate function in Oracle, and as far as I know, there is no way to do what you want solely in sql. However, this function should do the trick.
    SQL> CREATE OR REPLACE FUNCTION my_eval (
      2     p_tab_name IN VARCHAR2,
      3     p_rowid IN ROWID,
      4     p_calc_col IN VARCHAR2) RETURN NUMBER IS
      5
      6  sqlstr VARCHAR2(4000);
      7  result NUMBER;
      8  BEGIN
      9     sqlstr:= 'SELECT '||p_calc_col||' FROM '||p_tab_name||' WHERE rowid = :b';
    10     EXECUTE IMMEDIATE sqlstr INTO result USING p_rowid;
    11     RETURN result;
    12  END;
    13  /
    Function created.
    SQL> CREATE TABLE jtest (col1 number,col2 number,col3 varchar2(50));
    Table created.
    SQL> INSERT INTO jtest values (5, 7, 'Col1+Col2');
    1 row created.
    SQL> INSERT INTO jtest values (10, 3, 'Col1*Col2');
    1 row created.
    SQL> INSERT INTO jtest values (20, 5, 'Col1/Col2');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> SELECT col1,col2,col3,MY_EVAL('jtest',rowid,col3) evald
      2  FROM jtest
      3  /
          COL1       COL2 COL3                           EVALD
             5          7 Col1+Col2                         12
            10          3 Col1*Col2                         30
            20          5 Col1/Col2                          4
    SQL> DROP TABLE jtest;
    Table dropped.
    SQL> CREATE TABLE jtest (col1 number,col2 number,col3 number,col4 varchar2(50));
    Table created.
    SQL> INSERT INTO jtest values (5, 7, 2, '(Col1+Col2)/Col3');
    1 row created.
    SQL> INSERT INTO jtest values (10, 3, 5, 'Col1*(Col2+Col3)');
    1 row created.
    SQL> INSERT INTO jtest values (20, 5, 2, 'Col1/Col2/Col3');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> SELECT col1,col2,col3,col4,MY_EVAL('jtest',rowid,col4) evald
      2  FROM jtest;
          COL1       COL2       COL3 COL4                           EVALD
             5          7          2 (Col1+Col2)/Col3                   6
            10          3          5 Col1*(Col2+Col3)                  80
            20          5          2 Col1/Col2/Col3                     2This could easily be extended to handle character functions as well.
    John

  • Evaluation of html stored in the database

    Hello everyone, here is my story.
    I have html stored in the database that I am using in regions. The region is a pl/sql anonymous block with code similar to this.
    DECLARE
    testt varchar(30000);
    BEGIN
    SELECT Main_Page_Image_Zone INTO testt FROM htmltable where Main_Page_Image_Zone IS NOT NULL;
    htp.p(testt);
    END;
    It draws in and displays the html great. The only problem is apex isn't evaluating the html. I have an image that is drawing from #workspace_images#, but instead of translating this to something useful, I get a red x. It is trying to find the image as #workspace_images#...The html being drawn in isn't being evaluated like I want it to (I want it to translate #workspace_Images#). Any ideas how to evaluate this html?
    Here is what the image location is supposed to look like
    http://127.0.0.1:8080/apex/wwv_flow_file_mgr.get_file?p_security_group_id=6933527329162765&p_fname=fmw.gif
    Instead this shows up:
    http://127.0.0.1:8080/apex/f?p=104:12:617607226208594:::::#WORKSPACE_IMAGES#fmw.gif
    This is stored in the database (ignore the .)
    <.img src="#WORKSPACE_IMAGES#fmw.gif" width="697" height="439" border="0" usemap="#Map" />

    However
    Replacing occurences of '#WORKSPACE_IMAGES' with 'WORKSPACE_IMAGES' in the database
    and then applying the replace function on the column works.
    select replace(f1,'WORKSPACEIMAGES','&WORKSPACE_IMAGES.') into str from temp_tab;
    Again, don't know why !

  • Using a xpath expression stored in a variable

    Hi All,
    I have an xpath expression which is stored in the database which I need to use against the request XML. I am able to retrieve this Xpath expression from the database, but not able to use it against the request XML.
    Xpath expression got from the database is: /request/param//name.
    I have tried $body/$XpathVariable, this does not work. I can not hard code this expression during my design time, so the details of the expression has to be fetched at run time.
    Any ideas to get the value would helpful.
    Thanks

    try to assign this value to a temp variable and then in the XqueryExpression try to retrieve it starting with "//"

  • Evaluating xpath expressions

    Hi all,
    I have an xml document as
    <?xml version="1.0" encoding="UTF-8"?>
    <purchaseReport xmlns="http://www.example.com/Report" >
    <regions>
    <zip code="95819">
    <part number="872-AA" quantity="1"/>
    <part number="926-AA" quantity="1"/>
    <part number="833-AA" quantity="1"/>
    <part number="455-BX" quantity="1"/>
    </zip>
    <zip code="63143">
    <part number="455-BX" quantity="4"/>
    </zip>
    </regions>
    <parts>
    <part number="872-AA">Lawnmower</part>
    </parts>
    </purchaseReport>
    when I evaluate the for an expression xpath_object.evaluate(f,"/purchaseReport/parts/part/@number",NODE)
    I am getting null as return value.
    I have set the namespace context for xpath_object as
    xpath_object.setNameSpaceContext(new name_space_context());
    class name_space_context implements NamespaceContext{
    public String getNamespaceURI(String prefix){
    //System.out.println("A call was made here");
    if(prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)){
    System.out.println("A call was made here");
    return "http://www.example.com/Report";
    else if(prefix.equals(XMLConstants.XML_NS_PREFIX)) {
    System.out.println("A call was made here");
    return XMLConstants.XML_NS_URI;
    else if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)){
    System.out.println("A call was made here");
    return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
    else if(prefix.equals("def")){
    System.out.println("A call was made here def");
    return "http://www.example.com/Report";
    else if(prefix.equals("si")){
    System.out.println("A call was made here si");
    return "http://www.example.com/Report/si";
    else if(prefix.equals("")){
    System.out.println("A call was made here empty");
    return "http://www.example.com/Report";
    else {
    return "There is no matching prefix with the given input" + prefix;
    please explain why me I am getting null when I evalute the expression.

    Hi tsuji,
    I am trying to update the element value in my xml , by getting input the xml and the xpath.
    My code is as below.
    InputSource is;
    is = new InputSource(new StringReader(input.toString()));
    Node node = (Node)xPath.evaluate(XPATH, is, XPathConstants.NODE);
    node.setTextContent(newValue);
    I succeeded in evaluating the namespace prefix also.
    After updating the value of the node, I tried to display the updated xml. But i couldnt succeed.
    i tried,
    Making 'Document' out of the 'is' - but failed throws NullPointerException in Document doc=dBuilder.parser(is)
    Please help me in displaying the updated XMLdocument.
    I have a doubt here, in this case like mere changing the value of the node, will it change the original InputSource 'is'
    But , when i used
    NodeIterator nl = XPathAPI.selectNodeIterator(doc, xpath); //here doc is the Document object, xpath is String object
    n=nl.nextNode();
    n.setTextContent(newValue);
    Then when i tried displaying the doc again, it gave me the updated document.
    I couldnt proceed with NodeIterator , i couldnt apply the setNamespaceContext.
    Kindly help me in this regard.
    Thanks,
    Sabarisri. N

  • Execute dynamic query stored as varchar in a different table.

    Hi,
    I have a table with a column as query,which stores the query i want to fire.for eg.my query will be like :-
    Select name,empid from employees where name =null
    Now,I have a stored procedure in which i have declared  a variable @query .I want to replace the following line of code .
    if exists(Select name ,empid from employees where name=null)
    begin
    --send mail
    end
    as
    if exists(@query)
    But it doesnt seem to work because it is taking the @query as varchar and not an actual t-sql command.I want to keep the query dynamic as each row in my table has a different query to fire.

    And only to clarify Praveen's solution:
    DECLARE @DynamicSQl nvarchar(250), @x nvarchar(100)
    SELECT @x = '@retVal int output'
    DECLARE @retVal int
    SET @DynamicSQl = 'SET @retVal = CASE WHEN EXISTS (' + @query + ') THEN 1 ELSE 0 END'
    EXEC sp_executesql @DynamicSQl, @x, @retVal output
    IF @retVal > 0
    BEGIN
    print 'send mail'
    END
    However, Nimo should probably have some error handling, as the stored query may not be syntactically correct. And even if it is syntactically correct, it may not play well with EXISTS. Case in point: a query that starts with a CTE.
    And of course, if any user is permitted to add these queries, and this code is exeuted with high permissions, they can inject queries that perform evil things they don't have permissions to do themselves, so be careful.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Please help ... evaluating jsp:expression in attributes

    Dear All,
    I have searched the forum and found a few posts expressing a similar problem. However none seemed to divulge any solution.
    <option value="<jsp:expression> signals[count] </jsp:expression>"><jsp:expression> signals[count] </jsp:expression></option>In the code above the second expression evaluates fine but the first causes problems. Its the angle brackets of the jsp:expression:
    The value of attribute "value" must not contain the '<' characterI have also tried <%= %> and %= % as has been suggested in previous posts
    <%= => fails also because of the angle brackets
    %= % is set to the value, instead of the evaluated expression.
    Am Completely Stumped. Surely there must be a way to do this!?!
    Thanks is advance

    Hi Steve, thanks for your help I have resolved the problem. Somewhere in the J2EE Tutorial I found a snippet of code that talked about using CDATA tags.
    My working code now looks like this:
    <td><select name="signal_list" multiple="multiple">
        <jsp:useBean id="signalslist" class="acreweb.SignalsList" scope="session" />
            <jsp:scriptlet>
                int count = 0;
                System.out.println("useBean");
                String[] signals = signalslist.getSignals();
                while(count < signals.length)
         //Display signal names in select box
         System.out.println(signals[count]);
         </jsp:scriptlet>
              <![CDATA[<option value=']]><jsp:expression>new String(signals[count])</jsp:expression><![CDATA[' />]]><jsp:expression> signals[count] </jsp:expression>
         <jsp:scriptlet>     
         count++;
               </jsp:scriptlet>
        </select>
    </td>Sorry about formatting am being dragged to the pub, impatient work colleagues

  • Evaluating an expression in a string

    I need to evaluate an expression in a string, and return 0 or 1 for true or false.
    Here is a version I tried:
    06:25:26  > CREATE OR REPLACE FUNCTION MJT_EVALUATE_EXPR (in_expr_to_evaluate VARCHAR2)
    06:26:00   2     RETURN NUMBER
    06:26:00   3  IS
    06:26:00   4     l_dual_record   DUAL%ROWTYPE;
    06:26:00   5     csr_dual        SYS_REFCURSOR;
    06:26:00   6     l_this_result   NUMBER;
    06:26:00   7  BEGIN
    06:26:00   8     OPEN csr_dual FOR 'SELECT * FROM DUAL WHERE ' || in_expr_to_evaluate;
    06:26:00   9 
    06:26:00  10     FETCH csr_dual INTO l_dual_record;
    06:26:00  11 
    06:26:00  12     IF csr_dual%FOUND
    06:26:00  13     THEN
    06:26:00  14        l_this_result := 1;
    06:26:00  15     ELSE
    06:26:00  16        l_this_result := 0;
    06:26:00  17     END IF;
    06:26:00  18 
    06:26:00  19     CLOSE csr_dual;
    06:26:00  20 
    06:26:00  21     RETURN l_this_result;
    06:26:00  22  END;
    06:26:00  23  /
    Function created.
    06:26:11> select mjt_evaluate_expr('((1=1) OR (1=0))') from dual;
    MJT_EVALUATE_EXPR('((1=1)OR(1=0))')
                                      1
    1 row selected.
    Elapsed: 00:00:00.02
    06:26:22 > Due to the high number of executions, I would like to avoid dynamic SQL or cursor operations such as this. Does anyone have a suggestion for another approach?
    The expressions can get more complex than this, possibly with dozens of terms.

    Does anyone have a suggestion for another approach?I don't think you'll gain any performance but for the records:
    SQL> select * from v$version where rownum = 1
    BANNER                                                                         
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production         
    1 row selected.
    SQL> var bool varchar2(40)
    SQL> exec :bool := '1=1 and 1=0'
    PL/SQL procedure successfully completed.
    SQL> select decode(column_value, 'true', 1, 0) bool from xmltable (:bool)
          BOOL
             0
    1 row selected.

  • Evaluating boolean expressions from a string

    Hi All,
    In my program I am dynamically generating boolean expressions.
    Hence, I store the expression as a string. I want to be able to determine if that expression evaluates to true/false.
    For eg, String expr = "1 < 2";
    I want to be able to evaluate expr and print false(in this case)
    How can I do that? Are there any class that come with JDK1.4 for doing this or can you point me to some API that I can use for this.
    Thanks,
    Vijay

    I can't count how many times this has been askedhere.
    Try searching the forums.Give yourself credit - you could count it if you
    wanted to.
    OK, maybe so. But I can't count it off the top of my
    head. :-) But easier than counting the hairs on your head (well.....presuming you do have some....)
    Really, it's bizarre how much this gets
    asked. I think I'll start a new thread about it...Be realistic....the integer to string or string to integer gets asked a lot more often!

Maybe you are looking for