Toplink expression - using complex in clause

We are trying to build an toplink expression in java that would produce the following where clause:
where (settlement_id, retailer_id, site_id, end_read_datetime, txn_datetime)
     in (select settlement_id, retailer_id, site_id, end_read_datetime, max(txn_datetime)
               from tlsa_dim
     where end_read_datetime
     BETWEEN to_date('1/1/2002 00:00:01','mm/dd/yyyy hh24:mi:ss')
                    AND to_date('1/9/2002 00:00:00','mm/dd/yyyy hh24:mi:ss')
               and site_id = '0040473041023'
          group by settlement_id, retailer_id, site_id, end_read_datetime )
We have created a reportquery to represent the internal sub query, but
cannot seem to find how to tell the ExpressionBuilder to get 5 fields together
before the .in(reportQuery).
Anyone have any ideas?          
here is our java code
public static ReportQuery getReportQueryForSiteIdAndEffectiveDateRangeAndMaxHistoricalStartDate() throws DataIntegrityException {
ExpressionBuilder aBuilder = new ExpressionBuilder();
ReportQuery query = new ReportQuery(aBuilder);
query.setReferenceClass(Dim.class);
query.addAttribute("settlementId", aBuilder.get("settlementId"));
query.addAttribute("retailerId", aBuilder.get("retailerId"));
query.addAttribute("siteId", aBuilder.get("siteId"));
query.addAttribute("endReadDateTime", aBuilder.get("endReadDateTime"));
query.addMaximum("max-txndatetime", aBuilder.get("historicalStartDate"));
query.setSelectionCriteria(equalsSiteId.and(greaterThanEqualtoEffectiveStart.and(lessThanEqualtoEffectiveEnd)));
query.addGrouping(aBuilder.get("settlementId"));
query.addGrouping(aBuilder.get("retailerId"));
query.addGrouping(aBuilder.get("siteId"));
query.addGrouping(aBuilder.get("endReadDateTime"));
// Vector reports = (Vector) session.executeQuery(query);
return query;
public static Expression forSiteIdAndEffectiveDateRangeAndMaxHistoricalStartDate(String siteId, DateInterval effectiveDateInterval) throws DataIntegrityException {
ExpressionBuilder aBuilder = new ExpressionBuilder();
Expression greaterThanEqualtoEffectiveStart = aBuilder.get("endReadDateTime").greaterThanEqual(effectiveDateInterval.getStartDate());
Expression lessThanEqualtoEffectiveEnd = aBuilder.get("endReadDateTime").lessThanEqual(effectiveDateInterval.getEndDate());
Vector parameterVector = new Vector();
// trying a vector, but no luck
parameterVector.addElement(aBuilder.get("settlementId"));
parameterVector.addElement(aBuilder.get("retailerId"));
parameterVector.addElement(aBuilder.get("siteId"));
parameterVector.addElement(aBuilder.get("endReadDateTime"));
parameterVector.addElement(aBuilder.get("historicalDateRange").get("historicalStartDate"));
Expression inMaxGroup = aBuilder.get(parameterVector).in(getReportQueryForSiteIdAndEffectiveDateRangeAndMaxHistoricalStartDate());
Expression equalsSiteid = forSiteId(aBuilder, aSiteId);
return equalsSiteid.and(inMaxGroup);
public static Expression forSiteId(ExpressionBuilder aBuilder, String aSiteId){
Expression equalsSiteId = aBuilder.get("siteId").equalsIgnoreCase(aSiteId);
return equalsSiteId;

There is no expression support for this. You'll have to use SQL.
Here is a thread of an example using Having with report queries.
Re: How to build SQL Where clause "Having" using Toplink ExpressionBuilder
- Don

Similar Messages

  • How to SQL intersect using Toplink expressions

    I try to do this SQL intersect
    SELECT part_k FROM ATTR_VALUE
    where commodity_n ='dab badge' and attribute_n='Badge Width' and attribute_value_x='10'
    INTERSECT
    SELECT part_k FROM ATTR_VALUE
    where commodity_n='dab badge' and attribute_n='Brand Logo' and attribute_value_x='Jaguar'
    using the following Toplink expressions:
    Expression e1 = builder.get("commodity").equal("dab badge")
    .and(builder.get("attribute").equal("Badge Width"))
    .and(builder.get("value").equal("10"));
    Expression e2 = builder.get("commodity").equal("dab badge")
    .and(builder.get("attribute").equal("Brand Logo"))
         .and(builder.get("value").equal("Jagua"));
    Expression myExpression = e1.and(e2);
    However, this would not give me the correct result.
    Any suggestions would be greatly appreicated.

    Right, TopLink doesn't have an Intersect operator. If it did, you might still get the same problem unless you are using a report query to return only the "part_k" value instead of an object since attribute_n cannot have a value of both 'Badge Width' and 'Brand Logo' at the same time.
    You can get the part_k values or the objects from the ATTR_VALUE
    table by using a report query for the second expression as a subquery to the IN clause. Something like
      ReportQuery subquery = new ReportQuery(yourclass.class);
      ExpressionBuilder subBuilder = subquery.getBuilder();
      Expression e2 = subBuilder.get("commodity").equal("dab badge").and(subBuilder.get("attribute").equal("Brand Logo")).and(subBuilder.get("value").equal("Jagua"));
      subquery.setSelectionCriteria(e2);
      subquery.addAttribute("partk");
      Expression myExpression = e1.and( builder.get("partk").in(subquery) );Regards,
    Chris

  • Why Scalar Subquery expression cannot be used in HAVING clauses?

    Hi All,
    I'm new to SQL. I'm confused with Scalar Subquery.
    Is there anyone who can answer me why Scalar Subquery expression cannot be used in HAVING clauses.
    Can you show me a example?
    Thanks very much,
    Xianyi.Ye
    Edited by: 908428 on 2012-1-16 下午7:24

    Hi,
    908428 wrote:
    Hi Frank,
    Thank you for your quick reply. I also agree with your point.
    But when I read the book, "OCA Oracle Database SQL Certified Expert Exam Guide",( link to illegal copies of book removed by moderator )
    on Page 359, it said that
    Scalar subquery expressions cannot be used in the following locations:
    1. In CHECK constraints
    2. In GROUP BY clauses
    3. In HAVING clauses
    4. In a function-based index (which is coming up in Chapter 11)
    5. As a DEFAULT value for a column
    6. In the RETURNING clause of any DML statement
    7. In the WHEN conditions of CASE
    8. In the START WITH and CONNECT BY clauses, which we discuss in
    Chapter 16.7 and 8 are wrong. Scalar sub-queries can be used in WHEN conditions and START WITH and CONNECT BY clauses. (At least in Oracle 10.2. Is the book based on some earlier version?)
    Edited by: BluShadow on 17-Jan-2012 09:08

  • How to Query Multiple Fields from different Tables using Toplink Expression

    Hi,
    I am trying to prepare an Oracle Toplink Expression to qurey the multiple columns of different tables. the query as following. Please can anyone help?
    SELECT CYCLE.CYCLE_ID,
    CYCLE.ASPCUSTOMER_ID,
    CYCLE.FACILITYHEADER_ID,
    CYCLE.ADDUSER,
    ASP.FIRSTNAME || ' ' || ASP.LASTNAME ADDUSERNAME,
    CYCLE.ADDDATE,
    CYCLE.LASTUPDATEUSER,
    ASP.FIRSTNAME || ' ' || ASP.LASTNAME LASTUPDATEUSERNAME,
    CYCLE.LASTUPDATEDATE,
    CYCLE.CYCLENAME,
    CYCLE.CYCLENUMBER,
    CYCLE.DESCRIPTION
    FROM CYCLE,ASPUSER ASP
    WHERE CYCLE.ADDUSER = ASP.ASPUSER_ID
    and then i want to send that expression to readAllObjects method as a parameter
    Expression exp = (..............this is the required qurey expression...................)
    Vector employees = session.readAllObjects(getClass(), exp);
    thanks,

    You havent given any information on the mapping between Cycle and Asp. I presume there is a one to one mapping between them. Also it appears there is no "WHERE" clause to limit the number of cycles being retrieved. If that is the case then I presume you want to load all cycles in the system.
    Thats just a clientSession.readAllObjects(Cycle.class). If you have indirection turned on the Asp should get loaded when you do a cycle.getAsp().
    I presume that SQL you posted loads all the columns of CYCLE and ASP. If you are interested in a subset of CYCLE or ASP then you should do a ReportQuery or partial object read.
    Hi,
    I am trying to prepare an Oracle Toplink Expression
    to qurey the multiple columns of different tables.
    the query as following. Please can anyone help?
    SELECT CYCLE.CYCLE_ID,
    CYCLE.ASPCUSTOMER_ID,
    CYCLE.FACILITYHEADER_ID,
    CYCLE.ADDUSER,
    ASP.FIRSTNAME || ' ' || ASP.LASTNAME ADDUSERNAME,
    CYCLE.ADDDATE,
    CYCLE.LASTUPDATEUSER,
    ASP.FIRSTNAME || ' ' || ASP.LASTNAME
    LASTUPDATEUSERNAME,
    CYCLE.LASTUPDATEDATE,
    CYCLE.CYCLENAME,
    CYCLE.CYCLENUMBER,
    CYCLE.DESCRIPTION
    FROM CYCLE,ASPUSER ASP
    WHERE CYCLE.ADDUSER = ASP.ASPUSER_ID
    and then i want to send that expression to
    readAllObjects method as a parameter
    Expression exp = (..............this is the required
    qurey expression...................)
    Vector employees = session.readAllObjects(getClass(),
    exp);
    thanks,

  • Use of EXISTS clause in Interface

    I want to build an interface from one table but using an exist clause to check the data change in the same table.
    In SQL statement it can be expressed as follows
      SELECT PB.PROJECT_KEY, COUNT (DISTINCT DW_PROJECT_BUILDING_KEY)
        FROM DW_PROJECT_BUILDING PB
       WHERE     EXISTS
                    (SELECT 1
                       FROM DW_PROJECT_BUILDING PB1
                      WHERE     PB1.PROJECT_KEY = PB.PROJECT_KEY
                            AND PB1.RECORD_STATUS_ID = 1)
             AND PB.RECORD_STATUS_ID = 1
             AND TRUNC (PB.LOAD_DT) >= '03-OCT-2013'
    GROUP BY PB.PROJECT_KEY;
    How can I build this SQL with exists clause in the interface ?
    Thanks

    Create the interface with DW_PROJECT_BUILDING table and give this table a name PB.
    Now put one filter on the table with the conditions that you have just mentioned in the query above, with the exist statement.
    I assume data from this table is targeted into one more aggregated table: here is the definition for the table:
    CREATE TABLE PROJECT_BUILDING_AGGR
    (PROJ_BUILD_KEY VARCHAR2(20),
    PROJECT_KEY varchar2(20));
    perform mapping like :
    PROJECT_KEY=PB.PROJECT_KEY
    PROJ_BUILD_KEY=count(distinct PB.DW_PROJECT_BUILDING_KEY)
    Select IKM as IKM SQL control append.
    FLOW control as false.
    run the interface, it is giving something like this for me, I hope this is according to your requirement:
    insert into
    ORACLE_SOURCE.PROJECT_BUILDING_AGGR
    PROJ_BUILD_KEY,
    PROJECT_KEY
    select
        PROJ_BUILD_KEY,
    PROJECT_KEY  
    FROM (
    select
    count(distinct PB.DW_PROJECT_BUILDING_KEY) PROJ_BUILD_KEY,
    PB.PROJECT_KEY PROJECT_KEY
    from
    ORACLE_SOURCE.DW_PROJECT_BUILDING   PB
    where
    (1=1)
    And (EXISTS
                    (SELECT 1
                       FROM DW_PROJECT_BUILDING PB1
                      WHERE     PB1.PROJECT_KEY = PB.PROJECT_KEY
                            AND PB1.RECORD_STATUS_ID = 1)
             AND PB.RECORD_STATUS_ID = 1
             AND TRUNC (PB.LOAD_DT) >= '03-OCT-2013')
    Group By PB.PROJECT_KEY
    )    ODI_GET_FROM

  • How to use complex function as condition in Oracle Rule Decision Table?

    How to use complex function as condition in Oracle Rule Decision Table?
    We want to compare an incoming date range with the date defined in the rules. This date comparison is based on the input date in the fact & the date as defined for each rule. Can this be done in a decision table?

    I see a couple of problems here.
    First, what you posted below is not a syntactically valid query. It seems to be part of a larger query, specifically, this looks to be only the GROUP BY clause of a query.
    Prabu ammaiappan wrote:
    Hi,
    I Have a group function in the Query. Below is the Query i have used it,
    GROUP BY S.FREIGHTCLASS,
    R.CONTAINERKEY,
    S.SKU,
    S.DESCR ||S.DESCRIPTION2,
    S.PVTYPE,
    RD.LOTTABLE06,
    R.WAREHOUSEREFERENCE,
    RD.TOLOC,
    R.ADDWHO,
    R.TYPE,
    S.CWFLAG,
    S.STDNETWGT,
    S.ORDERUOM,
    R.ADDDATE,
    C.DESCRIPTION,
    (CASE WHEN P.POKEY LIKE '%PUR%' THEN 'NULL' ELSE to_char(P.PODATE,'dd/mm/yyyy') END),
    NVL((CASE WHEN R.ADDWHO='BOOMI' THEN RDD.SUPPLIERNAME END),SS.COMPANY),
    RDD.BRAND,
    S.NAPA,
    RD.RECEIPTKEY,
    R.SUSR4,
    P.POKEY,
    RDD.SUSR1,
    r.STATUS, DECODE(RDD.SUSR2,' ',0,'',0,RDD.SUSR2),
    rd.SUSR3Second, the answer to your primary question, "How do I add a predicate with with a MAX() function to my where clause?" is that you don't. As you discovered, if you attempt to do so, you'll find it doesn't work. If you stop and think about how SQL is processed, it should make sense to you why the SQL is not valid.
    If you want to apply a filter condition such as:
    trunc(max(RD.DATERECEIVED)) BETWEEN TO_DATE('01/08/2011','DD/MM/YYYY') AND TO_DATE('01/08/2011','DD/MM/YYYY')you should do it in a HAVING clause, not a where clause:
    select ....
      from ....
    where ....
    group by ....
    having max(some_date) between this_date and that_date;Hope that helps,
    -Mark

  • Mapping feature for queries that cannot be expressed using JDO QL

    In the "Java Data Objects vs. Entity Beans" thread at theserverside.com,
    there was a question concerning the ways to use a query that cannot be
    expressed using JDO QL (for example SQL requests having no equivalent) .
    Among the possibilities mentionned in his answers, Craig Russel said
    that a JDO implementation could map an SQL query to a Java class
    directly :
    "This might be done by a JDO vendor who mapped a user-specified SQL
    query to a JDO PC class. For example, if you have a DEPARTMENT table
    that you want to write an aggregate query for "SELECT D.DEPTID,
    MAX(E.SALARY) FROM DEPARTMENT D, EMPLOYEE E WHERE D.DEPTID = E.DEPTID".
    You would map this query to a JDO PC class DepartmentMaxSalary which has
    a key field deptid and a non-key field maxSalary. The key class
    DepartmentMaxSalaryKey has a key field deptid.
    Now, construct an instance of the key class:
    DepartmentMaxSalaryKey dk = new DepartmentMaxSalaryKey(100);
    DepartmentMaxSalary d = pm.getObjectById(dk);
    System.out.println ("Department " + d.getDeptid()
    + " has max salary of " + d.getMaxSalary());
    When the getObjectById is executed a hollow instance of
    DepartmentMaxSalary is constructed by the PersistenceManager. When the
    d.getMaxSalary() is executed, the implementation of the method accesses
    the maxSalary field which causes the PersistenceManager to executes the
    query and return the result into the field.
    No implementation to my knowledge currently offers this kind of mapping,
    but certainly some will in future."
    Do you consider in providing this kind of mapping feature in Kodo ?
    Thanks in advance.

    patrice thiebaud <[email protected]> writes:
    In the "Java Data Objects vs. Entity Beans" thread at theserverside.com,
    there was a question concerning the ways to use a query that cannot be
    expressed using JDO QL (for example SQL requests having no equivalent) .
    Among the possibilities mentionned in his answers, Craig Russel said
    that a JDO implementation could map an SQL query to a Java class
    directly :
    "This might be done by a JDO vendor who mapped a user-specified SQL
    query to a JDO PC class. For example, if you have a DEPARTMENT table
    that you want to write an aggregate query for "SELECT D.DEPTID,
    MAX(E.SALARY) FROM DEPARTMENT D, EMPLOYEE E WHERE D.DEPTID = E.DEPTID".
    You would map this query to a JDO PC class DepartmentMaxSalary which has
    a key field deptid and a non-key field maxSalary. The key class
    DepartmentMaxSalaryKey has a key field deptid.
    Now, construct an instance of the key class:
    DepartmentMaxSalaryKey dk = new DepartmentMaxSalaryKey(100);
    DepartmentMaxSalary d = pm.getObjectById(dk);
    System.out.println ("Department " + d.getDeptid()
    + " has max salary of " + d.getMaxSalary());
    When the getObjectById is executed a hollow instance of
    DepartmentMaxSalary is constructed by the PersistenceManager. When the
    d.getMaxSalary() is executed, the implementation of the method accesses
    the maxSalary field which causes the PersistenceManager to executes the
    query and return the result into the field.
    No implementation to my knowledge currently offers this kind of mapping,
    but certainly some will in future."
    Do you consider in providing this kind of mapping feature in Kodo ?Patrice,
    Sorry for the delay responding to this question. The thread dropped out
    of my awareness until Rakesh's followup question today.
    We do not currently plan on providing a mechanism for configuring JDO
    objects to load themselves from arbitrary SQL queries at this point. The
    example above seems a little contrived, for a few reasons:
    - Presumably, this aggregate salary object would be read-only.
    Read-only JDO fields/objects are a whole separate topic that we
    have chosen not to address just yet.
    - Where would the complex SQL statement go? Putting it in the
    metadata seems less than ideal, as this would make for a hideous
    metadata file, and even more complexity and more debugging
    problems than using direct JDBC SQL calls. Putting the SQL
    statement into the class also seems awkward.
    - Kodo provides a mechanism for obtaining a connection to the data
    store. When aggregate info are needed or complex,
    non-object-oriented queries must be executed, standard JDBC calls
    to the data store are probably the most appropriate approach, as
    they give you complete access to your data store.
    If we see a significant interest in these capabilities, then we may
    consider them for a future release.
    Thanks in advance.Again, I apologize for the time delay in my response. I hope that this
    answers your questions.
    -Patrick
    Patrick Linskey [email protected]
    SolarMetric Inc. http://www.solarmetric.com

  • Edit a TopLink Expression

    Hi. I am design a application in Jdeveloper 11g, but i have a problem with a try to edit a toplink expression a first argument, in the button edit I click in this button but nothing happend. Why happend this, i need edit this first argument but i can not.
    Thanks...

    I am also having this problem using JDevloper 11g Update 2 for OSX. The Expression Builder works fine on smaller projects but chokes on larger ones. It also doesn't seem to work for the Batch Read Attributes and Joined Attributes buttons.
    The following error shows up in my console:
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] Exception in thread "AWT-EventQueue-0"
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] java.lang.StackOverflowError
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] at java.lang.StringBuffer.<init>(StringBuffer.java:104)
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] at sun.text.normalizer.ReplaceableString.<init>(ReplaceableString.java:46)
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] at sun.text.normalizer.ReplaceableUCharacterIterator.<init>(ReplaceableUCharacterIterator.java:44)
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] at sun.text.normalizer.UCharacterIterator.getInstance(UCharacterIterator.java:66)
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] at sun.text.normalizer.NormalizerBase.<init>(NormalizerBase.java:559)
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] at sun.text.normalizer.NormalizerBase.<init>(NormalizerBase.java:1563)
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] at java.text.CollationElementIterator.<init>(CollationElementIterator.java:105)
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] at java.text.RuleBasedCollator.getCollationElementIterator(RuleBasedCollator.java:303)
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] at java.text.RuleBasedCollator.compare(RuleBasedCollator.java:346)
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] at oracle.toplink.workbench.utility.node.Node$1.compare(Node.java:436)
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] at oracle.toplink.workbench.utility.node.Node$1.compare(Node.java:428)
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] at java.util.Arrays.mergeSort(Arrays.java:1270)
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] at java.util.Arrays.mergeSort(Arrays.java:1281)
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] at java.util.Arrays.mergeSort(Arrays.java:1282)
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] at java.util.Arrays.mergeSort(Arrays.java:1281)
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] at java.util.Arrays.sort(Arrays.java:1210)
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] at java.util.Collections.sort(Collections.java:159)
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] at oracle.toplink.workbench.mappingsmodel.mapping.relational.MWAbstractTableReferenceMapping.subQueryableElements(MWAbstractTableReferenceMapping.java:455)
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] at oracle.toplink.workbench.mappingsmodel.mapping.relational.MWAbstractTableReferenceMapping.isLeaf(MWAbstractTableReferenceMapping.java:447)
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] at oracle.toplink.workbench.mappingsplugin.ui.query.relational.QueryableTreeModel.getChild(QueryableTreeModel.java:72)
    30/04/09 11:59:07 AM [0x0-0x113113].oracle.ide.boot.Launcher[3761] at oracle.toplink.workbench.uitools.swing.Tree.expandAllNodes(Tree.java:163)

  • Case stament use in where clause  grive error

    i want to use this conditions but gives error. Please give me the solution of it
    WHERE
    CASE
    WHEN CANCELLED_DATE IS NULL THEN
    TO_DATE(INV_GL_DATE,'DD-MON-YY') <= TO_DATE (:P_DATE1,'DD-MON-YY')
    ELSE
    TO_DATE(INV_GL_DATE,'DD-MON-YY') >= TO_DATE(:P_DATE1,'DD-MON-YY')
    END) --- <= TO_DATE(:P_DATE1,'DD-MON-YY')

    Hi,
    Remember that a CASE expression always evaluates to a single value in one of the SQL datatypes, such as VARCHAR2, NUMBER or DATE. (There is no Boolean datatype in SQL.)
    You can't say
    WHERE   CASE ... END;for the same reason that you can't say
    WHERE   'Hello, world!';orWHERE   100;or
    WHERE   SYSDATE;CASE expressions are really valuable because they allow you do perform IF-THEN-ELSE logic in places where you normally can't, like the SELECT clause.
    The WHERE clause is a place where you can perform IF-THEN-ELSE logic anyway, so there's rarely a need for a CASE expression in a WHERE clause. It's just as efficient and just as clear (if not more so) to put all your conditions directly in the WHERE clause, like Max demonstrated.
    Edited by: Frank Kulash on Feb 26, 2010 10:13 AM
    user11995078 wrote:
    Thanks Dear But how can we use with case and decodeWhy do you want to?
    CASE does not help in this problem, any more than regular expressions or CONNECT BY or MODEL help. They are all great tools for particular jobs, but not for this job. Asking "How can I use CASE to do this?" Is like asking "How can I use a hammer to tighten a bolt?" Perhaps there is a way, but it's likely to be contrived and ridiculous.
    Here's the least ridiculous way I can think of:
    WHERE     ( TO_DATE (INV_GL_DATE, 'DD-MON-YY') 
         - TO_DATE (:P_DATE1,     'DD-MON-YY')
         ) * CASE
                 WHEN  cancelled_date  IS NULL  THEN  1
                    `                            ELSE -1
             END <= 0

  • Using for update clause in VPD(Virtual Private Databases)

    Hi,
    We are using for update clause in our procedure to explicitly lock rows in a particular table as shown below:
    SELECT AMOUNT FROM INTERFACE_TABLE
    INTO T_Amount
    WHERE ROWID = :B1
    FOR UPDATE OF BANK_ACCOUNT_NUM NOWAIT;
    But this statement is giving the following error in VPD:
    ORACLE error 1733 in FDPSTP
    Cause: FDPSTP failed due to ORA-01733: virtual column not allowed here.
    We need to lock rows in that particular table until the commit is issued,so as to prevent the updation of the rows which are being processed.
    Is there any other way in which this can be achieved.
    Thanks & Regards,
    Brahmendra Kashyap

    From the docs, which you didn't read:
    ORA-01733 virtual column not allowed here
    Cause: An attempt was made to use an INSERT, UPDATE, or DELETE statement on an expression in a view.
    Action: INSERT, UPDATE, or DELETE data in the base tables, instead of the view.
    Can you explain why you didn't read the docs? I'm just curious why so many people do absolutely nothing to resolve their problem (they would learn Oracle by doing so) and request to be spoon fed.
    Sybrand Bakker
    Senior Oracle DBA
    Experts: those who did read the documentation.

  • SQL query from toplink expression

    Hi,
    I have a oracle.toplink.expressions.Expression object with me which has been created using oracle.toplink.expressions.ExpressionBuilder. I want to find its equivalent SQL query(say select emp.empname,emp.empId from employee emp) which will be fired in order to fetch data i.e. find its equivalent Statement/PreparedStatement or anything which will help me obtain the raw SQL statement about to be fired.
    Please let me know if there is any soln.
    Thanks,
    Adithya.

    You can create ReadAllQuery with the expression and get the query's SQL using query.prepareCall() and then query.getSQLString().
    James : http://www.eclipselink.org

  • Recursive joins / how to define query using connect by clause

    Hi,
    I have a table A have 1-1 reltionship with table Employee
    Structure of table is as follows
    Table A
    id name employee_id
    100 aa 1
    200 bb 2
    300 cc 3
    400 dd 4
    500 ee 5
    Table Employee
    id parent_id
    1 null
    2 1
    3 2
    4 3
    5 1
    6 1
    I want to get all records from A table whose employee_id is equal to 2 or (recursive)decendants/child of employee with id 2 (i.e. employee with id 2,3,4 )
    i.e I want recursively join where in I get records from table A as
    id name employee_id
    200 bb 2
    300 cc 3 (because it is child of employee with id 2)
    400 dd 4 (becaue it is child of employee with id 3 which is child of 2)
    I know we can use In clause , but it will be performance wise not good.
    Can we do it in Toplink without using IN clause?
    Oracle has connect by clause, but other database might not have this caluse. So how can write a toplink query which can run on any database.
    Any help is highly appreciated.
    Thanks a lot.

    You can use TopLink's Hierarchical Query support but this only works with Oracle DB as it relies on the database to perform the query.
    --Shaun                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • ADF BC equivalent of TopLink Expressions

    Hi,
    I'm looking for equivalent of TopLink Expressions in ADF BC world.
    Does such thing exist ?
    http://download-uk.oracle.com/otn_hosted_doc/ias/preview/web.1013/b13593/expres.htm

    Hi,
    the link you provide doesn't exist. I guess you mean http://www.oracle.com/technology/products/ias/toplink/doc/1013/main/_html/expres.htm
    ADF BC works similar but does not have object oriented expressions that you use. E.g. to filter a query you use ViewCriteria or bind variables in the query itself
    Frank

  • GET_UTC_DATE() and GET_UTC_TIMESTAMP() with Toplink Expression

    Hi All,
    I have a requirement which needs me to do some manipulation with dates. I am writing a report query and need to use the get_utc-date() function. What is the equivalent using the toplink expression builder?
    An example of such a query should generate the following SQL:
    SELECT order_no FROM vista_order_transfer vot where vot.updated_timestamp < get_utc_date() - 30. I could not figure out how to use the expression builder to build the get_utc_date() - 30 part of this SQL.
    Any help would be gratly appreciated.
    Roland.

    There is a currentDate() method on Expression which will return the current date, but this is SYSDATE not UTC. To call this function you can use the getFunction() method on the ExpressionBuilder.
    i.e.
    ExpressionBuilder builder = new ExpressionBuilder();
    Expression expression = builder.get("updatedTimestamp").lessThan(ExpressionMath.subtract(builder.getFunction("GET_UTC_DATE"), 30));
    There is also an Expression method postfixSQL() that will let you append any SQL you wish to the expression.

  • OPEN CURSOR using a WITH clause in the select query

    Hi,
    I am using Oracle 9i. I have a requirement where I have a REFCURSOR as an OUT parameter for my procedure. I have declared the TYPE and created the procedure.
    In the procedure, I am using OPEN <cursor_name> FOR <query>;
    Ideally this works in most of the cases that I have tried earlier. However, in the current case I am using a WITH clause in my query to get the results.
    I need help in understanding if the above mentioned syntax would not allow me to use the WITH clause in the query.

    What error do you get , seems to work ok for me on 10g
    SQL> begin
      2  open :cv for 'with x as (select * from emp)  select * from x';
      3  end;
      4  /
    PL/SQL procedure successfully completed.
    SQL> print :cv
         EMPNO
    ENAME
    JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7521
    WARD
    SALESMAN        7698 22-FEB-81       1250        500         30
          7566
    JONES
    MANAGER         7839 02-APR-81       2975                    20
         EMPNO

Maybe you are looking for

  • Vendor Open Item Was Not Offset After a Replacement Check

    Hi FI Guru, We have an issue with vendor replacement check.  Our vendor open item still apears in FBL1N after a replacement check is paid.  We initially issued a check against a vendor invoice and we had to void that check because due to check printi

  • How to differentiate a packing type for Finished goods based on which customer will be invoiced ?

    I need a little expertise The requirement for my organization is Certain Finish goods packing. Currently certain, Finished goods packaging items when send to Customer, is charged for the packaging items like Pallets , Q- Bit Boxes. There will be a de

  • DVD's with no VIDEO_TS folders- How do I back them up?

    Recently a few friends have been sending me disks made on stand alone DVD recorders. The DVD's usually have the name "DVDVIDEORECORDER". Surprisingly, these DVD's have no VIDEO_TS folders, though they play fine in a DVD player or my Mac. I went searc

  • Error with boot

    Hi all, i get an error when I start a Sun v240 server. i took this server over from someone else, but can not seem to install the OS. I get the following error when booting : "Boot device: disk File and args: WARNING: unknown command 'B' on line 87 o

  • Recon account and GL balanc

    Hi I am checking the opening  balance (c/forward balnce)for the year 2010 between the customers the reconciliation account assigned to the customers.I see that the balance int he reconciliation GL account is more than lthe customer balance. I know th