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!

Similar Messages

A: remove regular expression from a string

Hi Krishna,
DATA : str TYPE STRING VALUE '@1test;"{}]input+',
            char,
            length TYPE i,
            index TYPE i.
length = STRLEN( str ).
WHILE length > index.
  char = str+index(1).
  WRITE char.
  if char CA '+-*/!`@#$%^&()_=[]{};'.               " Add/Remove here to include numbers
    REPLACE ALL OCCURRENCES OF char in str WITH ''.
    REPLACE ALL OCCURRENCES OF '"' in str WITH ''.  " characters "{}[] are not comparable
    REPLACE ALL OCCURRENCES OF '{' in str WITH ''.
    REPLACE ALL OCCURRENCES OF '}' in str WITH ''.
    REPLACE ALL OCCURRENCES OF '[' in str WITH ''.
    REPLACE ALL OCCURRENCES OF ']' in str WITH ''.
    length = STRLEN( str ).
    ENDIF.
  add 1 to index.
ENDWHILE.
WRITE str.
Add or remove special char from '+-*/!`@#$%^&()_=[]{};' in if part as per your requirement.
Hope it meets your requirement.
Do not forget to mark helpful/correct if ma answer is useful .
Thanks,
Karthik

Hi Krishna,
DATA : str TYPE STRING VALUE '@1test;"{}]input+',
            char,
            length TYPE i,
            index TYPE i.
length = STRLEN( str ).
WHILE length > index.
  char = str+index(1).
  WRITE char.
  if char CA '+-*/!`@#$%^&()_=[]{};'.               " Add/Remove here to include numbers
    REPLACE ALL OCCURRENCES OF char in str WITH ''.
    REPLACE ALL OCCURRENCES OF '"' in str WITH ''.  " characters "{}[] are not comparable
    REPLACE ALL OCCURRENCES OF '{' in str WITH ''.
    REPLACE ALL OCCURRENCES OF '}' in str WITH ''.
    REPLACE ALL OCCURRENCES OF '[' in str WITH ''.
    REPLACE ALL OCCURRENCES OF ']' in str WITH ''.
    length = STRLEN( str ).
    ENDIF.
  add 1 to index.
ENDWHILE.
WRITE str.
Add or remove special char from '+-*/!`@#$%^&()_=[]{};' in if part as per your requirement.
Hope it meets your requirement.
Do not forget to mark helpful/correct if ma answer is useful .
Thanks,
Karthik

  • 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.

  • Boolean Expression Parsing

    Hi
    i have a String like "true && !true && (false || true)" and want to know if the expression is true or false. Is there any Helperclass that parses an boolean expression??
    String expression = "true && !true && (false || true)";
    boolean result = BooleanParser.parse(expression );
    Regard,
    Harald

    thats not cheating, just the simplest way to solvethe problem ;)
    ... and one missed opportunity to learn something
    about parser generators.I think there is something to be said for taking classes on that particular subject.
    That particular study area is well defined in computer science is well defined. So the good ideas that one can use are already there just waiting to be learned.

  • Boolean Expression Evaluator

    Hello everyone...
    Does any one know how to create a Java program that will evaluate boolean expression... For example, the user may enter (T AND T) OR F statement and the program will check the expression is valid or not and in addition it gives the answer T for true. Does anyone know where to download the free sample code that will be able to help me.. thanks.
    URGENT!
    -Eugene-

    http://www.japisoft.com/formula
    Features :
    * Decimal, string, boolean operators (or, and, not, xor...)
    * Unicode
    * Boolean expression support : (A or B) and not ( C equals D )
    * String expression support : "abc" != "cba"
    * IF THEN ELSE expression
    * Short expression format : 2x+3y
    * Variable : A=(cos(PI + x )*2) + [y-x]^2
    * Multiple lines expression : A = 1 B = A + 1 ...
    * Functions with decimal, boolean or string arguments
    * Evaluation tree produced by a pluggable parsing system
    * Evaluation optimization for symbol value changes
    * Standard library with 24 mathematical functions
    * Delegate for resolving unknown functions or symbols
    * Extend or add a new library dynamically
    * Share multiple formula context
    * Override any functions from the current library by your one
    * Support for multithreaded computing
    * Many samples (library extension, graphes) for API interesting parts
    * JDK 1.1 compliant (tested on JDK1.1.8 and JDK1.4.2)
    Best regards,
    A.Brillant

  • Dynamic boolean expression evaluation

    Hey everyone,
    We have a table that consists of a couple key columns and a column containing a boolean expression. We want to select a number of rows based on the key columns and evaluate the boolean expression in the expression column for each, only returning the first row wherein the boolean expression evaluates to true.
    We are using a context to inject the test variables into the boolean expressions and currently we are selecting all the key rows in a PL/SQL procedure and going through the cursor evaluating each of the boolean expressions with an execute immediate.
    The expressions are currently formated in the columns as anonymous PL/SQL blocks that, when called, will either return true or false to the PL/SQL procedure. Upon returning true, the procedure stops looping and returns true to the caller.
    Psuedo-code would be:
    - set-up sys_context with condition variables
    - create cursor for: select * from expression_tbl et where <key matches>
    - begin loop through cursor
    - execute immediate cursor_row.expression using out :out_is_true
    - if out_is_true = 'Y' then return true
    - loop
    - return false
    The expressions (anonymous PL/SQL blocks) from the table look something like this:
    begin if ((''||sys_context('ctx', '1')||'' = 'FL') AND (''||sys_context('ctx', '3')||'' BETWEEN 1619 AND 4598) ) then :1 := 'Y'; end if; end;
    This works, but it seems like I should be able to do this another way and potentially extract more performance.
    So...a couple questions:
    1) I have read on ask Tom that a dynamic select statement (rather than an anonymous PL/SQL block) can evaulate the boolean expressions. I.E. rather than use an execute immediate clause on an anonymous PL/SQL block contained in the expression column, I would make the expression column compatible with a where clause and create this dynamic SQL query: 'select count(*) from dual where ' || expression. I would then execute that query and if it returns a row then the expression is true, otherwise it is false. My question is, does anyone think the performance of parsing the SQL and executing it would be better than that of executing an anonymous PL/SQL block for every row? Tom said that the SQL could incur a lot of hard-parses and kill performance, but how deathly is the constant compilation of anonymous PL/SQL blocks as shown above in comparison?
    2) Would there be any benefit to pulling the execute routines out of the PL/SQL block and issuing a query such as the following:
    select * from expression_tbl et where <key matches> AND pkg.eval_routine(et.expression) = 'Y' AND rownum <= 1.
    I realize that the evaulating routine would then need to either perform an execute immediate on et.expression (if we keep the current method in place) or formulate the dynamic SQL statement and execute it. But, could this be faster than doing the same loop through rows explicitely in PL/SQL?
    Doing this would trim my PL/SQL down to:
    - set up sys_context
    - execute the above select statmenet
    - if a row is returned then return true otherwise return false
    Seems more elegant, but the peformance is all that matters.
    3) Is there any built-in routine that I may be able to replace pkg.eval_routine from 2 with that would evaulate boolean expressions for me? Or any other way to inline the idea from 1 with 2? I can't think of one given the dynamic nature of the beast, but...maybe there's something I missed.
    Thanks everyone! Hopefully I've expressed myself clearly.

    Brian - According to Tom Kyte Doing PL/SQL inside Execute Immediate should be faster as you are already within the context of a PL/SQL engine. If we choose to do it in SQL then the PL/SQL engine has to hand it over to the SQL Engine for executing the dynamic Select statements and so might be a little slower. But I am not sure if the difference can be quantifiable unless u do your own test of both evaluators and run them for like a few thousand times in a loop.
    If you are using 10g R2 - you might want to look into DBMS_RLMGR package which is the API for the Oracle's version of the embedded business rule manager.
    I looked into it but it didn't fit our needs as its deficient with respect to rule versioning and effective and until date based business rule enforcement/ validation.
    After taking a shot at designing something home grown I feel its not that difficult to construct one that fit our needs inclusive of the features( rule versioning, effective and until dates) that I listed above as deficiencies in the Oracle embedded rule engine.
    If you don't have those requirements may be using the Business Rule manager API of 10g R2 might not be a bad anticipating it will be improved in future versions.
    Regards
    -Suren

  • Create and save boolean expressions for later evaluation

    Is it possible to create Boolean expressions by inputs via user interface in LabVIEW and save them for later evaluation? I am interested in creating a 'flexible policy engine' which involves creating 'rules' comprising attribute values of certain attributes of objects based on boolean expressions which can later be used for arriving at some decisions based on the 'rules'.

    Hi Belur,
    Have you considered building a script based on the boolean expressions that you want to create for the flexible policy and saving the script to file?
    Later, you can read the script and depending on the policy, it can re-create the boolean expressions.
    A simple way to implement this is by having various pre-defined expressions places into a Case Statement. The script calls the appropriate cases that create the complete expression.
    You can store the attributes of the objects and when the vi is running, it can first open the initialization file, read the attributes and set them.
    For instance, you can read from and write to Property (and Invoke Nodes) to which you can the attributes.
    Unfortunately, I don't have an example of this that I c
    an share with you. There may be some if you do a search.
    Hope this helps..
    JLV

  • Change Boolean expression to string

    AND(NodeIsLeaf(),Equals(String,PropValue(Custom.AssignedNodeType),NodeTypeEntity))
    I need this evaluation formula to return the string N instead of False.  Any suggestions?
    DRM Version 11.1.2.2
    Thanks
    AnthonyG

    Put the code block in an IF statement and return what ever you want.
    Ex:
    IF(AND(NodeIsLeaf(),Equals(String,PropValue(Custom.AssignedNodeType),NodeTypeEntity)),N,Y)

  • Pl/sql boolean expression short circuit behavior and the 10g optimizer

    Oracle documents that a PL/SQL IF condition such as
    IF p OR q
    will always short circuit if p is TRUE. The documents confirm that this is also true for CASE and for COALESCE and DECODE (although DECODE is not available in PL/SQL).
    Charles Wetherell, in his paper "Freedom, Order and PL/SQL Optimization," (available on OTN) says that "For most operators, operands may be evaluated in any order. There are some operators (OR, AND, IN, CASE, and so on) which enforce some order of evaluation on their operands."
    My questions:
    (1) In his list of "operators that enforce some order of evaluation," what does "and so on" include?
    (2) Is short circuit evaluation ALWAYS used with Boolean expressions in PL/SQL, even when they the expression is outside one of these statements? For example:
    boolvariable := p OR q;
    Or:
    CALL foo(p or q);

    This is a very interesting paper. To attempt to answer your questions:-
    1) I suppose BETWEEN would be included in the "and so on" list.
    2) I've tried to come up with a reasonably simple means of investigating this below. What I'm attempting to do it to run a series of evaluations and record everything that is evaluated. To do this, I have a simple package (PKG) that has two functions (F1 and F2), both returning a constant (0 and 1, respectively). These functions are "naughty" in that they write the fact they have been called to a table (T). First the simple code.
    SQL> CREATE TABLE t( c1 VARCHAR2(30), c2 VARCHAR2(30) );
    Table created.
    SQL>
    SQL> CREATE OR REPLACE PACKAGE pkg AS
      2     FUNCTION f1( p IN VARCHAR2 ) RETURN NUMBER;
      3     FUNCTION f2( p IN VARCHAR2 ) RETURN NUMBER;
      4  END pkg;
      5  /
    Package created.
    SQL>
    SQL> CREATE OR REPLACE PACKAGE BODY pkg AS
      2 
      3     PROCEDURE ins( p1 IN VARCHAR2, p2 IN VARCHAR2 ) IS
      4        PRAGMA autonomous_transaction;
      5     BEGIN
      6        INSERT INTO t( c1, c2 ) VALUES( p1, p2 );
      7        COMMIT;
      8     END ins;
      9 
    10     FUNCTION f1( p IN VARCHAR2 ) RETURN NUMBER IS
    11     BEGIN
    12        ins( p, 'F1' );
    13        RETURN 0;
    14     END f1;
    15 
    16     FUNCTION f2( p IN VARCHAR2 ) RETURN NUMBER IS
    17     BEGIN
    18        ins( p, 'F2' );
    19        RETURN 1;
    20     END f2;
    21 
    22  END pkg;
    23  /
    Package body created.Now to demonstrate how CASE and COALESCE short-circuits further evaluations whereas NVL doesn't, we can run a simple SQL statement and look at what we recorded in T after.
    SQL> SELECT SUM(
      2           CASE
      3              WHEN pkg.f1('CASE') = 0
      4              OR   pkg.f2('CASE') = 1
      5              THEN 0
      6              ELSE 1
      7           END
      8           ) AS just_a_number_1
      9  ,      SUM(
    10           NVL( pkg.f1('NVL'), pkg.f2('NVL') )
    11           ) AS just_a_number_2
    12  ,      SUM(
    13           COALESCE(
    14             pkg.f1('COALESCE'),
    15             pkg.f2('COALESCE'))
    16           ) AS just_a_number_3
    17  FROM    user_objects;
    JUST_A_NUMBER_1 JUST_A_NUMBER_2 JUST_A_NUMBER_3
                  0               0               0
    SQL>
    SQL> SELECT c1, c2, count(*)
      2  FROM   t
      3  GROUP  BY
      4         c1, c2;
    C1                             C2                               COUNT(*)
    NVL                            F1                                     41
    NVL                            F2                                     41
    CASE                           F1                                     41
    COALESCE                       F1                                     41We can see that NVL executes both functions even though the first parameter (F1) is never NULL. To see what happens in PL/SQL, I set up the following procedure. In 100 iterations of a loop, this will test both of your queries ( 1) IF ..OR.. and 2) bool := (... OR ...) ).
    SQL> CREATE OR REPLACE PROCEDURE bool_order ( rc OUT SYS_REFCURSOR ) AS
      2 
      3     PROCEDURE take_a_bool( b IN BOOLEAN ) IS
      4     BEGIN
      5        NULL;
      6     END take_a_bool;
      7 
      8  BEGIN
      9 
    10     FOR i IN 1 .. 100 LOOP
    11 
    12        IF pkg.f1('ANON_LOOP') = 0
    13        OR pkg.f2('ANON_LOOP') = 1
    14        THEN
    15           take_a_bool(
    16              pkg.f1('TAKE_A_BOOL') = 0 OR pkg.f2('TAKE_A_BOOL') = 1
    17              );
    18        END IF;
    19 
    20     END LOOP;
    21 
    22     OPEN rc FOR SELECT c1, c2, COUNT(*) AS c3
    23                 FROM   t
    24                 GROUP  BY
    25                        c1, c2;
    26 
    27  END bool_order;
    28  /
    Procedure created.Now to test it...
    SQL> TRUNCATE TABLE t;
    Table truncated.
    SQL>
    SQL> var rc refcursor;
    SQL> set autoprint on
    SQL>
    SQL> exec bool_order(:rc);
    PL/SQL procedure successfully completed.
    C1                             C2                                     C3
    ANON_LOOP                      F1                                    100
    TAKE_A_BOOL                    F1                                    100
    SQL> ALTER SESSION SET PLSQL_OPTIMIZE_LEVEL=0;
    Session altered.
    SQL> exec bool_order(:rc);
    PL/SQL procedure successfully completed.
    C1                             C2                                     C3
    ANON_LOOP                      F1                                    200
    TAKE_A_BOOL                    F1                                    200The above shows that the short-circuiting occurs as documented, under the maximum and minimum optimisation levels ( 10g-specific ). The F2 function is never called. What we have NOT seen, however, is PL/SQL exploiting the freedom to re-order these expressions, presumably because on such a simple example, there is no clear benefit to doing so. And I can verify that switching the order of the calls to F1 and F2 around yields the results in favour of F2 as expected.
    Regards
    Adrian

  • Computing an expression in a string?

    I have an expression in a string, how can I compute this? I know I can put it in post fix and travers it with a Stack, but there must be an easier way in Java, e.g. How can I evaluation this string into an integer of 10?
    String s = "5+5";
    // how can I compute the expression in s???
    int i=???

    I appreciate the response, but have to agree with jschell
    With Java being an interpreted language, you would think it could resolve expressions built on the fly and residing in a string. I also see IDEs like IntelliJ that have an evaluate option in the debugger, so that is why I thought there might be a way. Perhaps they coded their own. I also saw a reference to an Expression Object, but could not make sense of it.
    If this issue of evaluatiing expressions in strings is a question has ben asked man times before, hopefully someone from Sun who works on the JDK is reading this, and considering adding this feature. I have seen this capability in another programming language, and have even seen the dynamic creation of programming statements built in strings.

  • Problems with Reflection API and intantiating an class from a string value

    I want to instantiate a class with the name from a String. I have used the reflection api so:
    static Object createObject(String className) {
    Object object = null;
    try {
    Class classDefinition = Class.forName(className);
    object = classDefinition.newInstance();
    } catch (InstantiationException e) {
    System.out.println(e);
    } catch (IllegalAccessException e) {
    System.out.println(e);
    } catch (ClassNotFoundException e) {
    System.out.println(e);
    return object;
    Let's say my class name is "Frame1".
    and then if i use:
    Frame1 frm = (Frame1) createObject("Frame1");
    everything is ok but i cannot do this because the name "Frame1" is a String variable called "name" and it doesn't work like:
    name frm = (name) createObject("Frame1");
    where i'm i mistaking?
    Thanks very much!

    i have understood what you have told me but here is a little problem
    here is how my test code looks like
    Class[] parameterTypes = new Class[] {String.class};
    Object frm = createObject("Frame1");
    Class cls = frm.getClass();
    cls.getMethod("pack",parameterTypes);
    cls.getMethod("validate",parameterTypes);
    everything works ok till now.
    usually if i would of had instantiated the "Frame1" class standardly the "cls" (or "frm" in the first question ) object would be an java.awt.Window object so now i can't use the function (proprietary):
    frame_pos_size.frame_pos_size(frm,true);
    this function requires as parameters: frame_pos_size(java.awt.Window, boolean)
    because my cls or frm objects are not java.awt.Window i really don't find any solution for my problem. I hope you have understood my problem. Please help. Thanks a lot in advance.

  • Getting char values from a string problem

    Hi,
    Here's an example of what I'm trying to do:
    boolean loopSwitch = true;
    while (loopSwitch)
         String orderDecider = JOptionPane.showInputDialog (null, "Would you like your numbers to be ordered in   ascending or descending order(A/D)",      "Order decision", JOptionPane.QUESTION_MESSAGE);
         if (orderDecider == A)
         loopSwitch = false;
         }I basically want the user to input either a/A/d/D and to get the char values from the string so I can use them in an if statement.
    Basically, I wanna parse the string into a char.
    Is this possible?
    Thanks.
    Edited by: xcd on Oct 16, 2009 8:38 AM

    Why not just use the String.equals() method to compare a String to a String?
    But if you must, you can use the String.charAt() method to return a char at a particular location in the String.
    Note: char literals need to be surrounded by single quotes ('A') and String literals need to be surrounded by double quotes ("A").

  • How to extract an element value from a String of HTML

    I have a web service that returns a fragment of HTML that contains a number in a table. The return parameter type is a string. I need to get this number and use it in a BPEL while loop, as the condition for the loop (while the number > 0).
    I have tried using the function bpws:getVariableData() but the BPEL PM faults and says: XPath expression failed to execute. Error while processing xpath expression. I think this is because I am trying to apply an XPath expression over a String variable.
    The return value from my web service looks like this:
    <whileConditionResultSet>
    <part xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" name="response">
    <ns1:string_Response xmlns:ns1="http://systinet.com/xsd/SchemaTypes/"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="d:string">
         <p>SQL Query: select count(*) from delta_manages</p>
         <p><table border='1'>
              <tr> <th bgcolor='#C0C0C0'>COUNT(*)</th></tr>
              <tr> <td>28</td></tr>
              </table>
         </p></ns1:string_Response>
    </part>
    </whileConditionResultSet>
    How do I get the value from the HTML table into a BPEL variable?

    the doSqlService() which executes an arbitrary SQL statement, returns a string of HTML like this:
    <doSqlServiceResponse>
    <part xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" name="response">
    <ns1:string_Response xmlns:ns1="http://systinet.com/xsd/SchemaTypes/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="d:string"><p>SQL Query: select count(*) from delta_manages</p> <p><table border='1'> <tr> <th bgcolor='#C0C0C0'>COUNT(*)</th></tr> <tr> <td>14</td></tr> </table></p></ns1:string_Response>
    </part>
    I then copy the result to the whileResultString variable
    <variable name="whileResultString" type="xsd:string"/>
    <copy>
                                       <from variable="doSqlServiceResponse" part="response" query="/ns1:string_Response">
                                       </from>
                                       <to variable="whileResultString"/>
                                  </copy>
    I realise too, a root element will be needed. This is not a mission critical problem as we could change the web service at the other end. It was originally designed for a client to display the results rather than use them within a business process. Anyway, I'm just interested to know if I can create a node from this string data in BPEL.
    Ross.

  • 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

  • Calling boolean function from tree query

    Hi all,
    I have placed a tree on my sidebar region from the following query
    select PAGE_NO id,
    PARENT_PAGE_NO pid,
    NAME name,
    'f?p=&APP_ID.:'||page_no||':&SESSION.' link,
    null a1,
    null a2
    from #OWNER#.APEX_PAGES
    WHERE page_no = :APP_PAGE_ID
    AND nvl(navigation,'N') = 'Y'
    Its running perfectly fine. Now i have my custom function "isUserAllowed(app_user, name_of_node, isParent)" which returns a boolean expression is the logged in User has access privilege on that node.
    How can i run my function inside the tree query so that node is visible only for those values in which my function returns "true"? and not on others?
    With Regards,
    Sunil Bhatia

    The "wrapper" function would actually be pretty easy - just another function to call the one returning the boolean and convert it to some other value, numeric or character. something like (untested)
    <pre>
    FUNCTION wrapper_function(P_whatever varchar2) return varchar2 IS
    v_return_value_c varchar2(5);
    BEGIN
    r_return_value_c := case boolean_function(p_whatever)
    when true then 'true'
    else 'false;
    return v_return_value_c;
    END;
    </pre>
    Using the function in the WHERE clause could look something like this (untested, but should work if done correctly)
    <pre>
    select whatever
    from your_table
    where wrapper_function(whatever) = 'true'
    </pre>

  • Maybe you are looking for