Converting Oracle query to Hibernate

0 down vote favorite
share [fb] share [tw]
considering I have Txn_Summ_Dec as a domain object (Entity) with all the fields used in the query how would I convert the SQL query below to Hibernate Query (ether HQL or Criteria api)..
What the query does: Given a date range as input the query counts distinct users grouped by date, eventdesc and left joins with all the dates in the date range so resultset contains user counts for all dates in the range for all events.
select
    d.dateInRange as dateval,
    eventdesc,
    nvl(td.dist_ucnt, 0) as dist_ucnt
from (
    select
        to_date('03-NOV-2011','dd-mon-yyyy') + rownum - 1 as dateInRange
    from all_objects
    where rownum <= to_date('31-DEC-2011','dd-mon-yyyy') - to_date('03-NOV-2011','dd-mon-yyyy') + 1
) d
left join (
    select
        currentdate,
        count(distinct(grauser_id)) as dist_ucnt,
        eventdesc
    from
        txn_summ_dec
    group by currentdate, eventdesc
) td on td.currentdate = d.dateInRange order by d.dateInRange ascThe query runs successfully on oracle returning the required result
Edited by: EJP on 30/01/2012 20:12: added {noformat}{noformat} tags on your behalf, to make your code legible.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

ow006921 wrote:
I think the question is, why would you want to convert a complex query like that to Hibernate syntax? Hibernate is an application layer superimposed over SQL and JDBC, intended to simplify your coding and provide a more object-oriented interface, best suited to simple cases of table i/o. It does not improve upon or substitute for the power of SQL.
For something this complex, I would capture the SQL in a view or stored procedure on the database and call that from the client, either with Hibernate or straight JDBC.
Just my opinion.
Howard HydeYour opinion is very valid, but moot in this case. Upon my reply I expected one of two things:
- silence (what I got; the OP looks for an easier way to make someone else solve his problems)
- a second attempt at outsourcing work by posting something along the lines of "Please. I read the linked article but I couldn't figure it out. Can you please post some sample code?"
When you've been around this forum for a while, you learn to identify the people who don't have a real problem other than being lazy.

Similar Messages

  • Converting Oracle query to Sql Server with date manipulation

    The following SSIS statement works great in Oracle, and it parses successfully in the "Sql Task" window. In Oracle it returns
    this result:
    FROM_DT              THRU_DT
    16-Jan-2014      23-Jan-2014
    select
    case
    when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=7 then to_date('24'||to_char(add_months(sysdate,-1),'mmyyyy'),'ddmmyyyy')
    when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=15 then to_date('01'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
    when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=23 then to_date('08'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
    else to_date('16'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
    end as from_dt,
    case
    when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=7 then trunc(last_day(add_months(sysdate,-1)))
    when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=15 then to_date('07'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
    when to_char(to_date(sysdate,'dd-mon-yyyy'),'dd') <=23 then to_date('15'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
    else to_date('23'||to_char(sysdate,'mmyyyy'),'ddmmyyyy')
    end as thru_dt
    from sys.dual
    How can I convert this to Sql Server ?

    >>You mean you get the data from Oracle and tries to insert it into SQL Server?
    - no, sorry, I want to convert the syntax to Sql Server
    >>Are
    you running the query in OLEDB provider connected to the Oracle's database?
    - yes, this works fine now (after fixing this redundancy:
    to_char(to_date(sysdate,'dd-mon-yyyy'),'dd')change toto_char(sysdate,'dd')

  • Converting MS SQL Server Query to Oracle Query

    Hi There,
    I've a strange problem. My project uses both MS SQL Server and Oracle server at run time. I've lot of queries which are written in MS SQL Style. Now, iam planning to write a helper class whic converts MS SQL Query to Oracle Query. Please Help me if any one has that kind of Helper with you.
    Thanks And Regards,
    Sasi Kanth

    That is why persistence applications like Hibernate or
    CMP get used for apps that will use more than one DB,
    but it takes upfront planning.
    If you have a set of automated unit tests that work
    with SQL Server, they will be a big help in getting
    your Oracle code up and running.Indeed - JUnit and Ant would be a big help here.
    It sounds like you have SQL in your JSPs, that will
    work against you as well if so. If you are using a
    DAO pattern, this will be much easier, as you can
    re-implement each DAO for Oracle.If you'd layered this app properly, you might just implement an OracleDAOFactory and be done with it. Interfaces and a DAO layer would go a long way.
    This is why layering is such a good idea. It isolates changes in a smaller subset of classes.
    But your problem sounds pretty big. It'd be daunting even if it were well designed.

  • Converting Oracle XML Query Result in Java String by using XSU

    Hi,
    I have a problem by converting Oracle XML Query Result in Java
    String by using XSU. I use XSU for Java.
    For example:
    String datum=new OracleXMLQuery(conn,"Select max(ps.datum) from
    preise ps where match='"+args[0]+"'");
    String datum1=datum;
    I become the following error:
    Prototyp.java:47: Incompatible type for declaration. Can't
    convert oracle.xml.sql.query.OracleXMLQuery to java.lang.String.
    Can somebody tell me a method() for converting to solve my
    problem??????
    Thanks

    Hmmm.. Pretty basic just look at the example:
    OracleXMLQuery qry = new OracleXMLQuery(conn,"Select max(ps.datum) from preise ps where match='"+args[0]+"'");
    String xmlString = qry.getXMLString();
    Hi,
    I have a problem by converting Oracle XML Query Result in Java
    String by using XSU. I use XSU for Java.
    For example:
    String datum=new OracleXMLQuery(conn,"Select max(ps.datum) from
    preise ps where match='"+args[0]+"'");
    String datum1=datum;
    I become the following error:
    Prototyp.java:47: Incompatible type for declaration. Can't
    convert oracle.xml.sql.query.OracleXMLQuery to java.lang.String.
    Can somebody tell me a method() for converting to solve my
    problem??????
    Thanks

  • How to convert Access query to Oracle?

    I am trying to convert this query into an Oracle 8i query: -
    SELECT *
    FROM EMPLOYEE
    LEFT JOIN ATTENDANCE ON EMPLOYEE.EMPID = ATTENDANCE.EMPID
    WHERE ATTENDANCE.COL1="#"
    AND ATTENDANCE.COL2>=#1/1/2007#
    AND ATTENDANCE.COL2<Now()
    GROUP BY EMPLOYEE.EMPID, EMPLOYEE.EMPNO;
    How do I put the above query in plain Oracle join operator (+) notation? Thanks for the help.

    Hi,
    Let us take a look at the solution you had suggested -
    EMPLOYEE.EMPID = ATTENDANCE.EMPID (+)
    AND ATTENDANCE.COL1="#"
    AND ATTENDANCE.COL2 >= TO_DATE ('1/1/2007','dd/mm/yyyy')
    AND ATTENDANCE.COL2< SYSDATE;
    Since we are outer joining ATTENDANCE but not using the (+) operator in the later filter conditions; it will still be a normal join i.e. it will not outer join on ATTENDANCE. That is my question.

  • Converting this query to Oracle-Help

    New account as my old email address has changed so I had to create a new one. Sucks!
    Either way can I please get some help with converting the query below to oracle syntax not microsoft sql. Cheers
    select  eventtypeid as Payment_Type,
         sum(commission_amount) as commission_amount,
         startdate as commission_date
    from
    SELECT distinct
              PERIOD.STARTDATE,
              Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE,
    case when Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE in ('2573','185')
         then 'D'
         when Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE in ('1126','1055')
         then 'O'
         when Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE in ('789','4000','785','871','1028','743')
         then 'R'
    else Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE
    end as SDC,
              Master_Usage.GENERICATTRIBUTE2 AS Service_Id,
              Master_Usage.EVENTTYPEID,
              sum(Master_Usage.CONTRIBUTIONVALUE) AS Commission_Amount
    FROM              Master_Usage INNER JOIN PERIOD
                   ON Master_Usage.PERIODSEQ = PERIOD.PERIODSEQ
              INNER JOIN (select distinct
                        lastname,
                        super_distributor_code,
                        distributor_code,
                        participantid,
                        startperiod
                   from Dealer_Hierarchy_107_114
                   where startperiod in ('107','108','110','111','112','114')
                   AND NOT POSITIONTYPEID LIKE 'MI %'
                   and not super_distributor_code = 'null' or distributor_code = 'null') as dealer_hierarchy
                   ON Master_Usage.GENERICATTRIBUTE1 = dealer_hierarchy.PARTICIPANTID and dealer_hierarchy.startperiod in ('107','108','110','111','112','114')
    WHERE          
              (NOT Master_Usage.PRODUCTID = 'IDDV' OR Master_Usage.PRODUCTID IS NULL)
              AND Master_Usage.PERIODSEQ in ('107','108','110','111','112','114')
              and Dealer_Hierarchy.startperiod in ('107','108','110','111','112','114')
              and Master_Usage.NAME not like '%revenue%'
              and Master_Usage.name not like '%GST%'
    group by      PERIOD.STARTDATE,
              Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE,
              Master_Usage.GENERICATTRIBUTE2,
              Master_Usage.EVENTTYPEID
    ) as asf
    group by asf.EVENTTYPEID,
          startdate
    order by commission_amount desc

    please see the bold section,
    could that be the reason ??
    select eventtypeid as Payment_Type,
         sum(commission_amount) as commission_amount,
         startdate as commission_date
    from
    SELECT distinct
              PERIOD.STARTDATE,
              Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE,
    case when Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE in ('2573','185')
         then 'D'
    when Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE in ('1126','1055')
         then 'O'
    when Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE in ('789','4000','785','871','1028','743')
         then 'R'
    else Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE
    end as SDC,
              Master_Usage.GENERICATTRIBUTE2 AS Service_Id,
              Master_Usage.EVENTTYPEID,
              sum(Master_Usage.CONTRIBUTIONVALUE) AS Commission_Amount
    FROM      Master_Usage INNER JOIN PERIOD
                   ON Master_Usage.PERIODSEQ = PERIOD.PERIODSEQ
              INNER JOIN (select distinct
                        lastname,
                        super_distributor_code,
                        distributor_code,
                        participantid,
                        startperiod
                   from Dealer_Hierarchy_107_114
                   where startperiod in ('107','108','110','111','112','114')
                   AND NOT POSITIONTYPEID LIKE 'MI %'
                   and not (super_distributor_code = 'null' or distributor_code = 'null') as dealer_hierarchy
                   ON Master_Usage.GENERICATTRIBUTE1 = dealer_hierarchy.PARTICIPANTID and dealer_hierarchy.startperiod in ('107','108','110','111','112','114')
    WHERE      
              (NOT Master_Usage.PRODUCTID = 'IDDV' OR Master_Usage.PRODUCTID IS NULL)
              AND Master_Usage.PERIODSEQ in ('107','108','110','111','112','114')
              and Dealer_Hierarchy.startperiod in ('107','108','110','111','112','114')
              and Master_Usage.NAME not like '%revenue%'
              and Master_Usage.name not like '%GST%'
    group by      PERIOD.STARTDATE,
              Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE,
              Master_Usage.GENERICATTRIBUTE2,
              Master_Usage.EVENTTYPEID
    ) as asf
    group by asf.EVENTTYPEID,
         startdate
    order by commission_amount desc

  • How to convert Oracle database to XML standard?

    I have a project to convert oracle database to XML standard.And get it to show in webpage.Please tell me for do it.Tell about the way to do it.Tell me some kit to do it.

    Hi,
    otn says like this
    "You can use the XML SQL Utility to generate a DTD based on the schema of the underlying table being queried. You can use the generated DTD as input to the XML Class Generator for Java, which will generate a set of classes based on the DTD elements. You can then write Java code that use these classes to generate the infrastructure behind a web-based form. Based on this infrastructure, the web form will capture user data and create an XML document compatible with the database schema."
    use 'mlsql utility'
    regards
    raghavan

  • Convert Oracle "connect by level 10" into MS SQL server 2005

    I want to convert oracle "SELECT LEVEL R FROM CONNECT BY LEVEL <=10" my bottom requirement is  get 1 to 10 as a dynamic table inside a query.
    Ex: Select id, name, R from names N, (1,2,3,4,5,6,7,8,9,10) R WHERE id < 1000 
    If any one know something regarding this please reply me.
    Thx,
    Buddhika

    Hi Buddhika Jayawardhane ,
    Have you sold your problem? I have the same issue to convert from Oracle into SQL Server:
    SELECT all_steps.to_step_id step_id, rownum step_order
    FROM (
    SElECT 0 from_step_id, steps.step_id to_step_id
    FROM steps
    WHERE steps.is_root = 1
    UNION
    SElECT step_transitions.from_step_id, step_transitions.to_step_id
    FROM step_transitions
    ) all_steps
    CONNECT BY all_steps.from_step_id = PRIOR all_steps.to_step_id
    START WITH all_steps.from_step_id = 0
    Please help me find information how to make it!
    Thanks in advance,
    cores

  • Convert a query form to Creation form.

    We create a normal jspx form and drag and drop a view object normal mode.
    When we open the form first record come
    Then We need to change this form to a creation form with new empty record.
    Form include many custom code.We can't recreate form.
    How can we do it?
    it means how Convert a query form to Creation form?
    we are using jdev 10.1.3.2
    Thanks

    You have to add Create method in PageDef.xml and then add expression in RefreshCondition to invoke it (in executables). For more information see:
    http://download-uk.oracle.com/docs/html/B25947_01/web_form006.htm#CACECCJA
    Kuba

  • Converting oracle join to Ansi sql join

    Hi Guys,
    I am new to SQL and trying to convert the following Oracle query (joins) into ANSI sql joins...Can someone please help me?
    SELECT M.EXTERNALCODE, M.NAME AS MNAME, SC.BIRIM, SM.TRANSACTIONDATE, SMD.AMOUNT,
    SMD.UNITPRICE, SM.ID AS SMID, SMD.ID AS SMDID, F.NAME AS FNAME,
    IFNULL (SMD.AMOUNT, 0, SMD.AMOUNT) * IFNULL (SMD.UNITPRICE, 0, SMD.UNITPRICE) AS TOTALPRICE, SMD.AMOUNT AS RECEIVED_QUANTITY,
    PD.ORDERID, PD.AMOUNT QUANTITY, PO.PROCESSDATE
    FROM STOCKMAINTRANSACTION SM,
    STOCKMAINTRANSACTIONDETAIL SMD,
    MATERIAL M,
    STOCKCARD SC,
    FVSTOCK FVS,
    FIRM F,
    PURCHASEORDER PO,
    PURCHASEORDERDETAIL PD,
    PURCHASEORDERDETAILSUPPLIED PDS
    WHERE SM.ID = SMD.MAINTRANSACTIONID
    AND SMD.MATERIALID = M.ID
    AND SMD.STOCKCARDID = SC.ID
    AND SM.PROPREF = FVS.RECORDID(+)
    AND FVS.FIELDID(+) = 2559
    AND FVS.FLEVEL(+) = 'F'
    AND F.ID(+) = SUBSTR (FVS.FVALUE, 1, 9)
    AND SM.TRANSDEFID in (999,2329,2344,2370,150000903,150005362)
    AND SMD.CANCELLED = 0
    AND SMD.STOCKUPDATED = 1
    AND SMD.ID = PDS.STOCKMAINTRANSACTIONDETAILID
    AND PDS.ORDERDETAILID = PD.ORDERDETAILID
    AND PO.ORDERID = PD.ORDERID
    AND (M.ID = {@MATERIALID@} OR {@MATERIALID@} = 0)
    AND (SM.STOREID = {@STOREID@} OR {@STOREID@} = 0)
    AND (F.ID = {@SUPPLIERID@} OR {@SUPPLIERID@} = 0)
    AND SM.TRANSACTIONDATE BETWEEN {@STARTDATE@} AND {@ENDDATE@}
    ORDER BY F.NAME, M.EXTERNALCODE, SM.TRANSACTIONDATE
    Really appreciate the help!
    Thanks.

    Hi,
    Welcome to the forum!
    To convert to ANSI syntax, replace join conditions in the WHERE clause
    FROM           x
    ,             y
    WHERE         x.x1  = y.y1
    AND           x.x2  = y.y2with ON conditions in the FROM clause:
    FROM           x
    JOIN             y   ON    x.x1  = y.y1
                             AND   x.x2  = y.y2In inner joins, conditions that do not reference 2 tables are not really join conditions, so it doesn't matter if they are in the FROM clause or in the WHERE clause.
    In your case
    SM.TRANSDEFID in (999,2329,2344,2370,150000903,150005362)could be part of a join condition involving sm, or it could be in the WHERE clause. Most people find it clearer if 1-table conditions like this are in the WHERE clause.
    Again, this only applies to inner joins. For outer joins, all conditions that apply to a table that may lack matching rows must be included in the FROM clause, like this:
    LEFT OUTER JOIN  fvstock   fvs  ON   sm.propref       = fvs.recordid
                                    AND  fvs.fieldid  = 2559
                        AND  fvs.flevel   = 'F'Try it.
    If you have trouble, post your best attempt, along with CREATE TABLE and INSERT statements for a little sample data from all the tables involved, and the results you want from that data. Simplify the problem. Post only the tables and columns that you don't know how to handle.
    See the forum FAQ {message:id=9360002}
    user8428528 wrote:
    AND (M.ID = {@MATERIALID@} OR {@MATERIALID@} = 0)
    AND (SM.STOREID = {@STOREID@} OR {@STOREID@} = 0)
    AND (F.ID = {@SUPPLIERID@} OR {@SUPPLIERID@} = 0)
    AND SM.TRANSACTIONDATE BETWEEN {@STARTDATE@} AND {@ENDDATE@}This is not valid Oracle SQL. Is {@MATERIALID@} some kind of variable?

  • Oracle Query to MYSQL query

    Hi,
    How to convert the below oracle query to MYSQL query
    Oracle Query:
    SELECT b.* FROM (SELECT t2.*, MIN(t2.id) over(PARTITION BY t2.rid)ord_num
    FROM (SELECT t1.id, dense_rank() over(ORDER BY nvl(t1.CLI_ID_CLIENT_EXT, 'a'||t1.id)) rid
    FROM CANGEN_MATRICE_BKUP t1) t2) t, (SELECT ROWNUM , b.* FROM CANGEN_MATRICE_BKUP b) b
    WHERE t.id = b.id ORDER BY t.ord_num, b.id
    i dont know howto convert the MYSQL query?
    Please help on this.
    Regards
    Sudhakar P.

    No MySQL haven't analytic functions. But every analytic function can be achieved with simple SQL, just one needs to write more it :)
    So here is a starting point how to emulate analytic functions in MySQL
    http://www.oreillynet.com/pub/a/mysql/2007/03/29/emulating-analytic-aka-ranking-functions-with-mysql.html
    And MySQL haven;t rowids as well, but actually I dont see any sense of it in this particular query.
    Gints Plivna
    http://www.gplivna.eu

  • Query on using Variables in Oracle Query

    Hi
    i am new to Oracle, i have tried extracting data from the Oracle Database using the following Query which includes 1 variable SYSDATE_UTS, however when i try to execute the Query i get an error. Please let me know what am i doing wrong and how can i correct it.
    Error Message
    ORA-06550: line 4, column 1:
    PLS-00428: an INTO clause is expected in this SELECT statement
    Oracle Query
    DECLARE SYSDATE_UTS NUMBER := (sysdate-to_date('19700101','yyyymmdd'))*86400;
    BEGIN
    SELECT
    INCIDENT_NUMBER,
    to_date(to_char((1/86400*REPORTED_DATE)+to_date('19700101','yyyymmdd'),'mm/dd/yyyy hh24:mi:ss'),'mm/dd/yyyy hh24:mi:ss') as REPORTED_DATE_TIME,
    ,GROUP_TRANSFERS
    ,LAST_MODIFIED_BY
    ,to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * LAST_MODIFIED_DATE,'mm/dd/yyyy hh24:mi:ss'),'mm/dd/yyyy hh24:mi:ss') as LAST_MODIFIED_DATE
    ,(to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) as AGE
    ,CASE
    WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 0 AND 1 THEN '0-1 Days'
    WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS, 'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 2 AND 4 THEN '2-4 Days'
    WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 5 AND 9 THEN '5-9 Days'
    WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 10 AND 19 THEN '10-19 Days'
    WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) >20 THEN '20+ Days'
    ELSE 'UNKNOWN'
    END AS AGE_GROUP
    FROM IncidentDataBase
    and STATUS not in (4,5,6)
    and rownum <10;
    END;

    Hi Frank
    i am using the following Oracle Version
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
    PL/SQL Release 10.2.0.5.0 - Production
    CORE     10.2.0.5.0     Production
    TNS for Linux: Version 10.2.0.5.0 - Production
    NLSRTL Version 10.2.0.5.0 - Production
    and Quest Toad for Oracle to write and execute the queries:
    Toad for Oracle Xpert
    Version 10.1.1.8
    The code i am using is:
    variable SYSDATE_UTS NUMBER;
    exec SYSDATE_UTS := (sysdate-to_date('19700101','yyyymmdd'))*86400;
    SELECT
    INCIDENT_NUMBER,
    to_date(to_char((1/86400*REPORTED_DATE)+to_date('19700101','yyyymmdd'),'mm/dd/yyyy hh24:mi:ss'),'mm/dd/yyyy hh24:mi:ss') as REPORTED_DATE_TIME
    ,GROUP_TRANSFERS
    ,LAST_MODIFIED_BY
    ,to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * LAST_MODIFIED_DATE,'mm/dd/yyyy hh24:mi:ss'),'mm/dd/yyyy hh24:mi:ss') as LAST_MODIFIED_DATE
    ,(to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) as AGE
    ,CASE
    WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 0 AND 1 THEN '0-1 Days'
    WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS, 'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 2 AND 4 THEN '2-4 Days'
    WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 5 AND 9 THEN '5-9 Days'
    WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 10 AND 19 THEN '10-19 Days'
    WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) >20 THEN '20+ Days'
    ELSE 'UNKNOWN'
    END AS AGE_GROUP
    FROM IncidentDataBase
    WHERE STATUS not in (4,5,6)
    and rownum <10;
    Notes:
    1. When i put the cursor before "variable" (starting of the query) and execute the script i get an Error: ORA-00900: invalid SQL statement.
    2. When i put the cursor just before "SELECT" i get a pop up.
    a. it is a Toad window which displays the available variables (in this case :SYSDATE_UTS).
    b. gives me a dropdown option to select the type (by default VARCHAR2 is selected).
    c. there is a value field where i need to enter the value for the Variable.
    d. the SQL statement shown in this dilog box does not include the 1st 2 lines
    variable SYSDATE_UTS NUMBER;
    exec SYSDATE_UTS := (sysdate-to_date('19700101','yyyymmdd'))*86400;
    Q: is there something wrong in the syntax i am using?
    Sven W. - I have been using your method all these days, which works just fine. i wanted to know how i could use a variable instead.
    Business Requirement - My whole intent is to calculate the Age of an incident (Difference between "Reported Date" and current date) and to assign Age Groups (0-1 Days, 2-4 Days,....,20+ Days).
    Edited by: 921713 on Mar 19, 2012 12:23 PM

  • Oracle query help

    Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.8.0 - Production
    Report Builder 10.1.2.0.2
    ORACLE Server Release 10.1.0.4.2
    Oracle Procedure Builder 10.1.2.0.2
    Oracle ORACLE PL/SQL V10.1.0.4.2 - Production
    Oracle CORE    10.1.0.4.0    Production
    Oracle Tools Integration Services 10.1.2.0.2
    Oracle Tools Common Area 10.1.2.0.2
    Oracle Toolkit 2 for Windows 32-bit platforms 10.1.2.0.2
    Resource Object Store 10.1.2.0.2
    Oracle Help 10.1.2.0.2
    Oracle Sqlmgr 10.1.2.0.2
    Oracle Query Builder 10.1.2.0.2 - Production
    PL/SQL Editor (c) WinMain Software (www.winmain.com), v1.0 (Production)
    Oracle ZRC 10.1.2.0.2
    Oracle XML Developers Kit 10.1.0.4.2 - Production
    Oracle Virtual Graphics System 10.1.2.0.2
    Oracle Image 10.1.2.0.2
    Oracle Multimedia Widget 10.1.2.0.2
    Oracle Tools GUI Utilities 10.1.2.0.2
    I have enclosed sample data and also table structure. I need help in getting the query.
    select dept_id,proc_code,override_goal,goal_override_date
      from table2
    where goal_override_date between '02-jan-2014' and '11-jan-2014'
       and dept_id = 10
       and proc_code = 'CP'
    select DEPT_ID, PROC_CODE, DAY_SUNDAY, DAY_MONDAY,
           DAY_TUESDAY, DAY_WEDNESDAY, DAY_THURSDAY,
             DAY_FRIDAY, DAY_SATURDAY
      from table1
    where dept_id =10
    and proc_code = 'CP'; 
    Table1  is kind of maintenance table.
    In Table2 values can be overridden.
    Requirement
    Check to see if there is data in table 2 for the date range . If table2 has no value then take value from table1 for that day the date falls into. Any more clarification please ask me.
    Sundays are all zeros.
    I want this data. and the sum for the date range.
    2-jan-2014  - 3
    3-jan-2014  - 3
    4-jan-2014  - 3
    5-jan-2014  - 0
    6-jan-2014  - 1
    7-jan-2014  - 3
    8-jan-2014  - 5
    9-jan-2014  - 5
    10-jan-2014 - 3
    11-jan-2014 - 3
    Sum for the date range has to be 29
    Sample table and data
    CREATE TABLE TABLE1
      DEPT_ID NUMBER NOT NULL,
      PROC_CODE VARCHAR2(2 BYTE) NOT NULL,
      DAY_SUNDAY NUMBER(4) NOT NULL,
      DAY_MONDAY NUMBER(4) NOT NULL,
      DAY_TUESDAY NUMBER(4) NOT NULL,
      DAY_WEDNESDAY NUMBER(4) NOT NULL,
      DAY_THURSDAY NUMBER(4) NOT NULL,
      DAY_FRIDAY NUMBER(4) NOT NULL,
      DAY_SATURDAY NUMBER(4) NOT NULL
    Insert into TABLE1
      (DEPT_ID, PROC_CODE, DAY_SUNDAY, DAY_MONDAY, DAY_TUESDAY,
      DAY_WEDNESDAY, DAY_THURSDAY, DAY_FRIDAY, DAY_SATURDAY)
    Values
      (10, 'CP', 0, 3, 3,
      3, 3, 3, 3);
    COMMIT;
    CREATE TABLE TABLE2
      DEPT_ID NUMBER NOT NULL,
      PROC_CODE VARCHAR2(2 BYTE) NOT NULL,
      OVERRIDE_GOAL NUMBER(4),
      GOAL_OVERRIDE_DATE DATE NOT NULL
    Insert into TABLE2
      (DEPT_ID, PROC_CODE, OVERRIDE_GOAL, GOAL_OVERRIDE_DATE)
    Values
      (10, 'CP', 1, TO_DATE('01/06/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into TABLE2
      (DEPT_ID, PROC_CODE, OVERRIDE_GOAL, GOAL_OVERRIDE_DATE)
    Values
      (10, 'CP', 3, TO_DATE('01/07/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into TABLE2
      (DEPT_ID, PROC_CODE, OVERRIDE_GOAL, GOAL_OVERRIDE_DATE)
    Values
      (10, 'CP', 5, TO_DATE('01/08/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into TABLE2
      (DEPT_ID, PROC_CODE, OVERRIDE_GOAL, GOAL_OVERRIDE_DATE)
    Values
      (10, 'CP', 5, TO_DATE('01/09/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into TABLE2
      (DEPT_ID, PROC_CODE, OVERRIDE_GOAL, GOAL_OVERRIDE_DATE)
    Values
      (10, 'CP', 3, TO_DATE('01/10/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into TABLE2
      (DEPT_ID, PROC_CODE, OVERRIDE_GOAL, GOAL_OVERRIDE_DATE)
    Values
      (10, 'CP', 3, TO_DATE('01/11/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    COMMIT;
    Help is highly appreciated.

    SELECT dates,
           override_goal,
           SUM(override_goal) OVER()
           FROM(SELECT dates,
                       CASE WHEN EXISTS(SELECT 1
                                        FROM table2 t2
                                        WHERE t2.goal_override_date = qry1.dates
                                        AND t2.dept_id = 10
                                        AND t2.proc_code = 'CP')
                            THEN (SELECT override_goal
                                  FROM table2 t2
                                  WHERE t2.goal_override_date = qry1.dates
                                  AND t2.dept_id = 10
                                  AND t2.proc_code = 'CP')
                       ELSE (SELECT DECODE(days,'SUN',day_sunday,
                                                'MON',day_monday,
                                                'TUE',day_tuesday,
                                                'WED',day_wednesday,
                                                'THU',day_thursday,
                                                'FRI',day_friday,
                                                'SAT',day_saturday )
                              FROM table1)
                       END as override_goal
                FROM (SELECT in_dt1+(LEVEL-1) dates,
                             TO_CHAR(in_dt1+(LEVEL-1),'DY') days
                      FROM(SELECT TO_DATE(&from_date,'DD-MON-YYYY') in_dt1,
                                  TO_DATE(&to_date,'DD-MON-YYYY') in_dt2
                                 FROM dual)
                      CONNECT BY LEVEL <= (in_dt2 - in_dt1)+1) qry1);
    Now run the query it will prompt you for the inputs. You can pass the date values and check the result. Otherwise replace &from_date,&to_date with user inputs

  • How can i convert oracle report in excel format using 8i

    hi,
    I want to convert oracle report in excel format using 6i reports. please give the solution with emp table.
    millons of thanks in advance.

    You'll have to use the destype DELIMITEDDATA to render your Report in CSV format. Then set the mime type to Excel. I don't know the exact syntax, so please do a search in metalink for "reports excel" for examples and more info.
    Regards,
    Martin Malmstrom

  • How to convert oracle report in html form into excel form?

    Hi friends !! I m trying to convert oracle 10g report into excel form.Its coming in excel form but not with all formats.How to solve the problem?

    Hello,
    Please give us more information what kind of report(s). Sample example etc.,
    Sri

Maybe you are looking for

  • Using the end routine to populate the Cubes

    Hi BI Gurus, I am having following requirement: DSO: ZODS1  - > This DSO gets all the raw data from Source system. DSO:ZODS4   - >  Updates ZCUBE4        ,ZODS5    - > Updates ZCUBE5 there is no data flow between ZODS1 and  ZODS4                     

  • Skip Error message in submit report

    Hello Gurus, I am using SUBMIT <REPORT> command inside a loop of my calling report. For one record the SUBMIT <report> is throwing an eror message due to which my report is getting stopped by displaying the error message. My requirement is to skip th

  • Calling a function in a form in PL/SQL

    Hi all, i'm workin in Forms ( Oracle 10g) i wonna call a function and i got an error this is my code: declare      x number;      b_min_g number;      b_max_g number; begin      x := check_overlap(:min_g, :max_g, ex2.min_g, ex2.max_g); end; ex2 is a

  • Is multiple inheritence is possible in sap?

    can any one help me? is multiple inheritence possible in sap ? and is one class can extend multiplre interfaces??

  • Why doesn't my apple TV 2 see my new photo albums right away?

    When I create a new photo album to iPhoto, I can't figure out how to get it to show up on Apple TV right away.  It eventually does, but never right away, sometimes it takes days...  The same happens with new events when I import new photos into iPhot