PL/SQL Cartridge with Union Query

I have a pl/sql cartridge, with 3 select queries connected to each other by a "union". These queries basically generate a report from two tables. One of those queries is based on Table 1, and the other two are based on Table 2. What I need to accomplish is that I want to add a condition that restricts the outcome of the query (all three unions as a whole) based on a condition. Say, the condition is table1.param1 = '1'. Now, I'm getting confused with incorporating this condition in query 2 and query 3 which are based on table 2, and don't have the param1. However, both table1 and table 2 have param2 in common. I tried writing something like: (this is just a skeleton of my code)
SELECT param1, PARAM2, OTHER_PARAM
FROM table1
where param1 = '1'
union
select param2, param3, 0 other_param
from table2
where param2 in
(select param2
from table1
where param1 = '1')
union
select param2, param4, param5 other_param
from table2
where param2 in
(select param2
from table1
where param1 = '1');but this doesn't work. Can anyone help me with this query? any help is appreciated.

I think it will help you guys better if I illustrate in more detail. Posting my code below. p1,p2,p3..etc are parameter names. Hope someone will be able to help now.
The original code, before adding the new condition is:
select p1_num,
          p2_date,
          sum(decode(p3,'50',p4,0)) b_amt,
          sum(decode(p3,'10',p4,0)) r_amt,
          sum(decode(p3,'20',p4,0)) d_amt,
          sum(decode(p3,'40',p4,0)) l_amt,
          0 pay_amt,
          0 o_amt,
          0 g_amt,
          0 ot_amt
   FROM table1 t1
   where p1_num = passed_parameter  -- Parameter passed to the cursor
         AND to_char(p2_date, 'mmyyyy')  =  V_pdate  -- V_pdate is a parameter passed to the procedure
         group by p1_num, p2_date
   UNION
   select p1_num,
          p6_date,
          0,
          0,
          0,
          0,
          sum(decode(p7,'2', p8,0)) pay_amt,
          0 o_amt,
          0 g_amt,
          0 ot_amt
   from table2 t2
   where  p1_num = passed_parameter  -- Parameter passed to the cursor
          AND to_char(p6_date, 'mmyyyy')  =  V_pdate  -- V_pdate is a parameter passed to the procedure
          group by p1_num, p6_date
   UNION
   select p1_num,
          p6_date,
          0,
          0,
          0,
          0,
          0 pay_amt,
          sum(decode(substr(p9,1,1),'1',p8,0)) oil_amt,
          sum(decode(substr(p9,1,1),'2',p8,0)) gas_amt,
          sum(decode(substr(p9,1,1),'5',p8,'3',p8,'4',p8,0)) ot_amt
   from table2 t2
   where ((p7 IS NULL) OR (p7 IN ('0','1','3','4')))
         and p1_num = passed_parameter  -- Parameter passed to the cursor
         AND to_char(p6_date, 'mmyyyy')  =  V_pdate  -- V_pdate is a parameter passed to the procedure
         group by p1_num, p6_date;
         I need to add a condition <b>p5 = '1'</b> to filter the results of this query. p5 is a from table1. I tried using inner join, as per Jane's suggestion, something like this:
  select t1.p1_num,
          t1.p2_date,
           sum(decode(p3,'50',p4,0)) b_amt,
          sum(decode(p3,'10',p4,0)) r_amt,
          sum(decode(p3,'20',p4,0)) d_amt,
          sum(decode(p3,'40',p4,0)) l_amt,
           sum(decode(p7,'2', p8,0)) pay_amt,
          sum(decode(substr(p9,1,1),'1',p8,0)) oil_amt,
          sum(decode(substr(p9,1,1),'2',p8,0)) gas_amt,
          sum(decode(substr(p9,1,1),'5',p8,'3',p8,'4',p8,0)) ot_amt
   FROM  table2 t2 inner join table1 t1
   on t2.p1_num = t1.p1_num
   WHERE
   to_char(t1.p6_date,'mmyyyy') = V_pdate
   and   t1.p5 = '1'
   and  ((t2.p7 IS NULL) OR (t2.p7 IN ('0','1','3','4')))
   group by t1.p1_num, t1.p2_date
   order by t1.p1_num
   Firstly, I get duplicates for some of the records, which I need to eliminate. Once I eliminate those, i'll know if my retrieved records are right (since right now its retrieving more than 1000 records!)

Similar Messages

  • SQL statement with union clause

    Hi,
    I have a scenario where i need to generate a sql statement with UNION .
    Eg:
    SELECT B.YY_ID,
    FROM XXXX.YY B
    WHERE (B.YY_TY= 'as')
    UNION
    SELECT B.YY_ID
    FROM XXXX.YY_ALT_NAME A, XXXX.YY B
    WHERE (A.YY_TY= 'zx'
    AND (B.YY_ID=A.YY_ID)"
    I tried ns1:table1() union ns3:table2() in XQuery.
    But it is pushdown as 2 seperate sqls.
    Is it possible to create XQuery that pushdown as SINGLE SQL statement with union clause ?
    Thanks

    No. See 3.1.1.5 in the document I referenced in your previous post.

  • Help with UNION Query

    I need some help with an UNION. I have 2 tables, one stores old data and the other stores only the current month data. I need to combine both results in one query so I can report on it. So if the user selects a date range that includes the current month, then use both tables, if not then just use the old data table

    Not sure to completely understand your need, but you could use something like
    select * from (
    select * from old_data
    union
    select * from current_data
    where date_column between start_date and end_date

  • Sql error with date query

    Hi
    Please help!
    I have a page which has an sql statement to show me the records from the last 100 days.
    SELECT tblItems.intItemID, tblItems.txtProductCode, tblItems.txtModel, tblItems.memDescription, tblItems.dteDateIn, tblItems.txtSalesPrice, tblItems.txtLargeImage
    FROM tblItems
    WHERE (((tblItems.dteDateIn)>=DateAdd("d",-100,Date())))
    This works when I test it in the dataset window but throws up the following error on my server running WinXP Pro & IIS.
    Any guidance would be greatly appreciated.
    Thanks
    Lee
    Server Error in '/instruments' Application.
    Compilation Error
    Description: An error occurred during the  compilation of a resource required to service this request. Please  review the following specific error details and modify your source code  appropriately.            
    Compiler Error Message: BC30516: Overload resolution failed because no accessible 'ToString' accepts this number of arguments.
    Source Error:
    Line 1:  <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="utf-8" %>
    Line 2:  <%@ Register TagPrefix="MM" Namespace="DreamweaverCtrls" Assembly="DreamweaverCtrls,version=1.0.0.0,publicKeyToken=836f606ede05d46a,culture=neutral" %>
    Line 3:  <MM:DataSet
    Line 4:  id="DataSet1"
    Line 5:  runat="Server"
    Source File: E:\Websites\instruments\latest.aspx                Line: 3            
    Show Detailed Compiler Output:
    Version Information: Microsoft .NET Framework Version:2.0.50727.3623; ASP.NET Version:2.0.50727.3618

    Hi
    Thanks for the reply.
    Yes .Net 1.1 is installed.
    In fact, my application wouldnt work until I installed .Net version 2
    Regards

  • Very slow performance with UNION and UNION ALL

    I am returning three datasets as one with a UNION ALL between each of three SQL statements. The first one returns either 3 or 4 rows, the second one returns about 10 rows and the third one returns one row. The SQL statements are a little complex but they're all working on very small datasets ( < 1000 rows ) so when I run each of the three SQL statements by themselves, they run to completion and return data in less than 1 second.
    However.
    When I join the three statements together with a UNION ALL statement between them, the statement runs until I manually abort it. I've run it for up to two hours and it shows no signs of either 1) erroring or 2) running to completion. And, I've tried replacing the UNION ALL with UNION and I get the identical results - nothing returned, no error message.
    I've checked the obvious -- same column names, same number of columns, etc. I think that if there were something obvious like that, I would get an error message as soon as I attempted to execute the statements.
    I will be happy to post the code if you'd like, but I'm wondering if anyone has experienced these or similar symptoms when joining together SQL statements with UNIONs and if so what you did to get around it.
    Thanks in advance,
    Carl

    Or I guess you could use subquery factoring (WITH clause) and MATERIALIZE hints to create the temp tables inline, e.g.
    WITH table1 AS
         ( SELECT /*+ materialize */ somecolumns FROM sometable )
       , table2 AS
         ( SELECT /*+ materialize */ somecolumns FROM othertable )
       , table2 AS
         ( SELECT /*+ materialize */  somecolumns FROM anothertable )
    SELECT somecolumns FROM table1
    UNION ALL
    SELECT somecolumns FROM table2
    UNION ALL
    SELECT somecolumns FROM table3It might also be valuable to investigate exactly what is happening and why, as this might suggest a way to address the root cause.

  • Select query with UNION clause in database adapter

    Friends,
    I have got a SQL query with two UNION clause withing it. like
    select a,b,c
    from a
    union
    select a,b,c
    from b
    The schema generated is like below in sequence
    <element>a</element>
    <element>b</element>
    <element>c</element>
    <element>a</element>
    <element>b</element>
    <element>c</element>
    So, the columns from different select queries joined with UNION clause are all appeared in schema instead of the distinct columns.
    Is there any way around to solve this issue ? or will need to with DB function/procedure.

    I think I know what you are saying but your example doesn't make sense, your SQL should produce something like
    I had to change a, b, c with elementA, elementB, elementC as a and b are reserved html tags.
    <elementA>DateA</elementA>
    <elementB>DataB</elementB>
    <elementC>DataC</elementC>
    ...What is the result of the query when you run it in SQLPlus? Is it what you expect?
    cheers
    James

  • Please,I Can't deploy Union Comand in SQL Stament With XMLGEN

    I Have a Problem in SQL Stament
    I Traying execute this SQL Stament With XMLGEN
    Select
    Number as "@Number",
    NumRow as "@NumRow"
    from
    NewTable1
    Union
    Number as "@Number",
    NumRow as "@NumRow"
    from
    NewTable2
    Result: Show only NewTabla1 Rows.
    How I Can Solution This Problem

    Unless you're using the max-rows property which might be restricting the total number of rows, there's no way that XSU itself could affect the query outcome.
    If you reverse the order of the queries
    in the UNION, do you only get the rows from TABLE2 instead? Or regardless of order, you only get them from TABLE1?

  • Create a Union query that automatically adds/contains new tables with a similar name

    Dear All, 
    For a research project i am upscaling from an Access database to SQL server/ SQL azure since the database got far too large. Now i am quite well known with Access, but to be quite honest, I am a SQL rookey. So a lot to learn for me here. 
    what I need is a union query that automatically adds new research dumps to the query. All research dumps have a table name starting with TD_EXP (Table Dump _ Export). In Access VBA I simply made a loop that builds up the SQL statement, but i have no clue
    how to do this within SQL Server...
    So, I need the UNION Query to select * from TD_Exp_2012_06_06_15_48 UNON all the  TD_Exp_XXXX_XX_XX_XX_XX that are added in the database,
    Who could help me out please with a dynamic SQL statement. 
    Best regards  Jurjen

    you can use INFORMATION_SCHEMA.TABLES view for that
    do like below
    DECLARE @Query varchar(max)
    SELECT @Query = STUFF((SELECT ' UNION ALL ' + 'SELECT * FROM ' + TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE 'TD_EXP%' FOR XML PATH('')),1,11,'')
    SELECT @Query
    Add one more condition as below if you want to exclude views from above 
    DECLARE @Query varchar(max)
    SELECT @Query = STUFF((SELECT ' UNION ALL ' + 'SELECT * FROM ' + TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE 'TD_EXP%' AND TABLE_TYPE = 'BASE TABLE' FOR XML PATH('')),1,11,'')
    SELECT @Query
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • JSP with PL/SQL Cartridge

    I have installed OAS 4 and JavaServer Web Development Kit
    Version 1.0 in one PC and with o8i in another PC.
    I've got problem in linking a PL/SQL cartridge, which will
    return a small page, with my jsp.
    I've got no problem if I run the jsp under the OAS while the
    small page can't be retrieved if I run the jsp on other PC.
    Syntax of my jsp for including plsql cartridge :
    <IFRAME ID=IFrame1 title="Testing" FRAMEBORDER=1 SCROLLING=auto
    SRC="http://hkg-wsn-1014/plsql/current_users"></IFRAME>
    where
    http://hkg-wsn-1014/plsql/current_users is my plsql cartridge
    and
    http://hkg-wsn-1014:7070 is the entry point for jsp server
    Can anyone help ?
    Rgds,
    Edward
    null

    The resule is similar to you can't reach the site.
    I've got no problem if I install the OAS 4 and JavaServer Web
    Development Kit in separate machine.
    How can I solve it ?
    Rgds,
    Edward
    Oracle Java Technical Team wrote:
    : Please provide more information. Do you get back a response
    : to the JSP page or just a standard error message?
    : Edward (guest) wrote:
    : : I have installed OAS 4 and JavaServer Web Development Kit
    : : Version 1.0 in one PC and with o8i in another PC.
    : : I've got problem in linking a PL/SQL cartridge, which will
    : : return a small page, with my jsp.
    : : I've got no problem if I run the jsp under the OAS while the
    : : small page can't be retrieved if I run the jsp on other PC.
    : : Syntax of my jsp for including plsql cartridge :
    : : <IFRAME ID=IFrame1 title="Testing" FRAMEBORDER=1
    SCROLLING=auto
    : : SRC="http://hkg-wsn-1014/plsql/current_users"></IFRAME>
    : : where
    : : http://hkg-wsn-1014/plsql/current_users is my plsql cartridge
    : : and
    : : http://hkg-wsn-1014:7070 is the entry point for jsp server
    : : Can anyone help ?
    : : Rgds,
    : : Edward
    null

  • [Execute SQL Task] Error: Executing the query "DECLARE_@XMLA nvarchar(3000) ,__@DateSerial nvarch..." failed with the following error: "Incorrect syntax near '-'.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly,

    Hi
    DECLARE @XMLA nvarchar(3000)
    , @DateSerial nvarchar(35);
    -- Change date to format YYYYMMDDHHMMSS
    SET @DateSerial = CAST(GETDATE() AS DATE);
    --SELECT @DateSerial
    Set @XMLA = 
    N' <Batch xmlns="http://schemas.microsoft.com/analysis services/2003/engine">
     <ErrorConfiguration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ddl2="http://schemas.microsoft.com/analysisservices/2003/engine/2"
    xmlns:ddl2_2="http://schemas.microsoft.com/analysisservices/2003/engine/2/2" xmlns:ddl100_100="http://schemas.microsoft.com/analysisservices/2008/engine/100/100" xmlns:ddl200="http://schemas.microsoft.com/analysisservices/2010/engine/200"
    xmlns:ddl200_200="http://schemas.microsoft.com/analysisservices/2010/engine/200/200">
    <KeyErrorLimit>-1</KeyErrorLimit>
    <KeyNotFound>IgnoreError</KeyNotFound>
    <NullKeyNotAllowed>IgnoreError</NullKeyNotAllowed>
     </ErrorConfiguration>
     <Parallel>
    <Process xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ddl2="http://schemas.microsoft.com/analysisservices/2003/engine/2" xmlns:ddl2_2="http://schemas.microsoft.com/analysisservices/2003/engine/2/2"
    xmlns:ddl100_100="http://schemas.microsoft.com/analysisservices/2008/engine/100/100" xmlns:ddl200="http://schemas.microsoft.com/analysisservices/2010/engine/200" xmlns:ddl200_200="http://schemas.microsoft.com/analysisservices/2010/engine/200/200"
    xmlns:ddl300="http://schemas.microsoft.com/analysisservices/2011/engine/300" xmlns:ddl300_300="http://schemas.microsoft.com/analysisservices/2011/engine/300/300">
     <Object>
     <DatabaseID>MultidimensionalProject5</DatabaseID>
     <CubeID>giri</CubeID>
     <MeasureGroupID>Fact Internet Sales</MeasureGroupID>
     </Object>
     <Type>ProcessFull</Type>
     <WriteBackTableCreation>UseExisting</WriteBackTableCreation>
     </Process>
      </Parallel>
    </Batch>';
    EXEC (@XMLA) At SHALL-PCAdventureWorksDw ;
     iam executive the    query when iam getting below error.
      [Execute SQL Task] Error: Executing the query "DECLARE
    @XMLA nvarchar(3000)
    , @DateSerial nvarch..." failed with the following error: "Incorrect syntax near '-'.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set
    correctly, or connection not established correctly. 
     how to solve this error;
     please help me

    What are you trying to do? What sort of data source is  SHALL-PCAdventureWorksDw?
    When you use EXEC() AT, I would execpt to see an SQL string to be passed to EXEC(), but you are passing an XML string????
    If you explain why you think this would work in the first place, maybe we can help you.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Query with union

    Hi,
    I have three table:
    Candidates: (candidate_id primary key)
    Purhcase_orders: (Po_number primary key)
    Bids: (bid_number primary key)
    Just wanted to retrieve candidate information like candidate_id, first_name etc, along with count of purchase orders issued against this candidate and count of bid_number.
    For that I have written below query:
    query - 1:
    SELECT CANDIDATE_ID,
    INITCAP (first_name) FIRST_NAME,
    +(SELECT COUNT (DISTINCT bid_number)+
    FROM bids
    WHERE BIDS.CANDIDATE_ID = cand.candidate_id)
    BID_COUNT,
    +(SELECT COUNT (DISTINCT po_number)+
    FROM purchase_orders po
    WHERE PO.CONTRACTEE_ID = cand.candidate_id)
    PO_COUNT,
    +'Y' match_flag,+
    DECODE ( (SELECT candidate_id
    FROM v_ineligible_candidates vic
    WHERE VIC.CANDIDATE_ID = cand.candidate_id),
    NULL, 'N',
    +'Y')+
    INELIGIBLE_FLAG
    FROM candidates cand
    Based on business requirement, need to create another set of query (query -2) same like above. In that we have some decode statements to calculate match_flag, then need to perform UNION operation between query -1 and query -2.
    have around 130563 number of rows in candidates table.
    Individually both queries are taking 500 msec.
    But when I have used union, it didnt give result for atleast 60 sec. Then I cancelled execution.
    Execution plan for the final query with UNION: (final cost)
    Cost: 2,873  Bytes: 9,130,170  Cardinality: 260,862                
    Please help me in this issue.
    Why its taking that much time in union.
    Please correct my mistake and suggest me in this query.
    UNION ALL is running but not UNION.
    Thanks in advance

    Please post complete Explain Plans.
    To get detailed information of Explain Plan use
    explain plan for
    your_query;
    select *
      from table(dbms_xplan.display(null, null, 'ALL'));Post it alongwith below details between {noformat}{noformat} (exactly as specified) tags to preserve formatting and ease of understanding.
    On your requirement,
    Using UNIONALL you will get two set of rows, with UNION you might get a single row if your MATCH_FLAG are same for both queries. Use of either, has to meet your requirements than to meet your performance. If it is Business Acceptable, then look for performance and tuning.
    If you could do the folllowing, it might be helpful for you.
    1. Post the Sample table structure (Table information of Candidates should suffice) in a Create Table/With Sub-Query clause.
    2. Sample Data in Insert Into/With Sub-Query format.
    3. Expected Outcome based on Sample data
    4. The Explain Plan of your Queries as requested above.
    Reason of asking these details are, there might be a way to avoid Hitting the table Twice and avoid use of UNION/UNIONALL clauses.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • CFC query union with database query

    I'm trying to invoke a webservice to return a query, and then
    run a parallel query in another database, and UNION the two with a
    query of query. Both the webservice server and the local server are
    CF7, both running MySQL, both accessing tables with parallel
    structures. The webservice returns what appears to be a normal
    query from CFDUMP, but then when I UNION it with the second query,
    I get either "Incorrect Select List" or "Columns with index number
    equal "1" have diffent types (SMALLINT, JAVA_OBJECT)" errors. So
    apparently there's something different about the query from the
    webservice that's causing problems?

    Thanks, this fixed it. I had not realized CF had it's own Q
    of Q CAST function. Here's the documentation on it, in case it has
    eluded others.
    http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?cont ext=ColdFusion_Documentation&file=00001271.htm
    Adobe: It would be nice if the LiveDoc page for a main tag
    like CFQUERY would link to all related pages, like this one above.
    Then when looking for information on using a particular tag, it
    would be much more likely to find the related page.

  • SQL - JOIN using UNION ?? UNION using JOIN ?? with example!

    I was asked this question during one of my interviews. Can you do JOIN using UNION keyword? Can you do UNION using JOIN keyword?
    That is -
    1. I should get same output as JOIN without using JOIN keyword, but using UNION Keyword?
    2. I should get same output as UNION without using UNION keyword, but using JOIN Keyword?
    Can you give me an example of how to do this if possible?

    Hi,
    Welcome to the forum!
    user13067794 wrote:
    I was asked this question during one of my interviews. Can you do JOIN using UNION keyword? Can you do UNION using JOIN keyword?The correct answer to those questions is: Why would you want to? All versions of Oracle (and probably any other database product) provide JOIN to do certain things and UNION to do other things. Why not use those features the way they were designed to be used? Even if it is possible to do what you ask, it's going to be more complicated and less efficient.
    If you really must:
    That is -
    1. I should get same output as JOIN without using JOIN keyword, but using UNION Keyword? You can select the relevant columns from each table, and NULLs for all the columns from other tables, in a UNION query. Then you can use GROUP BY or analytic functions to combine data from different rows. For example, this JOIN:
    SELECT     d.dname
    ,     e.mgr
    FROM     scott.dept     d
    JOIN     scott.emp     e  ON     d.deptno  = e.deptno
    ;could be written using UNION, but no JOIN, like this:
    WITH     union_data     AS
         SELECT     deptno
         ,     dname
         ,     NULL     AS empno
         ,     NULL     AS mgr
         FROM     scott.dept
        UNION ALL
         SELECT     deptno
         ,     NULL     AS dname
         ,     empno
         ,     mgr
         FROM     scott.emp
    ,     quasi_join     AS
         SELECT     MAX (dname) OVER (PARTITION BY deptno)     AS dname
         ,     mgr
         ,     empno
         FROM     union_data
    SELECT     dname
    ,     mgr
    FROM     quasi_join
    WHERE     empno     IS NOT NULL
    ;Depending on your tables and your requirements, you might be able to do something a little simpler.
    2. I should get same output as UNION without using UNION keyword, but using JOIN Keyword?A FULL OUTER JOIN is similar to UNION.
    This UNION query:
    SELECT     dname          AS txt
    FROM     scott.dept
    UNION
    SELECT     TO_CHAR (mgr)     AS txt
    FROM     scott.emp
    ;Can be written like this, using JOIN but no UNION:
    SELECT DISTINCT
         NVL2 ( e.empno
              , TO_CHAR (e.mgr)
              , d.dname
              )          AS txt
    FROM          scott.dept     d
    FULL OUTER JOIN     scott.emp     e  ON       1 = 2
    user13067794 wrote:I too don't any example as such, but I am thinking on this line -
    Select a.x, b.y
    from a,b
    where a.key=b.key and sal<5000
    UNION
    Select a.x, b.y
    From a,b
    Where a.key=b.key and sal>7000
    can we get same result using JOIN?That's a very special case. You can get the same results without using UNION like this:
    Select distinct
         a.x
    ,      b.y
    from      a
    ,     b
    where      a.key     = b.key
    and      (        sal < 5000
         OR     sal > 7000
    Can we do something similar using UNION without using JOIN keyword??What you posted does not use the JOIN keyword.
    To get the same results without using a join (either with or without the JOIN keyword), you can use UNION together with aggregate or analytic functions, as I showed earlier.
    Edited by: Frank Kulash on Jul 5, 2011 9:01 PM

  • Query with UNION option

    Hi ,
    I have one partition table.The partitions are created datewise.Now when i have to fire select query on that talble i am firing below querry
    Select count(1) from table A where createdate between ('01-JAN-2012 00:00:00','DD-MON-YYYY HH24:MI:SS') AND ('01-JAN-2012 23:59:59','DD-MON-YYYY HH24:MI:SS')
    Above query will scan 1 day partition.
    now if i want to fetch records from whole month ,it will scan 31 partition one by one.
    Select count(1) from table A where createdate between ('01-JAN-2012 00:00:00','DD-MON-YYYY HH24:MI:SS') AND ('31-JAN-2012 23:59:59','DD-MON-YYYY HH24:MI:SS')
    Now if i change the query by writing another way which will scan partition parallely.
    Select count(1) from table A where createdate between ('01-JAN-2012 00:00:00','DD-MON-YYYY HH24:MI:SS') AND ('01-JAN-2012 23:59:59','DD-MON-YYYY HH24:MI:SS')
    union
    Select count(1) from table A where createdate between ('02-JAN-2012 00:00:00','DD-MON-YYYY HH24:MI:SS') AND ('02-JAN-2012 23:59:59','DD-MON-YYYY HH24:MI:SS')
    union
    Select count(1) from table A where createdate between ('03-JAN-2012 00:00:00','DD-MON-YYYY HH24:MI:SS') AND ('03-JAN-2012 23:59:59','DD-MON-YYYY HH24:MI:SS')
    union
    till
    Select count(1) from table A where createdate between ('31-JAN-2012 00:00:00','DD-MON-YYYY HH24:MI:SS') AND ('31-JAN-2012 23:59:59','DD-MON-YYYY HH24:MI:SS')
    Is it possible that i can make query by passing different month in above union query .
    Month can be dynamic, and above select can be take the values by passing the month.
    kindly guide me
    =======

    I hear you. But can you demonstrate, instead of just telling?
    Else, I'll be guessing, that you are just guessing. And I am inclined to guess that your guess is wrong.
    But, I could be guessing wrong, of course. (And week-ends I am not online to test it myself)
    Start by showing the table, ddl. Is it parallel, noparallel? - And then show the plans for both queries.
    And how did you come to that conclusion of "one by one" vs "in parallel"?
    Regards
    Peter

  • How to make OAS 4.0.7 work with PL/SQL-Cartridge

    Hi folks,
    it took me some days, but now I've found the solution:
    1. Although the OAS 4.0.7 seems to work fine on a 2.2-Kernel,
    the PL/SQL-Cartridge will definitely never work!!!!!!
    I don't know exactly why, but I've installed all
    relevant libs, but it won't work, whatever I do.
    2. I've installed the OAS on an old 2.0.36-Kernel (SuSE 6.0),
    and everything works fine!
    The only thing you have to take care of is to set the
    domainname BEFORE installing the OAS. The installation
    procedure queries 'domainname', not 'dnsdomainname' to
    get the domain. And if you don't have YP configured by
    chance, your hostname will look something like
    'myhost.(none)' in every OAS configuration file
    (and there are a lot), which prevents the ORB from starting.
    I hope that will help someone out there
    Greetings
    Jochen
    null

    Jochen Kutscheruk (guest) wrote:
    : Hi folks,
    : it took me some days, but now I've found the solution:
    : 1. Although the OAS 4.0.7 seems to work fine on a 2.2-Kernel,
    : the PL/SQL-Cartridge will definitely never work!!!!!!
    : I don't know exactly why, but I've installed all
    : relevant libs, but it won't work, whatever I do.
    : 2. I've installed the OAS on an old 2.0.36-Kernel (SuSE 6.0),
    : and everything works fine!
    : The only thing you have to take care of is to set the
    : domainname BEFORE installing the OAS. The installation
    : procedure queries 'domainname', not 'dnsdomainname' to
    : get the domain. And if you don't have YP configured by
    : chance, your hostname will look something like
    : 'myhost.(none)' in every OAS configuration file
    : (and there are a lot), which prevents the ORB from starting.
    : I hope that will help someone out there
    : Greetings
    : Jochen
    This would really be great, if this works.
    Can anybody confirm this ?
    To bad i need a 2.2 kernel for my raid diskset :(
    Greetings, Eric.
    null

Maybe you are looking for

  • Need to make a print button in indesign

    hi I need to make a print button in indesign for a brochure. I have made several buttons by using the create button toll but there is no 'print' option in the list of behaviours. can anyone help me with this please. The final output is a pdf and the

  • How do I stop an event sent by email which iCal is rejecting keep coming back?

    Some months ago  I was sent an appt by email for inclusion in iCal. This happens frequently - normally without a problem. On this occasion however it was rejected: "calendar can't accept the event [name of event]....etc" "The account [name of account

  • PI 7.1  EHP1 SR1 and Solutionmanager EHP1 is compatible ?

    Hi Folks , In our landscape we have Solution manager EHP1  , I would like to propose PI 7.1 . But as per the discussion with installation team , We have Solution manager EHP1 which is not compatible with PI 7.1 EHP1 SR1  ? is that true ?    1. What p

  • How to leave the current dialog box screen?

    Hi Experts, Now I met a problem when I use statement LEAVE SCREEN for closing current dialog box screen. The scenario is like this: There is a screen '0010' under function group A, on this screen, there are 4 tabs, i created a custom control element

  • Utilisatio​n Visa

    Bonjour, J'utilise un port série, et je souhaiterai passer les référence du VISA resource name d'un vi à un autre. Lorsque je lance mon prog il ne voit pas dans les sous Vi les VISA resource name ci-joint la copie d'écran dans Visa in j'ai un blanc a