Need help with writing a query with dynamic FROM clause

Hi Folks,
I need help with an query that should generate the "FROM" clause dynamically.
My main query is as follows
select DT_SKEY, count(*)
from *???*
where DT_SKEY between 20110601 and 20110719
group by DT_SKEY
having count(*) = 0
order by 1; The "from" clause of the above query should be generated as below
select 'Schema_Name'||'.'||TABLE_NAME
from dba_tables
where OWNER = 'Schema_Name'Simply sticking the later query in the first query does not work.
Any pointers will be appreciated.
Thanks
rogers42

Hi,
rogers42 wrote:
Hi Folks,
I need help with an query that should generate the "FROM" clause dynamically.
My main query is as follows
select DT_SKEY, count(*)
from *???*
where DT_SKEY between 20110601 and 20110719
group by DT_SKEY
having count(*) = 0
order by 1; The "from" clause of the above query should be generated as below
select 'Schema_Name'||'.'||TABLE_NAME
from dba_tables
where OWNER = 'Schema_Name'
Remember that anything inside quotes is case-sensitive. Is the owner really "Schema_Name" with a capital S and a capital N, and 8 lower-case letters?
Simply sticking the later query in the first query does not work.Right; the table name must be given when you compile the query. It's not an expression that you can generate in the query itself.
Any pointers will be appreciated.In SQL*Plus, you can do something like the query bleow.
Say you want to count the rows in scott.emp, but you're not certain that the name is emp; it could be emp_2011 or emp_august, or anything else that starts with e. (And the name could change every day, so you can't just look it up now and hard-code it in a query that you want to run in the future.)
Typically, how dynamic SQL works is that some code (such as a preliminary query) gets some of the information you need to write the query first, and you use that information in a SQL statement that is compiled and run after that. For example:
-- Preliminary Query:
COLUMN     my_table_name_col     NEW_VALUE my_table_name
SELECT     table_name     AS my_table_name_col
FROM     all_tables
WHERE     owner          = 'SCOTT'
AND     table_name     LIKE 'E%';
-- Main Query:
SELECT     COUNT (*)     AS cnt
FROM     scott.&my_table_name
;This assumes that the preliminary query will find exactly one row; that is, it assumes that SCOTT has exactly one table whose name starts with E. Could you have 0 tables in the schema, or more than 1? If so, what results would you want? Give a concrete example, preferably suing commonly available tables (like those in the SCOTT schema) so that the poepl who want to help you can re-create the problem and test their ideas.
Edited by: Frank Kulash on Aug 11, 2011 2:30 PM

Similar Messages

  • Please i need help with switch from the us store to malaysian store how i can switch

    Please i need help with switch from the us store to malaysian store how i can switch

    Click here and follow the instructions to change the iTunes Store country.
    (82303)

  • HT1766 I need help with restore from bachup

    I NEED HELP WITH MY IPAD RESTORE FROM BACKUP

    This is the iPod touch forum and you are not providing any information to help you.

  • Need help with Dynamic Excel File Name please.

    I am try to output an excel file with dynamic date. 
    Here what I done.
    I am using SQL 2012.
    Create Execute SQL Task Connect Type: Excel
    Create Data Flow Task set to DelayValidation: True
    Create OLE DB Sourc
    Create Data Converstion
    Excel Destination
    Excel Connection, Expression, select ExcelFilePath
    @[User::sXLFilePath] +  @[User::sFileName] + RIGHT("0" + (DT_WSTR, 2) DATEPART("DD", GETDATE()), 2)+ RIGHT("0" + (DT_WSTR, 2) DATEPART("MM", GETDATE()), 2) + RIGHT((DT_WSTR,
    4) DATEPART("YYYY", GETDATE()), 2) +".csv"
    C:\ExcelOutPut\SOX_CAM_SQL_Report_010215.xls
    What I try to accomplish is output the file with each day append to it, date must be DDMMYY.
    I google it and found many samples, tested it, and none of them is work for me. 
    Any suggestions or some examples to share is greatly appreciate. 
    I am new to SSIS.  I found one poster have similar issue and inside the posted below, there was one suggestion to create variable and connection string but how do I bind that variable to Excel Connection manger.
    Please help.
    Thank you so much in advance.
    Ex: SOX_CAM_SQL_Report _020215.csv
           SOX_CAM_SQL_Report _030215.csv
    --Similar issue:
    https://social.msdn.microsoft.com/Forums/en-US/bda433aa-c8f8-47c9-9e56-efd20b8354ac/creating-a-dynamic-excel-file?forum=sqlintegrationservices
    Suggestion in the above posted but where can bind this to Excel Connection Manger. 
    Please help provide step by step.  Thanks.
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\temp\\" + "ExcelTarget" + (DT_WSTR,4)DATEPART("yyyy",GETDATE())  +
    ".xls" + ";Extended Properties=\"EXCEL 8.0;HDR=YES\";"
    And yes, as you were intimating, the delay validation on the dataflow should be set.

    Hi NguyenBL,
    According to your description, you created ssis package to export data from database to excel, when the package runs, you want to create new excel and name the file with time stamp. If that is the case, we can achieve the goal by following steps:
    Create a script task used to create excel files.
    Create a data flow task to export data from database to excel.
    Add OLE DB source to data flow task.
    Add Excel Destination to data flow task.
    Create connection manager for OLE DB and Excel.
    Click Excel Connection Manager, in Properties window, click (…) button next to Expressions, then set ExcelFilePath with expression like below:
    "C:\\ETL Lab\\CreateNewExcel\\ExportData_"+REPLACE((DT_STR, 20, 1252)(DT_DBTIMESTAMP)@[System::StartTime], ":", "")+".xls"
    For detail information, please refer to the document:
    https://sqljourney.wordpress.com/2013/01/12/ssis-create-new-excel-file-dynamically-to-export-data/
    If you have any more questions, please feel free to ask.
    Thanks,
    Wendy Fu
    Wendy Fu
    TechNet Community Support

  • Need help with calc from tables

    I have a table that contains query #1 and have another table
    that contains a field that needs to use the result of the cfset in
    another calc.
    The new calc in query #2 needs to divide the Num_Checks_Trans
    from query #1 by the by the Weekly_Hours_Recorded in query #2.
    Can anyone help me figure this out?
    <b>1.</b>
    <cfquery name="QryEmployeeDetail"
    datasource="NBProdReports">
    SELECT TblContractInfo_SubMenuTable.User_ID,
    TblContractInfo_SubMenuTable.Contract_Number,
    TblContractInfo_SubMenuTable.Transaction_Type,
    TblContractInfo_SubMenuTable.Num_Checks_Trans, TblTransType.Value,
    TblContractInfo_SubMenuTable.Notes, TblMasterTrans.Date_Opened
    from TblContractInfo_SubMenuTable, TblMasterTrans,
    TblTransType
    WHERE TblContractInfo_SubMenuTable.Task_Number =
    TblMasterTrans.Task_Number
    and TblTransType.Transaction_Type =
    TblContractInfo_SubMenuTable.Transaction_Type
    And TblMasterTrans.Date_Opened BETWEEN
    #createODBCDate(DED_startDate)# AND #createODBCDate(DED_endDate)#
    order BY TblMasterTrans.Date_Opened ASC,
    TblContractInfo_SubMenuTable.User_id ASC
    </cfquery>
    <cfset totalTrans = 0 />
    <cfloop query="QryEmployeeDetail">
    <cfset totalTrans = totalTrans +
    (QryEmployeeDetail.Num_Checks_Trans * QryEmployeeDetail.Value)
    /></cfloop>
    Text
    2.
    <cfquery name="QryEmployeeDetail"
    datasource="NBProdReports">
    SELECT TblContractInfo_SubMenuTable.User_ID,
    TblContractInfo_SubMenuTable.Contract_Number,
    TblContractInfo_SubMenuTable.Transaction_Type,
    TblContractInfo_SubMenuTable.Num_Checks_Trans, TblTransType.Value,
    TblContractInfo_SubMenuTable.Notes, TblMasterTrans.Date_Opened
    from TblContractInfo_SubMenuTable, TblMasterTrans,
    TblTransType
    WHERE TblContractInfo_SubMenuTable.Task_Number =
    TblMasterTrans.Task_Number
    and TblTransType.Transaction_Type =
    TblContractInfo_SubMenuTable.Transaction_Type
    And TblMasterTrans.Date_Opened BETWEEN
    #createODBCDate(DED_startDate)# AND #createODBCDate(DED_endDate)#
    order BY TblMasterTrans.Date_Opened ASC,
    TblContractInfo_SubMenuTable.User_id ASC
    </cfquery>

    This can be rewritten as a single query which is good for a
    number of reasons, including we only make one trip to the database
    and we do our calculations on the SQL backend, which is faster than
    doing them in CFML.
    What you're going to want to do is SUM() the total
    transaction values by having a column like SUM(Num_Checks_Trans *
    Value) AS totalTrans. To get the value for your other column you
    can calculate that like Num_Checks_Trans / Weekly_Hours_Recorded. I
    didn't see the latter in either of your queries so I'm not sure
    where it comes from, but you can definitely use it in your SELECT
    clause when calculating.
    Since SUM() is an aggregate function, you'll have to use a
    GROUP BY clause to make it work. You'll have to GROUP BY each
    column in the SELECT statement. If some of the columns have
    differing data that you won't want to use in the GROUP, you can
    always use a nested subquery as part of your FROM clause and then
    join that to the original queries with the totals.
    I hope that helps.
    - William

  • Need help in writing the query

    The initial data is as follows:
    ID PARENT_ID
    =============
    1 NULL
    2 NULL
    3 2
    4 6
    5 3
    6 7
    7 4
    8 NULL
    but output is as follows in such way that Parent_Id should be displayed in ID place
    ID PARENT_ID
    =============
    1 NULL
    2 NULL
    3 2
    8 NULL
    6 8
    4 6
    5 3
    7 4
    Can any one help how resolve this query?
    Thanks in advance

    Your output is inconsistent with initial data :) But
    select * from t start with parent_id is null connect by parent_id = prior id;

  • Need help with sum from previous years

    Hi All,
    In a report i have 4 fields. The first field shows the YTD invoice totals for the current FY 2010 (which i accomplished). The other 3 fields are :
    2nd field Sum of the value of invoices for the FY 1YEAR prior to the current year
    3rd field Sum of the value of invoices for the FY 2YEAR's prior to the current year.
    4th field Sum of the value of invoices for the FY 3YEAR's prior to the current year.
    How can i get the desired results for the second,third and the fourth fields, please need help or advice.
    Thanks

    Hi
    If you have the values for several years in the same report you should be able to do what you want using the analytic LEAD and LAG.
    LAG will retrieve values from previous rows whereas LEAD will retrieve values from following rows.
    The basic syntax is the same and look like this:
    LAG(value, offset) OVER ({optional_partition_clause} ORDER BY mandatory_order_clause)
    The ORDER BY clause is mandatory and cannot be omitted. However, this ORDER BY has nothing to do with the sort order you manually create in the worksheet. Generally, most people will set their sort order the same as the ORDER BY in the calculation.
    Here's an example that gets year to date from 2 financial years ago:
    LAG(YTD,2) OVER (ORDER BY FY)
    You have to understand that Discoverer will pull values from previous rows not from previous cells as displayed on the report, although if the cells may happen to be rows too then it will appear as though it is pulling previous cells. I personally am very experienced with analytuc functions and can make manipulate data within Discoverer just about any way that I want. Generally, if I can see data on the screen even when they are in different cells or rows I can create functions to manipulate it. This capability only comes about as a result of experience and I would strongly advise you to practice with the analytics and see if you can at least master some of them. You'll find your Discoverer capabilities will improve dramatically and you will become a great asset at work.
    When working with a new report I generally duplicate the report as a table so that I can see the values. Then if I need to sort the items in order to line up the values I want to work with I do so. Having worked out what sort order I need I can then see what offset I use then I create the analytic and use it in the main worksheet.
    Hope this helps
    Best wishes
    Michael

  • Newb needs help with dynamic text

    Hi Everyone,
    I don't like being a newb - but that's how it is...
    I'm trying to create a multipage registration form that
    allows uses to register products.
    The first page asks for name etc, and on the second page I
    want it to say "Welcome "+username "!" - that sort of thing...
    The problem is I can't get it to keep the dynamic text values
    accross the pages.
    I can get it to repeat the input on the first page with this
    code:
    _root.firstname_txt.onChanged = function() {
    _root.firstname_repeat.text="Hello
    "+_root.firstname_txt.text;
    However when I call it on the second page it is undefined:
    second_repeat.text="hello "+_root.firstnamt_txt.text;
    trace (_root.second_repeat.text);
    I'm sure this is something simple and I'm just a programming
    dunce...
    Any help is appreciated.
    ta

    if your textfield (_root.firstname_repeat) doesn't exist on
    the 2nd frame, its text property will be undefined.
    to remedy, either extend your textfield's existance into the
    frames needed or use a variable to store its text property (in your
    onChanged handler) and use that variable to retrieve the value you
    need.

  • [10g] Need help with order by clause in hierarchical query

    I have the following sample data:
    CREATE TABLE     bill_test1
    (     parent_part     CHAR(25)
    ,     child_part     CHAR(25)
    ,     line_nbr     NUMBER(5)
    ,     qty_per          NUMBER(9,5)
    INSERT INTO bill_test1 VALUES ('ABC-1','ABC-10',100,1);
    INSERT INTO bill_test1 VALUES ('ABC-1','ABC-20',200,2);
    INSERT INTO bill_test1 VALUES ('ABC-1','ABC-30',300,3);
    INSERT INTO bill_test1 VALUES ('ABC-1','HARDWARE-1',401,10);
    INSERT INTO bill_test1 VALUES ('ABC-1','HARDWARE-2',402,5);
    INSERT INTO bill_test1 VALUES ('ABC-10','ABC-155',100,2);
    INSERT INTO bill_test1 VALUES ('ABC-10','HARDWARE-1',200,1);
    INSERT INTO bill_test1 VALUES ('ABC-155','RAW-2',100,4.8);
    INSERT INTO bill_test1 VALUES ('ABC-155','HARDWARE-3',200,3);
    INSERT INTO bill_test1 VALUES ('ABC-20','RAW-1',100,10.2);
    INSERT INTO bill_test1 VALUES ('ABC-30','RAW-3',100,3);And the query below gives me exactly what I want, in the order I want it. However, I am wondering if there is a way to get this order without creating the SEQ column, since I don't need it in my results
    SELECT     part_nbr
    ,     parent_part
    ,     child_part
    FROM     (
         SELECT     CONNECT_BY_ROOT b.parent_part                         AS part_nbr
         ,     b.parent_part
         ,     b.child_part
         ,     SYS_CONNECT_BY_PATH(b.line_nbr,' ')                    AS seq
         FROM     bill_test1 b
         ,     dual
         CONNECT BY     parent_part     = PRIOR child_part
    WHERE          part_nbr     = 'ABC-1'
    ORDER BY     seq
    Results of above query, except with SEQ included in SELECT (just to show what I'm sorting off of):
    PART_NBR                     PARENT_PART                  CHILD_PART                   SEQ
    ABC-1                        ABC-1                        ABC-10                        100
    ABC-1                        ABC-10                       ABC-155                       100 100
    ABC-1                        ABC-155                      RAW-2                         100 100 100
    ABC-1                        ABC-155                      HARDWARE-3                    100 100 200
    ABC-1                        ABC-10                       HARDWARE-1                    100 200
    ABC-1                        ABC-1                        ABC-20                        200
    ABC-1                        ABC-20                       RAW-1                         200 100
    ABC-1                        ABC-1                        ABC-30                        300
    ABC-1                        ABC-30                       RAW-3                         300 100
    ABC-1                        ABC-1                        HARDWARE-1                    401
    ABC-1                        ABC-1                        HARDWARE-2                    402

    Hi,
    As long as there's only one root, you can say ORDER SIBLINGS BY, but you can't do that in a sub-query (well, you can, but usually there's no point in doing it in a sub-query). If the CONNECT BY is being done in a sub-query, there is no guarantee that the main query will preserve the hierarchical order that the sub-query provides.
    The query you posted doesn't require a suib-query, so you can say:
    SELECT     CONNECT_BY_ROOT b.parent_part                         AS part_nbr
    ,     b.parent_part
    ,     b.child_part
    --,     SYS_CONNECT_BY_PATH(b.line_nbr,' ')                    AS seq
    FROM     bill_test1 b
    WHERE          CONNECT_BY_ROOT b.parent_part     = 'ABC-1'
    CONNECT BY     parent_part     = PRIOR child_part
    ORDER SIBLINGS BY     b.line_nbr     
    ;I said the query you posted doesn't require a sub-query. It also doesn't require dual, so I suspect what you posted is a simplification of what you're really doing, and that may need a sub-query. In particular, if you intend to GROUP BY part_nbr, then you need the sub-query. We can repeat the CONNECT_BY_ROOT expression in the WHERE clause (or, now that I think about it, use a START WITH clause instead of WHERE), but, for some reason, we can't use CONNECT_BY_ROOT in a GROUP BY clause; we need to compute CONNECT_BY_ROOT in a sub-query, give it a name (like part_nbr), and GROUP BY that column in a super-query.
    This assumes that there is only one root node. ORDER SIBLINGS BY means just that: children of a common parent will appear in order, but the root nodes, who have no parents, will not necessarily be in order.
    Here's what I meant by using START WITH instead of WHERE:
    SELECT     CONNECT_BY_ROOT b.parent_part                         AS part_nbr
    ,     b.parent_part
    ,     b.child_part
    --,     SYS_CONNECT_BY_PATH(b.line_nbr,' ')                    AS seq
    FROM     bill_test1 b
    START WITH     b.parent_part     = 'ABC-1'
    CONNECT BY     parent_part     = PRIOR child_part
    ORDER SIBLINGS BY     b.line_nbr     
    ;This should be much more efficient, because it narrows down the results before you waste time getting their descendants.
    Using a START WITH clause here is analagous to me sending you an e-mail, saying "Come to a meeting a my office at 3:00."
    Using a WHERE clause here is analagous to me sending an e-mail to everyone in the company, saying "Come to a meeting a my office at 3:00", and then, as people get here, telling everyone except you that they can go back.
    ORDER SIBLINGS BY was introduced in Oracle 9.
    Edited by: Frank Kulash on Dec 9, 2010 2:39 PM
    Added version with START WITH clause

  • Need help with dynamic html

    I am a Microsoft J++ developer, but am switching to Sun technologies. The first application that I need to work on is an application that does a great deal of dynamic HTML. I originally wrote this application under J++ but I need to convert it to Sun Java. The methodology J++ used for dynamic HTML (extending DhDocument) appears to be duplicated (somewhat) with Swing. I need a little push start here, I seem to have a mental block. My application must run in the client browser, so I believe an applet is the way to go, but I can't figure out how to manipulate HTML from an applet through Swing. Can someone point me to a simple Applet that, say for example, changes the value of a text box that is predefined in the HTML, I would greatly appreciate it. That should get me past this mental block so I can go on with the conversion. I have successfully added textboxes with Swing through my Applet, but I need to manipulate HTML elements that already exist. That's where I'm stuck.

    Here's the code I come up with. It doesn't work. I get a javascript exception on getWindow. I have never used the JSObject before. Can you give me any advice on what I am doing wrong?
    import javax.swing.*;
    import netscape.javascript.*;
    public class Search extends JApplet
    public void init()
         JSObject obj = JSObject.getWindow(this);
         JSObject doc = (JSObject) obj.getMember("document");
         String[] element = new String[1];
         element[0] = "UserID";
         JSObject form = (JSObject) doc.call("getElementById", element);
    }

  • Need help with dynamic code generation

    Hi Folks,
    I am trying to dynamically create and execute the following query
    Environment: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0
    DECLARE
    A NUMBER;
    stmt VARCHAR2(200);
         4
         5  CURSOR C1 IS
         6  SELECT TABLE_NAME
         7  FROM DB_MGMT.CTRL_TAB_RETENTION
         8  WHERE RETENTION_PERIOD_IN_MONTHS = 11
         9  AND rownum < 2;
        10
        11  BEGIN
        12  FOR i IN C1
        13  LOOP
        14
        15  -- dbms_output.put_line('Table Name: ' || i.TABLE_NAME);
        16
        17  -- dbms_output.put_line('SELECT min(DT_SKEY), max(DT_SKEY) FROM '||i.TABLE_NAME||' ;');
        18
        19  stmt :='SELECT min(DT_SKEY), max(DT_SKEY) FROM DWH_RSRC_PERF.'||i.TABLE_NAME||';';
        20
        21  dbms_output.put_line(stmt);
        22
        23  execute immediate stmt;
        24  END LOOP;
        25  END;
        26  /I get the following error message
    SQL> @sanity_check
    SELECT min(DT_SKEY), max(DT_SKEY) FROM DWH_RSRC_PERF.FACT_NOK_CELL_SERVICE2_HH;
    DECLARE
    ERROR at line 1:
    ORA-00911: invalid character
    ORA-06512: at line 23Can anybody spot any obvious syntax errors in the above code?
    Thanks in advance
    rogers42

    rogers42 wrote:
    Hi,
    Thanks for the suggestion.
    While getting rid of the ";" helps, but the output of the select statement is not displayed?When you do a SELECT statement in PL/SQL, you have to select the results into variables or arrays.
    Try something like this:
    DECLARE
         CURSOR C1 IS
                       SELECT  TABLE_NAME
                FROM    DB_MGMT.CTRL_TAB_RETENTION
                WHERE   RETENTION_PERIOD_IN_MONTHS = 11
                AND     rownum                  < 2;
         min_dt_skey    NUMBER;
         max_dt_skey    NUMBER;
         stmt            VARCHAR2 (100);
    BEGIN
        FOR i IN C1
         LOOP
            -- dbms_output.put_line('Table Name: ' || i.TABLE_NAME);
            stmt :='SELECT min(DT_SKEY), max(DT_SKEY) FROM DWH_RSRC_PERF.' || i.TABLE_NAME;
            dbms_output.put_line(stmt);
            EXECUTE IMMEDIATE stmt
             INTO min_dt_skey, max_dt_skey;
         dbms_output.put_line (  min_dt_skey   || ' = MIN (dt_skey), '
                        || max_dt_skey   || ' = MAX (dt_skey) for table '
                        || i.table_name
        END LOOP;
    END;

  • I need help with dynamic sql

    hello all,
    i'm using oracle forms 6i
    i create a bush-button and using trigger when button pressed
    DECLARE
       WHERE_CLAUSE   VARCHAR2 (3000) := '';
    BEGIN
      WHERE_CLAUSE :='T.L_ID IN ('||:CONTROL.TXT_L2||')'
                   ||'AND TO_NUMBER(TO_CHAR(T.M_DATE,''MM'')) IN ('||(:CONTROL.TXT_M)|| ')' ;
               /*     'T.M_DATE BETWEEN'|| (:TXT_FROM) ||'AND' ||(:TXT_TO);
                'T.M_DATE IN (SELECT M_DATE FROM T' ||'     WHERE M_DATE BETWEEN '||(:TXT_FROM)|| ' AND ' || (:TXT_TO) || ')';*/
       SET_BLOCK_PROPERTY ('T', DEFAULT_WHERE, WHERE_CLAUSE);
       GO_BLOCK('T');
      EXECUTE_QUERY;
    END;my code is working fine when i insert value in two txt item (:CONTROL.TXT_L2 ) (:CONTROL.TXT_M)
    my problem is
    i would like to insert one value in one txt item
    quotation 2
    how can i use (between operator) in same situation
    thank's all :)

    There is an exclusive forum for Forms: {forum:id=82}

  • Need help with ORDER BY clause

    Hey,
    I have a table:
    Name: Year:
    Eagle 2000
    Tiger 2001
    Eagle 2002
    Lion 2006
    Lion 1999
    Fox 1991
    Lion 1995
    I need a query which will return in such order:
    Name: Year: Position:
    Eagle 2000 1
    Eagle 2002 2
    Fox 1991 1
    Lion 1995 1
    Lion 1999 2
    Lion 2006 3
    Tiger 2001 1
    So, of course to get Name and Year in this order is quite easy:
    select Name, Year from Animals order by Name, Year;
    but how about Position, is there a way to count it with SQL?
    any help is welcome,
    Silvestras

    SQL> with rt as
      2  (select 'Eagle' nm, 2000 yr from dual union all
      3  select 'Tiger', 2001 from dual union all
      4  select 'eagle', 2002 from dual union all
      5  select 'Lion', 2006 from dual union all
      6  select 'Lion', 1999 from dual union all
      7  select 'Fox', 1991 from dual union all
      8  select 'Lion', 1995 from dual)
      9  select nm,yr,row_number() over(partition by (nm) order by nm,yr) position from rt;
    NM            YR   POSITION
    Eagle       2000          1
    Fox         1991          1
    Lion        1995          1
    Lion        1999          2
    Lion        2006          3
    Tiger       2001          1
    eagle 2002 1
    7 rows selected.
    SQL> with rt as
      2  (select 'Eagle' nm, 2000 yr from dual union all
      3  select 'Tiger', 2001 from dual union all
      4  select 'eagle', 2002 from dual union all
      5  select 'Lion', 2006 from dual union all
      6  select 'Lion', 1999 from dual union all
      7  select 'Fox', 1991 from dual union all
      8  select 'Lion', 1995 from dual)
      9  select nm,yr,row_number() over(partition by lower(nm) order by nm,yr) position from rt;
    NM            YR   POSITION
    Eagle       2000          1
    eagle 2002 2
    Fox         1991          1
    Lion        1995          1
    Lion        1999          2
    Lion        2006          3
    Tiger       2001          1
    7 rows selected.
    SQL> 

  • New to Oracle- Need help with installation from cmd shell.

    Hello!
    I am writing a script to automate the installation of Oracle Forms and Reports 6i in XP through cmd.exe. The script works great, but the command is incomplete.
    Currently the command in the script is "setup -responseFile directory\response.rsp".
    This is supposed to generate a .rsp file containing all the options I selected in the custom installation (so I can simply call that file in future implementations of this script to automatically get all those settings), but it does not.
    Does any one know what might be wrong: why isn't this generating the response file?
    Or, do you know the arguments for the command so that I don't even need a response file?
    I've googled this about a dozen times and found nothing very helpful.
    Any advice is appreciated.
    P.S. I've also tried -record -destinationFile. No luck with that either.
    Message was edited by:
    user582111

    Madrid,
    I had already tried that with no success. Just to be sure, I tried it again a moment ago exactly as you have it written except for the location name ("setup.exe -record -destinationFile \\directory\response.rsp"). Again, I don't see a response file.
    I have viewed the link you sent me as well. Unfortunately, it looks like a I need to use the Universal Installer? I don't see anything like that in my installation directory. Am I completely missing something? Oracle is a whole new bag for me.

  • Need help in writing inline query or subquery

    Hi All,
    I have 4 select statements like below ,
    1>Select customer_number, customer_name,customer_address1
    FROM ABC
    WHERE Site_use_code='BILL_TO'
    2>Select customer_number, customer_name,customer_address1
    FROM ABC
    WHERE Site_use_code='SHIP_TO'
    3>Select customer_number, customer_name,customer_address1
    FROM ABC
    WHERE Site_use_code='SOLD_TO'
    I need to write all these 3 in single select statement in such a way that if any select statement doesnot return any data it should execute the other select statements means it should not fail.
    for each column of the select statment i can write separate select statements in that way it should work but the query should be very big.
    So please help me on thsi.
    Thanks

    Example of my solution:
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (
      2    select 1 as customer_number, 'Fred' as customer_name, 'address1' as customer_address1, 'BILL_TO' as site_use_code from dual union all
      3    select 1 as customer_number, 'Fred' as customer_name, 'address1' as customer_address1, 'SHIP_TO' as site_use_code from dual union all
      4    select 2 as customer_number, 'Bob' as customer_name, 'address2' as customer_address1, 'BILL_TO' as site_use_code from dual union all
      5    select 3 as customer_number, 'George' as customer_name, 'address3' as customer_address1, 'BILL_TO' as site_use_code from dual union all
      6    select 3 as customer_number, 'George' as customer_name, 'address3' as customer_address1, 'SHIP_TO' as site_use_code from dual union all
      7    select 3 as customer_number, 'George' as customer_name, 'address3' as customer_address1, 'SOLD_TO' as site_use_code from dual union all
      8    select 4 as customer_number, 'Tim' as customer_name, 'address4' as customer_address1, 'BILL_TO' as site_use_code from dual union all
      9    select 5 as customer_number, 'Sam' as customer_name, 'address5' as customer_address1, 'BILL_TO' as site_use_code from dual
    10  )
    11  --
    12  -- END OF TEST DATA
    13  --
    14  select customer_number
    15        ,customer_name
    16        ,customer_address1
    17        ,site_use_code
    18  from (
    19        select customer_number
    20              ,customer_name
    21              ,customer_address1
    22              ,site_use_code
    23              ,row_number() over (partition by customer_number order by decode(Site_use_code,'BILL_TO',1,'SHIP_TO',2,3) desc) as rn
    24        FROM t
    25        WHERE Site_use_code IN ('BILL_TO','SHIP_TO','SOLD_TO')
    26       )
    27* where rn = 1
    SQL> /
    CUSTOMER_NUMBER CUSTOM CUSTOMER SITE_US
                  1 Fred   address1 SHIP_TO
                  2 Bob    address2 BILL_TO
                  3 George address3 SOLD_TO
                  4 Tim    address4 BILL_TO
                  5 Sam    address5 BILL_TO
    SQL>Or alternative...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (
      2    select 1 as customer_number, 'Fred' as customer_name, 'address1' as customer_address1, 'BILL_TO' as site_use_code from dual union all
      3    select 1 as customer_number, 'Fred' as customer_name, 'address1' as customer_address1, 'SHIP_TO' as site_use_code from dual union all
      4    select 2 as customer_number, 'Bob' as customer_name, 'address2' as customer_address1, 'BILL_TO' as site_use_code from dual union all
      5    select 3 as customer_number, 'George' as customer_name, 'address3' as customer_address1, 'BILL_TO' as site_use_code from dual union all
      6    select 3 as customer_number, 'George' as customer_name, 'address3' as customer_address1, 'SHIP_TO' as site_use_code from dual union all
      7    select 3 as customer_number, 'George' as customer_name, 'address3' as customer_address1, 'SOLD_TO' as site_use_code from dual union all
      8    select 4 as customer_number, 'Tim' as customer_name, 'address4' as customer_address1, 'BILL_TO' as site_use_code from dual union all
      9    select 5 as customer_number, 'Sam' as customer_name, 'address5' as customer_address1, 'BILL_TO' as site_use_code from dual
    10  )
    11  --
    12  -- END OF TEST DATA
    13  --
    14  select distinct
    15         customer_number
    16        ,customer_name
    17        ,customer_address1
    18        ,first_value(site_use_code) over (partition by customer_number order by decode(Site_use_code,'BILL_TO',1,'SHIP_TO',2,3) desc) as site_use_code
    19  FROM t
    20  WHERE Site_use_code IN ('BILL_TO','SHIP_TO','SOLD_TO')
    21* order by customer_number
    SQL> /
    CUSTOMER_NUMBER CUSTOM CUSTOMER SITE_US
                  1 Fred   address1 SHIP_TO
                  2 Bob    address2 BILL_TO
                  3 George address3 SOLD_TO
                  4 Tim    address4 BILL_TO
                  5 Sam    address5 BILL_TO

Maybe you are looking for