[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

Similar Messages

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

  • I had to put my computer by together without migration or time machine I NEED help with order of the files?

    I had to put my computer by together without migration or time machine I NEED help with order of the files?

    Hi, where are these other files exactly?

  • Need help with order booking tutorial

    Hi
    I am new to OracleFusion.
    Started Learning By practising OrderBooking tutorial for 10g.
    I am practising parellel branching in the tutorial .
    I ve invoked Rapid distributors service in branch 1 of the flow activity.
    and
    i ve invoked Select manufacturing service in branch 2 of flow activity.
    I ve deployed order booking service,rapid distributed service,select manufacturing service in the server.
    Select manufacturing service is an asynchronous service .for this service to be complete it requires user to manually set price for the item ordered.
    So I accesed SelectManufacturinUI in browser as instructed in book.The problem is tht it is directing me to login page where User id and password should be submitted.
    In the tutorial no info is given regarding login details fot this page.Hence i am not able to set price for order.
    So the Select manufacturing service is not completed ..hence i am not able to move further in the tutorial..
    Kindly help with this..if any one has faced same prblm
    thanks

    Hi
    I got the answer. Just posting it so that it helps someone
    User id i tried : jcooper
    password : Bpel console startup password

  • Need help with Order by statement

    I have a report which has an order by statement to order a varchar2 field in ascending order.
    The report sorts the records correctly but if I rerun the report, the records with the same values in the column that I order by, do not maintain the same order as was in the report's 1st run.
    The records will still be sorted in ascending order but those records that have the same values interchange positions each time I run the report.
    Is this ok or is there a way of making records with same values maintain the same order in all the report runs? Please assist. Thanks.

    user8655468 wrote:
    but those records that have the same values interchange positions each time I run the report.
    Is this ok or is there a way of making records with same values maintain the same order in all the report runs? Please assist. Thanks.Hello,
    It's normal those are same values may interchange at each run. you can add another column in order by clause. That
    Order by column1,column2 may add another column3 -- this will maintain always same but column 1,2,3 have same value , it will may interchange.
    Hope this helps
    Hamid

  • Need help with order by

    Test Data:
      CREATE TABLE "TEST_GMU"
       ( "PZINSKEY" VARCHAR2(255) NOT NULL ENABLE,
    "PXCREATEDATETIME" DATE,
    "PXURGENCYASSIGN" NUMBER(18,0),
    "WORK_PXURGENCYWORK" NUMBER(18,0),
    "MASTERACCNTFIRMCUSTID" VARCHAR2(255 CHAR)
       ) SEGMENT CREATION IMMEDIATE
      PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
    insert into test_gmu values ('ASSIGN-WORKBASKET SCHWAB-ACE-SERVICEREQUEST-WORK-ACCTMAINT AM-12858!AMADVISORSERVICESFLOW','16-JUL-13 15.55.57.000000 PM',0,40,'2531215'); 
    insert into test_gmu values ('ASSIGN-WORKBASKET SCHWAB-ACE-SERVICEREQUEST-WORK-ACCTMAINT AM-12859!AMADVISORSERVICESFLOW','16-JUL-13 15.01.22.000000 PM',0,40,'742254777');
    insert into test_gmu values ('ASSIGN-WORKBASKET SCHWAB-ACE-SERVICEREQUEST-WORK-ACCTMAINT AM-12860!AMADVISORSERVICESFLOW','16-JUL-13 15.01.23.000000 PM',0,40,'2531215'); 
    insert into test_gmu values ('ASSIGN-WORKBASKET SCHWAB-ACE-SERVICEREQUEST-WORK-ACCTMAINT AM-12861!AMADVISORSERVICESFLOW','16-JUL-13 15.03.55.000000 PM',0,40,'2568091'); 
    insert into test_gmu values ('ASSIGN-WORKBASKET SCHWAB-ACE-SERVICEREQUEST-WORK-ACCTMAINT AM-12862!AMADVISORSERVICESFLOW','16-JUL-13 15.03.56.000000 PM',0,40,'742254777');
    insert into test_gmu values ('ASSIGN-WORKBASKET SCHWAB-ACE-SERVICEREQUEST-WORK-ACCTMAINT AM-12863!AMADVISORSERVICESFLOW','16-JUL-13 15.03.57.000000 PM',0,40,'2568091'); 
    insert into test_gmu values ('ASSIGN-WORKBASKET SCHWAB-ACE-SERVICEREQUEST-WORK-ACCTMAINT AM-12864!AMADVISORSERVICESFLOW','16-JUL-13 15.06.29.000000 PM',0,40,'742254777');
    insert into test_gmu values ('ASSIGN-WORKBASKET SCHWAB-ACE-SERVICEREQUEST-WORK-ACCTMAINT AM-12865!AMADVISORSERVICESFLOW','16-JUL-13 15.06.31.000000 PM',0,40,'2568091'); 
    insert into test_gmu values ('ASSIGN-WORKBASKET SCHWAB-ACE-SERVICEREQUEST-WORK-ACCTMAINT AM-12866!AMADVISORSERVICESFLOW','16-JUL-13 15.06.32.000000 PM',0,40,'742254777');
    The output required is like below
    1.       AM-12859 BXYZAB CO. 742254777  07/16/2013 15:01:21
    2.       AM-12862 BXYZAB CO. 742254777  07/16/2013 15:03:56
    3.       AM-12864 BXYZAB CO. 742254777  07/16/2013 15:06:27
    4.       AM-12866 BXYZAB CO. 742254777  07/16/2013 15:06:31
    5.       AM-12858 WHIJKL CO.  2531215  07/16/2013 15:01:16       The values of this timestamp is actually '16-JUL-13 15.55.57 in datbase
    6.       AM-12860 WHIJKL CO.  2531215  07/16/2013 15:01:22
    7.       AM-12861 SIJKLM CO.  2568091  07/16/2013 15:03:54
    8.       AM-12863 SIJKLM CO.  2568091  07/16/2013 15:03:56
    9.       AM-12865 SIJKLM CO.  2568091  07/16/2013 15:06:30
    I could work this out till below:
    ASSIGN-WORKBASKET SCHWAB-ACE-SERVICEREQUEST-WORK-ACCTMAINT AM-12859!AMADVISORSERVICESFLOW 7/16/2013 3:01:22 PM 0 40 742254777
    ASSIGN-WORKBASKET SCHWAB-ACE-SERVICEREQUEST-WORK-ACCTMAINT AM-12862!AMADVISORSERVICESFLOW 7/16/2013 3:03:56 PM 0 40 742254777
    ASSIGN-WORKBASKET SCHWAB-ACE-SERVICEREQUEST-WORK-ACCTMAINT AM-12864!AMADVISORSERVICESFLOW 7/16/2013 3:06:29 PM 0 40 742254777
    ASSIGN-WORKBASKET SCHWAB-ACE-SERVICEREQUEST-WORK-ACCTMAINT AM-12866!AMADVISORSERVICESFLOW 7/16/2013 3:06:32 PM 0 40 742254777
    ASSIGN-WORKBASKET SCHWAB-ACE-SERVICEREQUEST-WORK-ACCTMAINT AM-12861!AMADVISORSERVICESFLOW 7/16/2013 3:03:55 PM 0 40 2568091 
    ASSIGN-WORKBASKET SCHWAB-ACE-SERVICEREQUEST-WORK-ACCTMAINT AM-12863!AMADVISORSERVICESFLOW 7/16/2013 3:03:57 PM 0 40 2568091 
    ASSIGN-WORKBASKET SCHWAB-ACE-SERVICEREQUEST-WORK-ACCTMAINT AM-12865!AMADVISORSERVICESFLOW 7/16/2013 3:06:31 PM 0 40 2568091 
    ASSIGN-WORKBASKET SCHWAB-ACE-SERVICEREQUEST-WORK-ACCTMAINT AM-12860!AMADVISORSERVICESFLOW 7/16/2013 3:01:23 PM 0 40 2531215 
    ASSIGN-WORKBASKET SCHWAB-ACE-SERVICEREQUEST-WORK-ACCTMAINT AM-12858!AMADVISORSERVICESFLOW 7/16/2013 3:55:57 PM 0 40 2531215
    with order by masteraccntfirmcustid desc ,pxcreatedatetime
    But one of the developer told me masteraccntfirmcustid should be asc
    This resultset is supposed to be ordered by
    order by masteraccntfirmcustid ,pxurgencyassign desc NULLS LAST ,work_pxurgencywork desc NULLS LAST,pxcreatedatetime
    in the test data I have been given pxurgencyassign and work_pxurgencywork is same for all the records
    Could you please help?
    Thanks,
    swapnil

    the results of the query are not matching the data in the table.  like ....
    1.      BXYZAB CO.
    2.      BXYZAB CO.
    3.      BXYZAB CO.

  • Need help with order cancellation

    Ordered Carbon ultrabook on last friday, I just called and also submitted the cancellation form online. Lenovo customer service sucks... keep telling me that they could not gurantee the cancellation since it's process! what process! The email I received after placing order told me the item won't ship out until 8/12! If they could send it out NOW, I will take it, but the point is they couldn't, then don't tell me they can't gurantee. Besides, it took so long to speak to a real person!

    SCC914,
    It can take 24+ hours for the cancellation request sent to the factory to be received and accepted.
    I agree that this is not ideal, and as we live in an increasingly networked world, we expect things to happen in almost real time.
    We'll arrange some further assitance for you - could you send me a PM with your order number that you are trying to get cancelled?
    Thanks
    Mark
    ThinkPads: S30, T43, X60t, X1, W700ds, IdeaPad Y710, IdeaCentre: A300, IdeaPad K1
    Mark Hopkins
    Program Manager, Lenovo Social Media (Services)
    twitter @lenovoforums
    English Community   Deutsche Community   Comunidad en Español   Русскоязычное Сообщество

  • Need Help with Order import corrections

    Hi Experts,
    I 'am trying to edit the data entered into the interface tables for a failed order import through the corrections window. I made changes to the error attribute, say - Inventory_item_id for lines and saved the changes. When I click on "Validate", I always get the error: "Error You are trying to insert an existing order or update an order that does not exist. Please enter a correct operation code." I get the same error for "UPDATE" and "CREATE" and blank values for "Operation Code".
    Can you please guide me on how to use the corrections window to import a failed order.
    Thanks,
    Ganapathi

    I 'am not certain whether I 'am using the corrections window incorrectly or this is a bug. Please suggest. I 'am on 12.0.6. The "Import" button remains disabled and the "Validate" button always fails. Any inputs on this will be immensely helpful.
    Thanks,
    Ganapathi

  • Need help with order site.

    mxgraphicsnew          Im trying to  figure out how to build the right side of this page something like that one

    You can surely insert multiple text box in your form where users can fill in the details , regarding paypal button , you can either place the button on same page or create a separate landing page for form , where after submission users will be redirected and then final payment can be carried on with paypal button.
    Thanks,
    Anshul

  • Need help with loading MySQL results into a query

    Hello, I need some help figuring out why my tree component
    isn't being populated with my MySQL results.
    I have a table of categories:
    ParentID - CategoryID - Name
    Every top-level category has a ParentID of 0 (zero). I'm
    using php and a recursive function to build an array of nested
    results, then passing those results back to Flex, making those
    results a new ArrayCollection, then assigning that to the
    dataProvider of the tree.
    Result: my tree component is blank
    Suspicion: it has to be a way with how my array is being
    formed in PHP. If I play around with how it is formed I can get
    some odd results in the tree, so I know it's not a problem with the
    data being passed back to Flex.
    I am attaching the PHP code used to form the array, and the
    output of the array being created

    Why not just build xml and send it back? Xml is hierarchical
    by nature.
    However, if you want to stick with the nested ACs then are
    you using a labelFunction() with your tree? The node values are in
    different properties, so you can't just set labelField.
    Tracy

  • Need help with detail by hour in SQL query

    Hello all,
    I am using the following query to track the usage on a circuit and I have the detail by day, but now they are asking for hourly usage from 0900 to 1200 on these days. Any ideas how I can append to include hour in my detail?
    select 'Report Name Here'  as Circuit,'Usage'  as Measurement,
     MONTH(interfacetraffic.datetime) as month, year(interfacetraffic.datetime) as year, day(interfacetraffic.datetime) as day,
     '' as Mo_yr,
     interfaces.inbandwidth as bandwidth,
      '' as adjustedbandwidth,
     max (interfacetraffic.in_maxbps )  as max_in,
    max (interfacetraffic.out_maxbps)  as max_out,
    avg(interfacetraffic.in_maxbps )  as avg_in,
    avg(interfacetraffic.out_maxbps)  as avg_out,
    max(case (interfacetraffic.in_maxbps ) when 0 then 0  else(interfacetraffic.in_maxbps  )/interfaces.inbandwidth *100 end) as 'max_in_%',
    max(case ( interfacetraffic.out_maxbps) when 0 then 0  else( interfacetraffic.out_maxbps )/interfaces.outbandwidth *100 end) as 'max_out_%',
    avg(case (interfacetraffic.in_maxbps ) when 0 then 0  else(interfacetraffic.in_maxbps  )/interfaces.inbandwidth *100 end) as 'avg_in_%',
    avg(case ( interfacetraffic.out_maxbps) when 0 then 0  else( interfacetraffic.out_maxbps )/interfaces.outbandwidth *100 end) as 'avg_out_%',
    nodes.location as location,nodes.sysname as sysname,nodes.timezone,interfaces.interfaceid as interfaceid,nodes.nodeid as nodeid,interfaces.fullname as fullname
     FROM 
    (Nodes INNER JOIN Interfaces ON (Nodes.NodeID = Interfaces.NodeID))  
    INNER JOIN InterfaceTraffic ON (Interfaces.InterfaceID = InterfaceTraffic.InterfaceID AND InterfaceTraffic.NodeID = Nodes.NodeID)
    where InterfaceTraffic.DateTime > GETDATE() -180
    and interfaces.InterfaceID = '31072'
    and month(interfacetraffic.datetime) = 1
    and year(interfacetraffic.datetime) = 2015
    --and  DATEPART(hh,interfacetraffic.datetime)  in ('09','10','11','12','13','14','15','16','17','18','19')
    group by interfaces.inbandwidth, year(interfacetraffic.datetime), 
    MONTH(interfacetraffic.datetime) ,nodes.location ,nodes.sysname,interfaces.inbandwidth,nodes.timezone ,interfaces.interfaceid,nodes.nodeid,interfaces.fullname, day(interfacetraffic.datetime) 
    --DAY(InterfaceTraffic.DateTime)

    select 'Report name here' as Circuit, 'Usage' as Measurement,
    month(...) as month, year(...) as year, day(...) as day, datepart(hour, ...) as hour,
    from ...
    group by month(...), year(...), day(...), datepart(hour, ...), ...
    Note - have you considered just having a single column for the date as opposed to 3 separate columns? And for efficiency, change your where clause from
    where InterfaceTraffic.DateTime > GETDATE() -180
    and interfaces.InterfaceID = '31072'
    and month(interfacetraffic.datetime) = 1
    and year(interfacetraffic.datetime) = 2015
    to
    where interfaces.InterfaceID = '31072'
    and interfacetraffic.datetime >= '20150101' and interfacetraffic.datetime < '20150201'
    and datepart(hour, ...) between 9 and 19
    That first part involving "getdate() - 180" does nothing useful when you only want values from January of this year.

  • 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

  • LSMW - Need help with Sales Order (Modification VA01)

    Hi,
    I need help with an LSMW for Sales Order (VA01).
    I need to do the following:
    1. Copy the Standard Sales Order LSMW
    2. They (users) would like to be able to pick the batch (lot) from the sales order.
    3. Also, they would like to have functionality, where from the list of Sales Order numbers, they would be able to switch one part number for another.
    Please help with the above 3 needs.
    Thanks,
    Laura

    Hi
    Run transaction SE38, insert your program (RVINVB10), select DOCUMENTATION option and press display
    Just only you need to consider the BDC program needs to read afile with all informations to create a sales order, so you have to create a program to prepare a file arraged as RVINVB10 needs, the documentaion explains how the file has to be created.
    Max

  • Need help with Pivoting rows to columns

    Hi,
    I need help with pivoting rows to columns. I know there are other posts regarding this, but my requirement is more complex and harder. So, please give me a solution for this.
    There are two tables say Table 1 and Table 2.
    Table1
    name address email identifier
    x e g 1
    f s d 2
    h e n 3
    k l b 4
    Table2
    identifier TRno zno bzid
    1 T11 z11 b11
    1 T12 z12 b12
    1 T13 z13 b13
    2 T21 z21 b21
    2 T22 z22 b22
    As you can see the identifier is the column that we use to map the two tables. The output should be like below
    output
    name address email identifier TRno1 zno1 bzid1 TRno2 zno2 bzid2 TRno3 zno3 bzid3
    x e g 1 T11 z11 b11 T12 z12 b12 T13 z13 b13
    f s d 2 T21 z21 b21 t22 z22 b22
    Also we do not know exactly how many TRno's, zno's, etc each value in the identifier will have. There may be only 1 TRNO, zno and bzid, or there may be four.
    All the values must be in separate columns, and not be just comma delimitted. There are also other conditions that i have to add to restrict the data.
    So, can you please tell me what is should use to get the data in the required format? We are using Oracle 10g. Please let me know if u need any more information

    Something like this ?
    SCOTT@orcl> ed
    Wrote file afiedt.buf
      1  select a.name,
      2  a.address,
      3  a.email,
      4  b.* from (
      5  select distinct identifier
      6  ,max(trno1) trno1
      7  ,max(zno1) zno1
      8  ,max(bzid1) bzid1
      9  ,max(trno2) trno2
    10  ,max(zno2) zno2
    11  ,max(bzid2) bzid2
    12  ,max(trno3) trno3
    13  ,max(zno3) zno3
    14  ,max(bzid3) bzid3
    15  ,max(trno4) trno4
    16  ,max(zno4) zno4
    17  ,max(bzid4) bzid4
    18  from (select identifier
    19  ,decode(rn,1,trno,null) trno1
    20  ,decode(rn,1,zno,null) zno1
    21  ,decode(rn,1,bzid,null) bzid1
    22  ,decode(rn,2,trno,null) trno2
    23  ,decode(rn,2,zno,null) zno2
    24  ,decode(rn,2,bzid,null) bzid2
    25  ,decode(rn,3,trno,null) trno3
    26  ,decode(rn,3,zno,null) zno3
    27  ,decode(rn,3,bzid,null) bzid3
    28  ,decode(rn,4,trno,null) trno4
    29  ,decode(rn,4,zno,null) zno4
    30  ,decode(rn,4,bzid,null) bzid4
    31  from (select identifier,
    32  trno,bzid,zno,
    33  dense_rank() over(partition by identifier order by trno,rownum) rn
    34  from table2)
    35  order by identifier)
    36  group by identifier) b,table1 a
    37* where a.identifier=b.identifier
    SCOTT@orcl> /
    NAME       ADDRESS    EMAIL      IDENTIFIER TRNO1      ZNO1       BZID1      TRNO2      ZNO2       BZID2      TRNO3      ZNO3       BZID3      TRNO4      ZNO4       BZID4
    x          e          g          1          T11        z11        b11        T12        z12        b12        T13        z13        b13
    f          s          d          2          T21        z21        b21        T22        z22        b22
    SCOTT@orcl> select * from table1;
    NAME       ADDRESS    EMAIL      IDENTIFIER
    x          e          g          1
    f          s          d          2
    h          e          n          3
    k          l          b          4
    SCOTT@orcl> select * from table2;
    IDENTIFIER TRNO       ZNO        BZID
    1          T11        z11        b11
    1          T12        z12        b12
    1          T13        z13        b13
    2          T21        z21        b21
    2          T22        z22        b22
    SCOTT@orcl>Regards
    Girish Sharma

  • I need help with Analytic Function

    Hi,
    I have this little problem that I need help with.
    My datafile has thousands of records that look like...
    Client_Id Region Countries
    [1] [1] [USA, Canada]
    [1] [2] [Australia, France, Germany]
    [1] [3] [China, India, Korea]
    [1] [4] [Brazil, Mexico]
    [8] [1] [USA, Canada]
    [9] [1] [USA, Canada]
    [9] [4] [Argentina, Brazil]
    [13] [1] [USA, Canada]
    [15] [1] [USA]
    [15] [4] [Argentina, Brazil]
    etc
    My task is is to create a report with 2 columns - Client_Id and Countries, to look something like...
    Client_Id Countries
    [1] [USA, Canada, Australia, France, Germany, China, India, Korea, Brazil, Mexico]
    [8] [USA, Canada]
    [9] [USA, Canada, Argentina, Brazil]
    [13] [USA, Canada]
    [15] [USA, Argentina, Brazil]
    etc.
    How can I achieve this using Analytic Function(s)?
    Thanks.
    BDF

    Hi,
    That's called String Aggregation , and the following site shows many ways to do it:
    http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
    Which one should you use? That depends on which version of Oracle you're using, and your exact requirements.
    For example, is order importatn? You said the results shoudl include:
    CLIENT_ID  COUNTRIES
    1        USA, Canada, Australia, France, Germany, China, India, Korea, Brazil, Mexicobut would you be equally happy with
    CLIENT_ID  COUNTRIES
    1        Australia, France, Germany, China, India, Korea, Brazil, Mexico, USA, Canadaor
    CLIENT_ID  COUNTRIES
    1        Australia, France, Germany, USA, Canada, Brazil, Mexico, China, India, Korea?
    Mwalimu wrote:
    ... How can I achieve this using Analytic Function(s)?The best solution may not involve analytic functions at all. Is that okay?
    If you'd like help, post your best attempt, a little sample data (CREATE TABLE and INSERT statements), the results you want from that data, and an explanation of how you get those results from that data.
    Always say which version of Oracle you're using.
    Edited by: Frank Kulash on Aug 29, 2011 3:05 PM

Maybe you are looking for

  • SEFAZ_MG de Produção  - Erro de certificado digital

    Boa tarde. Estou com o seguinte problema: O serviço SRVSC (verifica status na SEFAZ) para MG está retornando o erro abaixo: Message processing failed. Cause: com.sap.aii.af.ra.ms.api.MessagingException: iaik.security.ssl.SSLCertificateException: Peer

  • EDI incoming doc verification

    I am new to EDI processing.  How do I verify docs company said they sent were received into SAP ?  Company sending files is using  startrfc to execute function module EDI_DATA_INCOMING.  They execute EDI_DATA_INCOMING for each file sent.  If they say

  • Error #1053: Illegal override of getPollSyncMessageResponder in mx.messaging.channels.HTTPChannel

    Hi, I have a long term project that has been developed over the past year+ and I upgraded from Flex 3.3 to 3.4.1. After doing this I started to receive this message when I run my application: VerifyError: Error #1053: Illegal override of getPollSyncM

  • Transport connect Hang

    Hello to all, i have developed a very simple mail UI to send email but i encounter error where when the debug pointer reach this statement private final static String myHost = "smtp.gmail.com"; Username is the email address. try { myTransport.connect

  • Windows 7 Installed On NB205-N311/W, Working Just Fine

    Right out of the box, Windows 7 worked just fine. Wireless worked, sound worked, even my wireless mouse worked without having to add any additional drivers. Next I had Microsoft Update install everything that it thought I needed. Then I installed tho