CONNECT BY LOV - includes join to another table

I am trying to create a LOV that displays a dynamic list of clerks. I need the list to show everyone underneath the person logged in. I have been able to get a CONNECT BY statement to work that shows this for the organizations, but I need to link this to the users. Can someone help me out? I know that I'm going to need either an inline query or a view, as the CONNECT BY clause doesn't like joins.
Here are two pieces I have right now:
Shows Organizational hierarchy
SELECT PADDING d, ID r
  FROM (SELECT ORG_ID,
            ORG_NM,
            MNG_ORG_ID,
            LEVEL,
            SYS_CONNECT_BY_PATH(ORG_ID, '/') || ' ' || ORG_NM as FULL_PATH,
            LPAD('  ', 2*(LEVEL-1), '-') || ORG_NM as PADDING
          FROM ORG_ENTITIES
         WHERE ACTIVE = 1
           AND LEVEL > 1 START WITH ORG_ID = 999
         CONNECT BY PRIOR ORG_ID = MNG_ORG_ID
         ORDER BY 5) XXXLists all the clerks
select x.ADMIN_USERNAME, x.ID, x.ORG_ID, g.MNG_ORG_ID
  from APEX_ACCESS_CONTROL x, ORG_ENTITIES g
where x.ORG_ID = g.ORG_ID
   and x.CLERK = 'Y'
   and x.ADMIN_USERNAME NOT LIKE '%.LOCKED'

Actually, I just need the people. It's just that I don't have a manager ID to refer to; I have to use the ORG_ID.
select lpad(' ',level*2,' ')||x.ADMIN_USERNAME d, x.ID r
  from (select x.ADMIN_USERNAME, x.ID, x.ORG_ID, g.MNG_ORG_ID
          from APEX_ACCESS_CONTROL x, ORG_ENTITIES g
         where x.ORG_ID = g.ORG_ID
           and x.CLERK = 'Y'
           and x.ADMIN_USERNAME NOT LIKE '%.LOCKED') x
   START WITH x.ID = :PXXX
CONNECT BY PRIOR x.ORG_ID = x.MNG_ORG_IDThis does the trick. My problem was that I was trying to start at too high of a level and was getting every single tree. By starting down one level I saw I was getting what I needed.

Similar Messages

  • Adding a single table without a logical join to another table (OBIEE 10g)

    Sometimes I want to just display a single table without a logical join to another table in the repository. However, everytime I move it to the Business Model and Mapping layer and perform a Global Consistency Check, it tells me that it needs a logical join and I am forced to create another table to join to it. Thus creating a dimension-fact relationship. There are times I don't need this relationship and just want to display some data. Is there anyway to get around this?
    Thanks in advance!

    Yes,You have to create a join.You cannot take single table to BMM layer.You can create an alias of the table.Join this alias and base table through any common column and take both tables to BMM and desired table to presentation layer.
    Another way is to create a view in physcial layer.Write a select statement like
    Select primary_key from Table
    Where primary_key is primary key of base table.Join this view ith base table and repeat the steps defined for Alias.
    Regards,
    Sandeep

  • Where clause with XMLExists and join on another table

    Hi,
    We have table like:
    drop table xml_tbl;
    create table xml_tbl (
    xml_msg_id integer,
    xml_msg_text xmltype
    insert into xml_tbl values
    (1, '<main><id>1</id></main>') ;
    insert into xml_tbl values --(xml_msg_id,xml_msg_text)
    (1, '<main><id>2</id></main>') ;
    Another table like:
    create Table Table1
    ( id1 int);
    Insert into Table1 values(2);
    Insert into Table1 values(3);
    We need to have a view on top of the table xml_tbl where /main/id should have only those values which are in id1 column of table Table1.
    Something like
    CREATE OR REPLACE VIEW V_xml_tbl
    xml_msg_text
    AS
    SELECT T.xml_msg_text
    FROM xml_tbl T
    WHERE XMLEXISTS (
    'declare namespace Namesp1 ="Abc:Set";
    let $Results as xs:boolean := fn:exists($p/main/id in (Select id1 from Table1)) --Now here I know I can't do Select id1 from
    Table1*
    return if ($Results ) then true() else ()'
    PASSING T.xml_msg_text AS "p");
    Actually in the real scenario Table1 will have many IDs and xml_tbl has many XML files..
    So I am stuck on how to do it. Please help.
    Thanks..
    Edited by: user8941550 on Nov 20, 2012 7:19 PM

    One of these two :
    SQL> select t.xml_msg_text
      2  from xml_tbl t
      3  where exists (
      4    select null
      5    from table1 t1
      6    where t1.id1 = xmlcast(
      7                     xmlquery('/main/id' passing t.xml_msg_text returning content)
      8                     as integer
      9                   )
    10  );
    XML_MSG_TEXT
    <main>
      <id>2</id>
    </main>
    SQL> select t.xml_msg_text
      2  from xml_tbl t
      3     , xmltable('/main' passing t.xml_msg_text
      4         columns id integer path 'id'
      5       ) x
      6  where exists (
      7    select null
      8    from table1 t1
      9    where t1.id1 = x.id
    10  );
    XML_MSG_TEXT
    <main>
      <id>2</id>
    </main>
    And a third one, using XMLExists :
    SQL> select t.xml_msg_text
      2  from xml_tbl t
      3  where xmlexists (
      4    'fn:collection("oradb:/DEV/TABLE1")/ROW[ID1=$d/main/id]'
      5    passing t.xml_msg_text as "d"
      6  );
    XML_MSG_TEXT
    <main>
      <id>2</id>
    </main>
    Execution Plan
    Plan hash value: 3633580934
    | Id  | Operation           | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |         |     2 |   116 |     8   (0)| 00:00:01 |
    |*  1 |  FILTER             |         |       |       |            |          |
    |   2 |   TABLE ACCESS FULL | XML_TBL |     2 |   116 |     3   (0)| 00:00:01 |
    |   3 |   NESTED LOOPS      |         |     1 |     5 |     5   (0)| 00:00:01 |
    |   4 |    TABLE ACCESS FULL| TABLE1  |     2 |     6 |     3   (0)| 00:00:01 |
    |*  5 |    XPATH EVALUATION |         |       |       |            |          |
    Predicate Information (identified by operation id):
       1 - filter( EXISTS (SELECT 0 FROM "DEV"."TABLE1"
                  "SYS_ORAVW_2",XPATHTABLE('/main/id' PASSING :B1 COLUMNS "C_00$" XMLTYPE
                  PATH '.', "C_01$" XQEXVAL CHAR PATH '.')  "P" WHERE
                  TO_BINARY_DOUBLE("ID1")=TO_BINARY_DOUBLE("P"."C_01$")))
       5 - filter(TO_BINARY_DOUBLE("ID1")=TO_BINARY_DOUBLE("P"."C_01$"))The plan is similar to that of the second query above (XMLTable/EXISTS).
    Still using XMLExists, a plan similar to the first query (EXISTS/XMLCast/XMLQuery) can be achieved by casting id to an integer datatype :
    SQL> select t.xml_msg_text
      2  from xml_tbl t
      3  where xmlexists (
      4    'fn:collection("oradb:/DEV/TABLE1")/ROW[ID1=xs:int($d/main/id)]'
      5    passing t.xml_msg_text as "d"
      6  );
    XML_MSG_TEXT
    <main>
      <id>2</id>
    </main>
    Execution Plan
    Plan hash value: 1149640166
    | Id  | Operation          | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |         |     1 |    61 |     7  (15)| 00:00:01 |
    |*  1 |  HASH JOIN SEMI    |         |     1 |    61 |     7  (15)| 00:00:01 |
    |   2 |   TABLE ACCESS FULL| XML_TBL |     2 |   116 |     3   (0)| 00:00:01 |
    |   3 |   TABLE ACCESS FULL| TABLE1  |     2 |     6 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - access("ID1"=SYS_XQ_ATOMCNVCHK(TO_NUMBER(SYS_XQ_UPKXML2SQL(SYS_XQ
                  EXVAL(SYS_XQEXTRACT(SYS_MAKEXML(0,"T"."SYS_NC00003$"),'/main/id'),1,50,3
                  3792,8192),50,1,0)),2,37))
    Note
       - Unoptimized XML construct detected (enable XMLOptimizationCheck for more information)Check each one on your real scenario to see which show best performance.
    (I would tend to say the ones involving streaming evaluation)
    Edited by: odie_63 on 5 nov. 2012 12:24
    Edited by: odie_63 on 5 nov. 2012 12:38

  • Update Problem - Join With Another Table

    I'm trying to convert few MS Access Queries into Oracle. Following is one of the query from MS Access.
    <font face="courier">
    UPDATE [RESULT] INNER JOIN [MASTER]
        ON ([RESULT].[LAST_NAME] = [MASTER].[LAST_NAME])
       AND ([RESULT].[FIRST_NAME] = [MASTER].[FIRST_NAME])
       AND ([RESULT].[DOCUMENT_NUMBER] = [MASTER].[DOCUMENT_NUMBER])
       AND ([RESULT].[BATCH_ID] = [MASTER].[LEAD_ID])
    SET [MASTER].[CLOSURE_REASON] = "Closed For Name and Document Number Match",
        [MASTER].[RESULT_ID] = [RESULT].[ID],
        [MASTER].[RESULT_PID] = [RESULT].[PID]
    WHERE (([MASTER].[CLOSURE_REASON] Is Null)
       AND ([MASTER].[REC_CODE] = "A1")
       AND ([RESULT].[EVENT_DATE] = [MASTER].[EVENT_DATE])
       AND ([RESULT].[EVENT_TYPE] = "Open")
       AND ([MASTER].[DOCUMENT_NUMBER] Is Not Null)
       AND ([MASTER].[DOCUMENT_NUMBER)] "null"));
    </font>
    First I received ORA-01779: cannot modify a column which maps to a non key-preserved table Error. I followed different examples (including MERGE) from your
    site and modified my original query. Now, I receive ORA-30926: unable to get a stable set of rows in the source tables Error.
    Most of the examples showed only one join between the tables but I have to make more joins based on my requirements.
    Any help translating this query in to Oracle would be Great. Thanks!

    Assuming that the columns you are joining to in the result table are the whole PK or are declared as aunique contraint (i.e. some combination of last_name, first_name, document_number, batch_id, event_date, id, and pid make up the entire PK/unique constraint), then the updateable join view should look something like:
    update (select m.last_name, m.first_name, m.document_number, m.lead_id,
                   m.closure_reason, m.result_id, r.id, m.result_pid, r.pid
            from master m
               join result r
                  on r.last_name = m.last_name and
                     r.first_name = m.first_name and
                     r.document_number = m.document_number and
                     r.batch_id = m.lead_id and
                     r.event_date = m.event_date
            where m.closure_reason is null and
                  m.rec_code = 'A1' and
                  r.event_type = 'Open' and
                  m.document_number is not null and
                  m.document_number != 'null')
    set closure_reason = 'Closed For Name and Document Number Match',
        result_id = id,
        result_pid = pidThe merge version would look something like:
    merge into master
       using (select last_name, first_name, document_number, batch_id,
                     event_date, id, pid
              from result
              where event_type = 'Open') r
       on (r.last_name = m.last_name and
           r.first_name = m.first_name and
           r.document_number = m.document_number and
           r.batch_id = m.lead_id and
           r.event_date = m.event_date)
       when mathed then
          update
          set closure_reason = 'Closed For Name and Document Number Match',
              result_id = id,
              result_pid = pid
          where m.closure_reason is null and
                m.rec_code = 'A1' and
                m.document_number is not null and
                m.document_number != 'null';However, as Hoek pointed out, the combination of last_name, first_name, document_number, batch_id, event_date, id, and pid must point to a unique row in the result table, whether they make up the PK or a unique constraint. If there are, or could be, multiple rows for a particular combination of last_name, first_name, document_number, batch_id, event_date, id, and pid, then you will need to find a way to determine which of those rows should be used to do the update.
    John

  • Join with another table in pre-query

    Hi,
    We have a large data block and we need to order some columns based on street name for example, not id. The base table of db block contains an id_street column, and 'streets' table contains id and name.
    Ok, in pre-query trigger of that block, we have a complex logic and we dynamically build the where clause. At the end, we set the order_By clause of the block, to order the rows, for example we need to order by the 'my_date' column asc (it's a date type column), and street desc; but street NAME, not id. We don't want to use a from clause query, because the dynamically where clause logic it's complex.
    How can we join the db block table with 'streets' table in pre-query, so when constructing the order by clause to specify something like
    set_block_property('ADRESE_NEZONATE', order_by, 'my_date, name desc');where 'name' is the name of the street, from the 'streets' table.
    Is it possible in pre-query, somehow? Or, in my case where can I join with that table and use that column in pre-query at setting order by?
    Thanks!
    Edited by: Roger25 on 26.04.2013 12:31

    I understand what you say but partially.. please explain in more detail how to do that;
    How should look the adrese_nezonate block, then? I have to add a 'name' column and set copy value from item property to 'STREETS.NAME', and database_property No?
    Then the post-query trigger how should look like (the order by clause)? The post-query sends the entire query (with where/order by clauses) to the server, but in that "select... where... order by" (built dynamically) there are only columns from that block (adrese_nezonate). I need to join with streets, INSIDE that query.
    Thanks.

  • Tables of View Joined in Wrong Order When View Joined to Other Tables

    I have the following view:
    select
         distinct
         'PKG' item_type_code,
         msibk.organization_id,
         msibk.inventory_item_id
    from
         mtl_system_items_b_kfv msibk,
         mtl_item_categories mic,
         mtl_default_category_sets mdcs,
         mtl_categories_b_kfv mcbk
    where
         msibk.organization_id = mic.organization_id
         and msibk.inventory_item_id = mic.inventory_item_id
         and mic.category_set_id = mdcs.category_set_id
         --1 Inventory (Lookup = MTL_FUNCTIONAL_AREAS)
         and mdcs.functional_area_id = 1
         and mic.category_id = mcbk.category_id
         and mcbk.segment1 = 'EXP'
         and mcbk.segment2 in ( 'PACKAGING' )When I access the columns like this:
    select
    from
         xxcus_mtl_sys_item_types_v
    where
         organization_id = :1
         and inventory_item_id = :2
         and item_type_code = :3It correctly accesses MTL_SYSTEM_ITEMS_B second in the explain plan and everything is good.
    But when it is part of a join, it accesses MTL_SYSTEM_ITEMS_B last in the explain plan and has performance issues.
    select
         msi.segment1
    from
         xxcus_mtl_sys_item_types_v x,
         mtl_system_items msi
    where
         msi.organization_id = x.organization_id
         and msi.inventory_item_id = x.inventory_item_id
         and x.item_type_code = 'PAK'Any ideas why the view tables are getting joined incorrectly when the view is joined with another table?
    Thanks,
    Kurz

    The query I posted for the view is just an excerpt. It is several nearly identical queries with UNION ALL between them. I get the same results when I have only one query in the view.
    Here is the explain plan for the first query:
    | Id  | Operation                          | Name                         | Rows  | Bytes | Cost (%CPU)|
    |   0 | SELECT STATEMENT                   |                              |     5 |   160 |    25  (20)|
    |   1 |  VIEW                              | XXCUS_MTL_SYS_ITEM_TYPES_V   |     5 |   160 |    25  (20)|
    |   2 |   UNION-ALL                        |                              |       |       |            |
    |   3 |    SORT UNIQUE NOSORT              |                              |     1 |    71 |     5  (20)|
    |*  4 |     FILTER                         |                              |       |       |            |
    |   5 |      NESTED LOOPS                  |                              |     1 |    71 |     4   (0)|
    |   6 |       NESTED LOOPS                 |                              |     1 |    36 |     3   (0)|
    |   7 |        NESTED LOOPS                |                              |     1 |    17 |     1   (0)|
    |   8 |         TABLE ACCESS BY INDEX ROWID| MTL_DEFAULT_CATEGORY_SETS    |     1 |     8 |     1   (0)|
    |*  9 |          INDEX UNIQUE SCAN         | MTL_DEFAULT_CATEGORY_SETS_U1 |     1 |       |     0   (0)|
    |* 10 |         INDEX UNIQUE SCAN          | MTL_SYSTEM_ITEMS_B_U1        |     1 |     9 |     0   (0)|
    |* 11 |        INDEX RANGE SCAN            | MTL_ITEM_CATEGORIES_U1       |     1 |    19 |     2   (0)|
    |* 12 |       TABLE ACCESS BY INDEX ROWID  | MTL_CATEGORIES_B             |     1 |    35 |     1   (0)|
    |* 13 |        INDEX UNIQUE SCAN           | MTL_CATEGORIES_B_U1          |     1 |       |     0   (0)|
    |  14 |    SORT UNIQUE NOSORT              |                              |     1 |    63 |     5  (20)|
    |* 15 |     FILTER                         |                              |       |       |            |
    |  16 |      NESTED LOOPS                  |                              |     1 |    63 |     4   (0)|
    |  17 |       NESTED LOOPS                 |                              |     1 |    36 |     3   (0)|
    |  18 |        NESTED LOOPS                |                              |     1 |    17 |     1   (0)|
    |  19 |         TABLE ACCESS BY INDEX ROWID| MTL_DEFAULT_CATEGORY_SETS    |     1 |     8 |     1   (0)|
    |* 20 |          INDEX UNIQUE SCAN         | MTL_DEFAULT_CATEGORY_SETS_U1 |     1 |       |     0   (0)|
    |* 21 |         INDEX UNIQUE SCAN          | MTL_SYSTEM_ITEMS_B_U1        |     1 |     9 |     0   (0)|
    |* 22 |        INDEX RANGE SCAN            | MTL_ITEM_CATEGORIES_U1       |     1 |    19 |     2   (0)|
    |* 23 |       TABLE ACCESS BY INDEX ROWID  | MTL_CATEGORIES_B             |     1 |    27 |     1   (0)|
    |* 24 |        INDEX UNIQUE SCAN           | MTL_CATEGORIES_B_U1          |     1 |       |     0   (0)|
    |  25 |    SORT UNIQUE NOSORT              |                              |     1 |    71 |     5  (20)|
    |* 26 |     FILTER                         |                              |       |       |            |
    |  27 |      NESTED LOOPS                  |                              |     1 |    71 |     4   (0)|
    |  28 |       NESTED LOOPS                 |                              |     1 |    36 |     3   (0)|
    |  29 |        NESTED LOOPS                |                              |     1 |    17 |     1   (0)|
    |  30 |         TABLE ACCESS BY INDEX ROWID| MTL_DEFAULT_CATEGORY_SETS    |     1 |     8 |     1   (0)|
    |* 31 |          INDEX UNIQUE SCAN         | MTL_DEFAULT_CATEGORY_SETS_U1 |     1 |       |     0   (0)|
    |* 32 |         INDEX UNIQUE SCAN          | MTL_SYSTEM_ITEMS_B_U1        |     1 |     9 |     0   (0)|
    |* 33 |        INDEX RANGE SCAN            | MTL_ITEM_CATEGORIES_U1       |     1 |    19 |     2   (0)|
    |* 34 |       TABLE ACCESS BY INDEX ROWID  | MTL_CATEGORIES_B             |     1 |    35 |     1   (0)|
    |* 35 |        INDEX UNIQUE SCAN           | MTL_CATEGORIES_B_U1          |     1 |       |     0   (0)|
    |  36 |    SORT UNIQUE NOSORT              |                              |     1 |    71 |     5  (20)|
    |* 37 |     FILTER                         |                              |       |       |            |
    |  38 |      NESTED LOOPS                  |                              |     1 |    71 |     4   (0)|
    |  39 |       NESTED LOOPS                 |                              |     1 |    36 |     3   (0)|
    |  40 |        NESTED LOOPS                |                              |     1 |    17 |     1   (0)|
    |  41 |         TABLE ACCESS BY INDEX ROWID| MTL_DEFAULT_CATEGORY_SETS    |     1 |     8 |     1   (0)|
    |* 42 |          INDEX UNIQUE SCAN         | MTL_DEFAULT_CATEGORY_SETS_U1 |     1 |       |     0   (0)|
    |* 43 |         INDEX UNIQUE SCAN          | MTL_SYSTEM_ITEMS_B_U1        |     1 |     9 |     0   (0)|
    |* 44 |        INDEX RANGE SCAN            | MTL_ITEM_CATEGORIES_U1       |     1 |    19 |     2   (0)|
    |* 45 |       TABLE ACCESS BY INDEX ROWID  | MTL_CATEGORIES_B             |     1 |    35 |     1   (0)|
    |* 46 |        INDEX UNIQUE SCAN           | MTL_CATEGORIES_B_U1          |     1 |       |     0   (0)|
    |  47 |    SORT UNIQUE NOSORT              |                              |     1 |    71 |     5  (20)|
    |* 48 |     FILTER                         |                              |       |       |            |
    |  49 |      NESTED LOOPS                  |                              |     1 |    71 |     4   (0)|
    |  50 |       NESTED LOOPS                 |                              |     1 |    36 |     3   (0)|
    |  51 |        NESTED LOOPS                |                              |     1 |    17 |     1   (0)|
    |  52 |         TABLE ACCESS BY INDEX ROWID| MTL_DEFAULT_CATEGORY_SETS    |     1 |     8 |     1   (0)|
    |* 53 |          INDEX UNIQUE SCAN         | MTL_DEFAULT_CATEGORY_SETS_U1 |     1 |       |     0   (0)|
    |* 54 |         INDEX UNIQUE SCAN          | MTL_SYSTEM_ITEMS_B_U1        |     1 |     9 |     0   (0)|
    |* 55 |        INDEX RANGE SCAN            | MTL_ITEM_CATEGORIES_U1       |     1 |    19 |     2   (0)|
    |* 56 |       TABLE ACCESS BY INDEX ROWID  | MTL_CATEGORIES_B             |     1 |    35 |     1   (0)|
    |* 57 |        INDEX UNIQUE SCAN           | MTL_CATEGORIES_B_U1          |     1 |       |     0   (0)|
    --------------------------------------------------------------------------------------------------------Here is the explain plan for the second query:
    | Id  | Operation                           | Name                         | Rows  | Bytes | Cost (%CPU)|
    |   0 | SELECT STATEMENT                    |                              |     5 |   240 |    10  (50)|
    |   1 |  NESTED LOOPS                       |                              |     5 |   240 |    10  (50)|
    |   2 |   VIEW                              | XXCUS_MTL_SYS_ITEM_TYPES_V   |     5 |   160 |     5 (100)|
    |   3 |    UNION-ALL                        |                              |       |       |            |
    |   4 |     HASH UNIQUE                     |                              |     1 |    71 |     1 (100)|
    |*  5 |      FILTER                         |                              |       |       |            |
    |   6 |       NESTED LOOPS                  |                              |    17 |  1207 |    77   (0)|
    |   7 |        NESTED LOOPS                 |                              |    16 |   992 |    77   (0)|
    |   8 |         NESTED LOOPS                |                              |     1 |    43 |     7   (0)|
    |   9 |          TABLE ACCESS BY INDEX ROWID| MTL_DEFAULT_CATEGORY_SETS    |     1 |     8 |     1   (0)|
    |* 10 |           INDEX UNIQUE SCAN         | MTL_DEFAULT_CATEGORY_SETS_U1 |     1 |       |     0   (0)|
    |* 11 |          TABLE ACCESS BY INDEX ROWID| MTL_CATEGORIES_B             |     1 |    35 |     6   (0)|
    |* 12 |           INDEX RANGE SCAN          | MTL_CATEGORIES_B_N1          |    44 |       |     2   (0)|
    |* 13 |         TABLE ACCESS BY INDEX ROWID | MTL_ITEM_CATEGORIES          |    49 |   931 |    70   (0)|
    |* 14 |          INDEX RANGE SCAN           | MTL_ITEM_CATEGORIES_N3       |   441 |       |     4   (0)|
    |* 15 |        INDEX UNIQUE SCAN            | MTL_SYSTEM_ITEMS_B_U1        |     1 |     9 |     0   (0)|
    |  16 |     HASH UNIQUE                     |                              |     1 |    63 |     1 (100)|
    |* 17 |      FILTER                         |                              |       |       |            |
    |  18 |       NESTED LOOPS                  |                              |  2158 |   132K|   250   (1)|
    |  19 |        NESTED LOOPS                 |                              |  2134 |   112K|   249   (0)|
    |  20 |         NESTED LOOPS                |                              |    44 |  1540 |     7   (0)|
    |  21 |          TABLE ACCESS BY INDEX ROWID| MTL_DEFAULT_CATEGORY_SETS    |     1 |     8 |     1   (0)|
    |* 22 |           INDEX UNIQUE SCAN         | MTL_DEFAULT_CATEGORY_SETS_U1 |     1 |       |     0   (0)|
    |  23 |          TABLE ACCESS BY INDEX ROWID| MTL_CATEGORIES_B             |    44 |  1188 |     6   (0)|
    |* 24 |           INDEX RANGE SCAN          | MTL_CATEGORIES_B_N1          |    44 |       |     2   (0)|
    |* 25 |         TABLE ACCESS BY INDEX ROWID | MTL_ITEM_CATEGORIES          |    49 |   931 |    70   (0)|
    |* 26 |          INDEX RANGE SCAN           | MTL_ITEM_CATEGORIES_N3       |   441 |       |     4   (0)|
    |* 27 |        INDEX UNIQUE SCAN            | MTL_SYSTEM_ITEMS_B_U1        |     1 |     9 |     0   (0)|
    |  28 |     HASH UNIQUE                     |                              |     1 |    71 |     1 (100)|
    |* 29 |      FILTER                         |                              |       |       |            |
    |  30 |       NESTED LOOPS                  |                              |    33 |  2343 |    77   (0)|
    |  31 |        NESTED LOOPS                 |                              |    33 |  2046 |    77   (0)|
    |  32 |         NESTED LOOPS                |                              |     1 |    43 |     7   (0)|
    |  33 |          TABLE ACCESS BY INDEX ROWID| MTL_DEFAULT_CATEGORY_SETS    |     1 |     8 |     1   (0)|
    |* 34 |           INDEX UNIQUE SCAN         | MTL_DEFAULT_CATEGORY_SETS_U1 |     1 |       |     0   (0)|
    |* 35 |          TABLE ACCESS BY INDEX ROWID| MTL_CATEGORIES_B             |     1 |    35 |     6   (0)|
    |* 36 |           INDEX RANGE SCAN          | MTL_CATEGORIES_B_N1          |    44 |       |     2   (0)|
    |* 37 |         TABLE ACCESS BY INDEX ROWID | MTL_ITEM_CATEGORIES          |    49 |   931 |    70   (0)|
    |* 38 |          INDEX RANGE SCAN           | MTL_ITEM_CATEGORIES_N3       |   441 |       |     4   (0)|
    |* 39 |        INDEX UNIQUE SCAN            | MTL_SYSTEM_ITEMS_B_U1        |     1 |     9 |     0   (0)|
    |  40 |     HASH UNIQUE                     |                              |     1 |    71 |     1 (100)|
    |* 41 |      FILTER                         |                              |       |       |            |
    |  42 |       NESTED LOOPS                  |                              |    17 |  1207 |    77   (0)|
    |  43 |        NESTED LOOPS                 |                              |    16 |   992 |    77   (0)|
    |  44 |         NESTED LOOPS                |                              |     1 |    43 |     7   (0)|
    |  45 |          TABLE ACCESS BY INDEX ROWID| MTL_DEFAULT_CATEGORY_SETS    |     1 |     8 |     1   (0)|
    |* 46 |           INDEX UNIQUE SCAN         | MTL_DEFAULT_CATEGORY_SETS_U1 |     1 |       |     0   (0)|
    |* 47 |          TABLE ACCESS BY INDEX ROWID| MTL_CATEGORIES_B             |     1 |    35 |     6   (0)|
    |* 48 |           INDEX RANGE SCAN          | MTL_CATEGORIES_B_N1          |    44 |       |     2   (0)|
    |* 49 |         TABLE ACCESS BY INDEX ROWID | MTL_ITEM_CATEGORIES          |    49 |   931 |    70   (0)|
    |* 50 |          INDEX RANGE SCAN           | MTL_ITEM_CATEGORIES_N3       |   441 |       |     4   (0)|
    |* 51 |        INDEX UNIQUE SCAN            | MTL_SYSTEM_ITEMS_B_U1        |     1 |     9 |     0   (0)|
    |  52 |     HASH UNIQUE                     |                              |     1 |    71 |     1 (100)|
    |* 53 |      FILTER                         |                              |       |       |            |
    |  54 |       NESTED LOOPS                  |                              |    17 |  1207 |    77   (0)|
    |  55 |        NESTED LOOPS                 |                              |    16 |   992 |    77   (0)|
    |  56 |         NESTED LOOPS                |                              |     1 |    43 |     7   (0)|
    |  57 |          TABLE ACCESS BY INDEX ROWID| MTL_DEFAULT_CATEGORY_SETS    |     1 |     8 |     1   (0)|
    |* 58 |           INDEX UNIQUE SCAN         | MTL_DEFAULT_CATEGORY_SETS_U1 |     1 |       |     0   (0)|
    |* 59 |          TABLE ACCESS BY INDEX ROWID| MTL_CATEGORIES_B             |     1 |    35 |     6   (0)|
    |* 60 |           INDEX RANGE SCAN          | MTL_CATEGORIES_B_N1          |    44 |       |     2   (0)|
    |* 61 |         TABLE ACCESS BY INDEX ROWID | MTL_ITEM_CATEGORIES          |    49 |   931 |    70   (0)|
    |* 62 |          INDEX RANGE SCAN           | MTL_ITEM_CATEGORIES_N3       |   441 |       |     4   (0)|
    |* 63 |        INDEX UNIQUE SCAN            | MTL_SYSTEM_ITEMS_B_U1        |     1 |     9 |     0   (0)|
    |  64 |   TABLE ACCESS BY INDEX ROWID       | MTL_SYSTEM_ITEMS_B           |     1 |    16 |     1   (0)|
    |* 65 |    INDEX UNIQUE SCAN                | MTL_SYSTEM_ITEMS_B_U1        |     1 |       |     0   (0)|
    ---------------------------------------------------------------------------------------------------------

  • Create table from another table including constraints

    Hi,
    Is there a way to create a table from another table including constraints.
    CREATE TABLE COPY_EMP
    as
    SELECT *
    FROM EMP
    WHERE 1 =2 ;
    This creates the table, but the constraints are not copied over.
    I was reading about DBMS_REDEFINITION - can that be used for this scenario ?
    Thanks!
    Anand

    >
    I tried that, but the constraint names are posing a problem. And unfortunately our constraints are not named in a standard, so am finding it difficult to replace them.
    Was just wondering if there were any simpler approach to this.
    >
    No - there isn't.
    You will have to use new names for the constraints. That usually means extracting the DDL and manually changing the constraint names.

  • Connecting Each row to another Table

    Hi
    This probably isnt the JDBC question but can some one tell me how to Connect each row of a column to another Table.
    I have a Table with two columns Name and UserID. I want to connect each UserID to another Table. like User01 will be connected to another table called burn table for user01. User 02 will be connected to another table called burn table for user 02. Each table for user01 and user02 has 3 columns: CDName, EULA, License Key.
    I read about primary and foreign keys but can some one give me a hint on this about how to start on it?
    And if i get this done, then how would i execute a SQL query command so that I can read the data for each user. I am using java Servlets.
    I am new sorry.
    -bhaarat

    i agree with you that making seperate table for each
    user is terrible and i would be ashamed to present
    this projec to anyone.
    how do you think i should design this database other
    than what i have suggested..
    i might have alredy explained what the database is
    doing but let me do that again..
    1. There are about 150 or more CD's from MS.
    2. Each user is able to burn a cd once only. for
    example if user has already burned xp pro he cant burn
    again.
    3. there are about 600 or more users(thats why making
    each table for each user is wrong, eventhough some one
    else will be doing it, instead of me).
    4. each cd has a license key associated with it.
    please suggest me how i should do this database so its
    not much of a hazzle and i dont have to pay some one
    100 an hour so fix the problems lol.okay first i am going to list out the table designs and then I am going to provide some explanations
    tblUser
    username VARCHAR PRIMARY KEY
    firstname VARCHAR
    lastname VARCHAR
    tblCD
    cdname VARCHAR PRIMARY KEY
    licensekey VARCHAR PRIMARY KEY
    eula VARCHAR or TEXT
    tblUserCD
    username VARCHAR PRIMARY KEY
    cdname VARCHAR PRIMARY KEY
    licensekey VARCHAR PRIMARY KEY
    so what's happening here...
    well we have a table for users.. since we need a unique key i am using username... this could be the
    name for someone uses to login to your system.
    there is a different table that is list of all the cds. the primary key for this one is both the name and license together.
    then there is a table that builds a relationship between the two.
    in this scheme each user may download or whatnot each cd zero or one times. you can't put a second
    download in because that will violate the primary key of tblUserCD
    now let's look at some sample data
    if the user table has this....
    username----firstname----lastname
    jsmith----------John----------Smith
    aadams-------Audrey--------Adams
    and the CD table has this
    cdname----license----eula
    Access-----12345----blah blah
    Word--------12356----blah blah
    Windows---99999---blah blah
    then we do the following queries when John wants to get Access and Windows and Audrey wants to get Word and Access.
    INSERT INTO tblUserCD(username,cdname,licensekey) VALUES('jsmith','Access','12345');
    INSERT INTO tblUserCD(username,cdname,licensekey) VALUES('jsmith',Windows,'99999');
    INSERT INTO tblUserCD(username,cdname,licensekey) VALUES('aadams','Word','12356');
    INSERT INTO tblUserCD(username,cdname,licensekey) VALUES('aadams','Access','12345');
    now if you want to get the list of program for any user (example John Smith) you just do this....
    SELECT cdname FROM tblUserCD WHERE username='jsmith'
    which gives you this
    cdname
    Access
    Windows
    there are several pluses to this design
    1) as I alluded to earlier this design prevents you putting in the same cd and license key more than once for each user
    2) You now can get a nice list of all the CD's easily.
    SELECT cdname,licensekety FROM tblCD;
    3) if you need to make any changes, like a persons username or more likely the cd stuff then it is easier to do so.. for example in your old design if you wanted to change Access to Access XP you would have to change EVERY table. in the new model you can do this in two queries.
    UPDATE tblCD SET cdname='Access XP' WHERE cdname='Access' AND licensekey='12345';
    UPDATE tblUserCD SET cdname='Access XP' WHERE cdname='Access' AND licensekey='12345';
    (actually if you set up the keys properly and to cascade changes then you would just need the one query)
    there is actually a theory for this sort of timesaving and error prevention work called normal form data.
    for your further "enjoyment" may I suggest reading this http://databasejournal.com/sqletc/article.php/1443021
    anyway hope this helps you out....
    does this make sense to you?

  • Sql join on two tables where column like another column

    hi all,
    been trying to get the results from a join between two tables where one column is like another one.
    table1 (nameA) examples: black2, green1
    table2 (nameB) example: black2.location.uk.com, green1.location.uk.com
    so for example I want to match all those in table1 with black2 to the column in table2 that begins with black2 and so on if you see what im trying to get at!
    my sql so far:
    select * from  schema.table1 a
    join schema.table2 b
    on a.nameA like concat('%', b.nameB, '%'); but it errors:
    ORA-00909: invalid number of arguments
    00909. 00000 - "invalid number of arguments"
    Any help or advice would be greatly appreciated, thankyou!

    Either of these should do it...
    select * from  schema.table1 a
    join schema.table2 b on a.nameA like '%'||b.nameB||'%';or
    select * from  schema.table1 a
    join schema.table2 b on instr(b.nameB,a.nameA) > 0

  • Comparing data size in one table to column widths in another table

    I have data in a table that has a large number of columns, many of them nvarchar of varying widths.  Im trying to take that data and insert it into another table but Im getting the warning message about string or binary data being truncated.  I
    suspect there is a field somewhere that is not large enough for the data.  However, I run across this often enough I would like to come up with a better solution than just eyeballing the data.
    I found this example
    http://www.sqlservercentral.com/Forums/Topic1115499-338-2.aspx
    (credit goes to poster in the linked thread above)
    Select columns
    into #T
    from MyDataSource;
    select *
    from tempdb.sys.columns as TempCols
    full outer join MyDb.sys.columns as RealCols
    on TempCols.name = RealCols.name
    and TempCols.object_id = Object_ID(N'tempdb..#T')
    and RealCols.object_id = Object_ID(N'MyDb.dbo.MyTable)
    where TempCols.name is null -- no match for real target name
    or RealCols.name is null -- no match for temp target name
    or RealCols.system_type_id != TempCols.system_type_id
    or RealCols.max_length < TempCols.max_length ;
    Why a full outer join ?  Why not just a left join, since I really only want to see the matches on my source table?
    When Im running this against the table im interested in, it doesnt seem to find matches between my target table and my temp table 

    As an outer join of any type, that query won't work well.  For example, suppose you do a left join.  So the query begins by getting every row from tempdb.sys.columns (whether it is in #T or not).  Consider a row for a column which is not in
    #T, you look for matches for rows in Mydb.sys.columns ON
    on TempCols.name = RealCols.name
    and TempCols.object_id = Object_ID(N'tempdb..#T')
    and RealCols.object_id = Object_ID(N'MyDb.dbo.MyTable)
    Notice that since the row you are considering is NOT a column in #T, the second part of the ON condition is not true, so the whole ON condition will not be true.  But this is a left join.  So the join keeps this row with NULL's in the columns coming
    from the RealCols table.  Then you do the where condition, but the connections are all OR and one of the conditions is RealCols.name is null (which it is because there was no match), your output will include a row for this column in tempdb even though
    this column is not in #T.  So if you use a left join, the output of this query will include a row for every column in every table in tempdb not named #T.
    Similarly, if you do a right join, you get a column for every row of every table in MyDb which is not a column in dbo.MyTable.
    And a full join (which you are doing above) will return a row for every column in every table in both tempdb and MyDb.
    This query will sort of work if you make it an inner join.  But even then it won't find every possible cause of string or binary truncation.  For example, you are doing RealCols.max_length < TempCols.max_length.  But in sys.columns, if
    you have a varchar(max) column, max_length is stored as -1.  So if a column in RealCols is varchar(50) and the same column in TempCols is varchar(max), that column will not show up as an exception, but of course, you can get truncation if you attempt
    to store a varchar(max) in a varchar(50).
    I would run a query more like
    Create Table FooX(a int, b varchar(20), c int, d varchar(20), e int, f varchar(20), g decimal(4,0));
    Select a, b, 1 as x, 'abc' as y, Cast('' as varchar(max)) As f, Cast(25.1 as decimal(3,1)) as g
    into #T
    from FooX;
    Select 'In Real, not in or different in Temp' As Description, name, column_id, system_type_id, max_length, precision, scale, collation_name From sys.columns Where object_id = Object_ID(N'FooX')
    Except Select 'In Real, not in or different in Temp' As Description, name, column_id, system_type_id, max_length, precision, scale, collation_name From tempdb.sys.columns Where object_id = Object_ID(N'tempdb..#T')
    Union All
    Select 'In Temp, not in or different in Real' As Description, name, column_id, system_type_id, max_length, precision, scale, collation_name From tempdb.sys.columns Where object_id = Object_ID(N'tempdb..#T')
    Except Select 'In Temp, not in or different in Real' As Description, name, column_id, system_type_id, max_length, precision, scale, collation_name From tempdb.sys.columns Where object_id = Object_ID(N'FooX')
    Order By name, Description;
    go
    Drop Table #T
    go
    Drop Table FooX
    The output of that is
    In Real, not in or different in Temp c 3 56 4 10 0 NULL
    In Real, not in or different in Temp d 4 167 20 0 0 SQL_Latin1_General_CP1_CI_AS
    In Real, not in or different in Temp e 5 56 4 10 0 NULL
    In Real, not in or different in Temp f 6 167 20 0 0 SQL_Latin1_General_CP1_CI_AS
    In Temp, not in or different in Real f 5 167 -1 0 0 SQL_Latin1_General_CP1_CI_AS
    In Real, not in or different in Temp g 7 106 5 4 0 NULL
    In Temp, not in or different in Real g 6 106 5 3 1 NULL
    In Temp, not in or different in Real x 3 56 4 10 0 NULL
    In Temp, not in or different in Real y 4 167 3 0 0 SQL_Latin1_General_CP1_CI_AS
    From which you can quickly see that the differences are c, d, and e are in the real table and not the temp table, f is in both tables but the max_length is different, g is in both table, but the precision and scale are different, and x and y are in the temp
    table, but not the real table.
    Tom

  • Query to Identify Data in One Table Not In Another Table

    I need to create a query that will return the records in one table that are not in another table.  Here is the structure of my data tables:
    tbl_Practice – contains information about management practices.  The primary key field is “ID” which is an autonumber field.
    tbl_Controls – contains information about internal controls associated with the management practices.  The primary key is “ID” which is an autonumber.
    tbl_PracticeJoin – this is a table that contains the mapping of controls to practices.  Some practices can have multiple controls assigned to them and some controls can be mapped to multiple practices. 
    This table’s primary key is “ID” which is an autonumber field.  The only other data included in this table are the primary keys of the practice and control.  Those field names are “PracticeIDFK” and “ControlIDFK”.
    In this application, the user will normally enter practices and controls at the same time; however, there may be instances where a control is entered and it is not known at that time what practice(s) it should
    be mapped to.  I want to be able to run a query that will show me any controls that are in the tbl_Controls which are not in tbl_PracticeJoin.  I would like to be able to do the same with the practice table. 
    Thanks.

    The easiest way to do this is through the 'Find Unmatched Query Wizard'.
    On the Create tab of the ribbon, click Query Wizard.
    Select 'Find Unmatched Query Wizard'.
    Click OK.
    Select tbl_Controls, then click Next >.
    Select tbl_PracticeJoin, then click Next >.
    Select ID in tbl_Controls and ControlIDFK in tbl_PracticeJoin (if the wizard hasn't already done so automatically), then click Next >.
    Add the fields from tbl_Controls that you want to see to the list on the right; click >> if you want to add them all at once. Then click Next >.
    Access proposes a name for the query; you can edit the name if you wish.
    Click Finish.
    You can do the same for tbl_Practice and tbl_PracticeJoin, with PracticeIDFK instead of ControlIDFK.
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

  • Copy selected values from a table control into another table control

    hi there,
    as seen in the subject i need to copy selected values from a table control into another table control in the same screen. as i dont know much about table controls i made 2 table controls with the wizard and started to change the code... right now im totally messed up. nothing works anymore and i don't know where to start over.
    i looked up the forums and google, but there is nothing to help me with this problem (or i suck in searching the internet for solutions)
    i have 2 buttons. one to push the selected data from the top table control into the bottom tc and the other button is to push selected data from the bottom tc into the top tc. does somebody has a sample code to do this?

    you're funny
    i still don't get it... can't believe, there is no tutorial or sample code around how to copy multiple selected rows from a tc.
    here's my code, maybe you can tell me exactly were i have to change it:
    tc1 = upper table control
    tc2 = lower table control
    SCREEN 0100:
    PROCESS BEFORE OUTPUT.
      MODULE status_0100.
      MODULE get_nfo. --> gets data from the dictionary table
      MODULE tc1_change_tc_attr.
      LOOP AT   it_roles_tc1
           INTO wa_roles_tc1
           WITH CONTROL tc1
           CURSOR tc1-current_line.
      ENDLOOP.
      MODULE tc2_change_tc_attr.
      LOOP AT   it_roles_tc2
           INTO wa_roles_tc2l
           WITH CONTROL tc2
           CURSOR tc2-current_line.
      ENDLOOP.
    PROCESS AFTER INPUT.
      LOOP AT it_roles_tc1.
        CHAIN.
          FIELD wa_roles_tc1-agr_name.
          FIELD wa_roles_tc1-text.
        ENDCHAIN.
        FIELD wa_roles_tc1-mark
          MODULE tc1_mark ON REQUEST.
      ENDLOOP.
      LOOP AT it_roles_tc2.
        CHAIN.
          FIELD wa_roles_tc2-agr_name.
          FIELD wa_roles_tc2-text.
        ENDCHAIN.
        FIELD wa_roles_tc2-mark
          MODULE tc2_mark ON REQUEST.
      ENDLOOP.
      MODULE ok_code.
      MODULE user_command_0100.
    INCLUDE PAI:
    MODULE tc1_mark INPUT.
      IF tc1-line_sel_mode = 2
      AND wa_roles_tc1-mark = 'X'.
        LOOP AT it_roles_tc1 INTO g_tc1_wa2
          WHERE mark = 'X'.    -
    > big problem here is, that no entry has an 'X' there
          g_tc1_wa2-mark = ''.
          MODIFY it_roles_tc1
            FROM g_tc1_wa2
            TRANSPORTING mark.
        ENDLOOP.
      ENDIF.
      MODIFY it_roles_tc1
        FROM wa_roles_tc1
        INDEX tc1-current_line
        TRANSPORTING mark.
    ENDMODULE.                    "TC1_MARK INPUT
    MODULE tc2_mark INPUT.
      IF tc2-line_sel_mode = 2
      AND wa_roles_tc2-mark = 'X'.
        LOOP AT it_roles_tc2 INTO g_tc2_wa2
          WHERE mark = 'X'.             -
    > same here, it doesn't gets any data
          g_tc2_wa2-mark = ''.
          MODIFY it_roles_tc2
            FROM g_tc2_wa2
            TRANSPORTING mark.
        ENDLOOP.
      ENDIF.
      MODIFY it_roles_tc2
        FROM wa_roles_tc2
        INDEX tc2-current_line
        TRANSPORTING mark.
    ENDMODULE. 
    thx for anybody who can help with this!

  • Move data from one table to another table

    Hi all,
    I  had a custom table called sales_data in that table there are  columns like JAn,FEB,upto DEC including other columns so in each month there is some data total data is  23000 count but each month has has specific data like JAn-2500,FEB-2000 like that it has total 23000 records
    My Requirement  is i have to move data from one table to another table that too if i will pass jan only jan data should move like that feb,march,.....
    in my table there is no month column i had get it from another table called gl_periods and by using cursor and case function i have written the code
    well while when i am inserting data am passing year,month as parameters but 23000 data is moving it should get like that.
    Please suggest me.its urgent
    Thank You

    Hi hamid,
                   Please go through the below procedure.
    CREATE OR REPLACE PROCEDURE APPS.copy_sales_to_forecast(p_fiscal_year varchar2,p_month number)
    IS
    CURSOR C1 IS select period_year,period_num,start_date,end_date from apps.gl_periods
                 where period_set_name='Accounting'
                 and   period_year=p_fiscal_year
                 and   period_num<=p_month;
    type type1 is table of xxc_forecast_data%rowtype;
    t1 type1;
    BEGIN
    FOR CREC IN C1 LOOP
    BEGIN
    DELETE FROM xxc_forecast2
    where fiscal_year = crec.period_year
      and attribute1='Copied From Sales to Forecast Table of Month '||crec.period_num;
    END;
    SELECT
      product_category           ,
      product_sub_category       ,
      product_line               ,
      product_style              ,
      item_number                ,
      item_description           ,
      customer_name              ,
      customer_number            ,
      sales_channel              ,
      null      ,
      CASE
        WHEN crec.period_num=1 THEN sales_amount_month1
        ELSE 0
      END Transaction_quantity_period1,
      CASE
        WHEN crec.period_num=1 THEN sales_cost_month1
        ELSE 0
      END item_cogs_period1,
      CASE
        WHEN crec.period_num=1 THEN sales_mtl_cost_month1
        ELSE 0
      END item_material_cogs_period1 ,
      CASE
        WHEN crec.period_num=1 THEN sales_mtl_ovhd_cost_month1
        ELSE 0
      END item_mtl_ovhd_cogs_period1,
      CASE
        WHEN crec.period_num=1 THEN sales_res_cost_month1
        ELSE 0
      END item_resource_cogs_period1,
      CASE
        WHEN crec.period_num=1 THEN sales_op_cost_month1
        ELSE 0
      END item_op_cogs_period1,
      CASE
        WHEN crec.period_num=1 THEN sales_ovhd_month1
        ELSE 0
      END item_ovhd_cogs_period1,
      CASE
        WHEN crec.period_num=1 THEN sales_units_month1
        ELSE 0
      END extended_amount_us_period1,
      CASE
        WHEN crec.period_num=2 THEN sales_amount_month2
        ELSE 0
      END Transaction_quantity_period2,
      CASE
        WHEN crec.period_num=2 THEN sales_mtl_cost_month2
        ELSE 0
      END item_material_cogs_period2,
      CASE
        WHEN crec.period_num=2 THEN sales_mtl_ovhd_cost_month2
        ELSE 0
      END item_mtl_ovhd_cogs_period2,
      CASE
        WHEN crec.period_num=2 THEN sales_res_cost_month2
        ELSE 0
      END item_resource_cogs_period2,
      CASE
        WHEN crec.period_num=2 THEN sales_op_cost_month2
        ELSE 0
      END item_op_cogs_period2,
      CASE
        WHEN crec.period_num=2 THEN sales_ovhd_month2
        ELSE 0
      END item_ovhd_cogs_period2,
       CASE
        WHEN crec.period_num=2 THEN sales_units_month2
        ELSE 0
      END extended_amount_us_period2,
      CASE
        WHEN crec.period_num=3 THEN sales_amount_month3
        ELSE 0
      END Transaction_quantity_period3,
      CASE
        WHEN crec.period_num=3 THEN sales_mtl_cost_month3
        ELSE 0
      END item_material_cogs_period3,
      CASE
        WHEN crec.period_num=3 THEN sales_mtl_ovhd_cost_month3
        ELSE 0
      END item_mtl_ovhd_cogs_period3,
      CASE
        WHEN crec.period_num=3 THEN sales_res_cost_month3
        ELSE 0
      END item_resource_cogs_period3,
      CASE
        WHEN crec.period_num=3 THEN sales_op_cost_month3
        ELSE 0
      END item_op_cogs_period3,
      CASE
        WHEN crec.period_num=3 THEN sales_ovhd_month3
        ELSE 0
      END item_ovhd_cogs_period3,
      CASE
        WHEN crec.period_num=3 THEN sales_units_month3
        ELSE 0
      END extended_amount_us_period3,
      CASE
        WHEN crec.period_num=4 THEN sales_amount_month4
        ELSE 0
      END Transaction_quantity_period4,
      CASE
        WHEN crec.period_num=4 THEN sales_mtl_cost_month4
        ELSE 0
      END item_material_cogs_period4,
      CASE
        WHEN crec.period_num=4 THEN sales_mtl_ovhd_cost_month4
        ELSE 0
      END item_mtl_ovhd_cogs_period4,
      CASE
        WHEN crec.period_num=4 THEN sales_res_cost_month4
        ELSE 0
      END item_resource_cogs_period4,
      CASE
        WHEN crec.period_num=4 THEN sales_op_cost_month4
        ELSE 0
      END item_op_cogs_period4,
      CASE
        WHEN crec.period_num=4 THEN sales_ovhd_month4
        ELSE 0
      END item_ovhd_cogs_period4,
      CASE
        WHEN crec.period_num=4 THEN sales_units_month4
        ELSE 0
      END extended_amount_us_period4,
      CASE
        WHEN crec.period_num=5 THEN sales_amount_month5
        ELSE 0
      END Transaction_quantity_period5,
      CASE
        WHEN crec.period_num=5 THEN sales_mtl_cost_month5
        ELSE 0
      END item_material_cogs_period5,
      CASE
        WHEN crec.period_num=5 THEN sales_mtl_ovhd_cost_month5
        ELSE 0
      END item_mtl_ovhd_cogs_period5,
      CASE
        WHEN crec.period_num=5 THEN sales_res_cost_month5
        ELSE 0
      END item_resource_cogs_period5,
      CASE
        WHEN crec.period_num=5 THEN sales_op_cost_month5
        ELSE 0
      END item_op_cogs_period5,
      CASE
        WHEN crec.period_num=5 THEN sales_ovhd_month5
        ELSE 0
      END item_ovhd_cogs_period5,
      CASE
        WHEN crec.period_num=5 THEN sales_units_month5
        ELSE 0
      END extended_amount_us_period5,
      CASE
        WHEN crec.period_num=6 THEN sales_amount_month6
        ELSE 0
      END Transaction_quantity_period6,
      CASE
        WHEN crec.period_num=6 THEN sales_mtl_cost_month6
        ELSE 0
      END item_material_cogs_period6,
      CASE
        WHEN crec.period_num=6 THEN sales_mtl_ovhd_cost_month6
        ELSE 0
      END item_mtl_ovhd_cogs_period6,
      CASE
        WHEN crec.period_num=6 THEN sales_res_cost_month6
        ELSE 0
      END item_resource_cogs_period6,
      CASE
        WHEN crec.period_num=6 THEN sales_op_cost_month6
        ELSE 0
      END item_op_cogs_period6,
      CASE
        WHEN crec.period_num=6 THEN sales_ovhd_month6
        ELSE 0
      END item_ovhd_cogs_period6,
       CASE
        WHEN crec.period_num=6 THEN sales_units_month6
        ELSE 0
      END extended_amount_us_period6,
      CASE
        WHEN crec.period_num=7 THEN sales_amount_month7
        ELSE 0
      END Transaction_quantity_period7,
      CASE
        WHEN crec.period_num=7 THEN sales_mtl_cost_month7
        ELSE 0
      END item_material_cogs_period7,
      CASE
        WHEN crec.period_num=7 THEN sales_mtl_ovhd_cost_month7
        ELSE 0
      END item_mtl_ovhd_cogs_period7,
      CASE
        WHEN crec.period_num=7 THEN sales_res_cost_month7
        ELSE 0
      END item_resource_cogs_period7,
      CASE
        WHEN crec.period_num=7 THEN sales_op_cost_month7
        ELSE 0
      END item_op_cogs_period7,
      CASE
        WHEN crec.period_num=7 THEN sales_ovhd_month7
        ELSE 0
      END item_ovhd_cogs_period7,
      CASE
        WHEN crec.period_num=7 THEN sales_units_month7
        ELSE 0
      END extended_amount_us_period7,
      CASE
        WHEN crec.period_num=8 THEN sales_amount_month8
        ELSE 0
      END Transaction_quantity_period8,
      CASE
        WHEN crec.period_num=8 THEN sales_mtl_cost_month8
        ELSE 0
      END item_material_cogs_period8,
      CASE
        WHEN crec.period_num=8 THEN sales_mtl_ovhd_cost_month8
        ELSE 0
      END item_mtl_ovhd_cogs_period8,
      CASE
        WHEN crec.period_num=8 THEN sales_res_cost_month8
        ELSE 0
      END item_resource_cogs_period7,
      CASE
        WHEN crec.period_num=8 THEN sales_op_cost_month8
        ELSE 0
      END item_op_cogs_period8,
      CASE
        WHEN crec.period_num=8 THEN sales_ovhd_month8
        ELSE 0
      END item_ovhd_cogs_period8,
      CASE
        WHEN crec.period_num=8 THEN sales_units_month8
        ELSE 0
      END extended_amount_us_period8,
      CASE
        WHEN crec.period_num=9 THEN sales_amount_month9
        ELSE 0
      END Transaction_quantity_period9,
      CASE
        WHEN crec.period_num=9 THEN sales_mtl_cost_month9
        ELSE 0
      END item_material_cogs_period9,
      CASE
        WHEN crec.period_num=9 THEN sales_mtl_ovhd_cost_month9
        ELSE 0
      END item_mtl_ovhd_cogs_period9,
      CASE
        WHEN crec.period_num=9 THEN sales_res_cost_month9
        ELSE 0
      END item_resource_cogs_period7,
      CASE
        WHEN crec.period_num=9 THEN sales_op_cost_month9
        ELSE 0
      END item_op_cogs_period9,
      CASE
        WHEN crec.period_num=9 THEN sales_ovhd_month9
        ELSE 0
      END item_ovhd_cogs_period9,
       CASE
        WHEN crec.period_num=9 THEN sales_units_month9
        ELSE 0
      END extended_amount_us_period9,
      CASE
        WHEN crec.period_num=10 THEN sales_amount_month10
        ELSE 0
      END Transaction_quantity_period10,
      CASE
        WHEN crec.period_num=10 THEN sales_mtl_cost_month10
        ELSE 0
      END item_material_cogs_period10,
      CASE
        WHEN crec.period_num=10 THEN sales_mtl_ovhd_cost_month10
        ELSE 0
      END item_mtl_ovhd_cogs_period10,
      CASE
        WHEN crec.period_num=10 THEN sales_res_cost_month10
        ELSE 0
      END item_resource_cogs_period10,
      CASE
        WHEN crec.period_num=10 THEN sales_op_cost_month10
        ELSE 0
      END item_op_cogs_period10,
      CASE
        WHEN crec.period_num=10 THEN sales_ovhd_month10
        ELSE 0
      END item_ovhd_cogs_period10,
      CASE
        WHEN crec.period_num=10 THEN sales_units_month10
        ELSE 0
      END extended_amount_us_period10,
      CASE
        WHEN crec.period_num=11 THEN sales_amount_month11
        ELSE 0
      END Transaction_quantity_period11,
      CASE
        WHEN crec.period_num=11 THEN sales_mtl_cost_month11
        ELSE 0
      END item_material_cogs_period11,
      CASE
        WHEN crec.period_num=11 THEN sales_mtl_ovhd_cost_month11
        ELSE 0
      END item_mtl_ovhd_cogs_period11,
      CASE
        WHEN crec.period_num=11 THEN sales_res_cost_month11
        ELSE 0
      END item_resource_cogs_period11,
      CASE
        WHEN crec.period_num=11 THEN sales_op_cost_month11
        ELSE 0
      END item_op_cogs_period11,
      CASE
        WHEN crec.period_num=11 THEN sales_ovhd_month11
        ELSE 0
      END item_ovhd_cogs_period11,
      CASE
        WHEN crec.period_num=11 THEN sales_units_month11
        ELSE 0
      END extended_amount_us_period11,
      CASE
        WHEN crec.period_num=12 THEN sales_amount_month12
        ELSE 0
      END Transaction_quantity_period12,
      CASE
        WHEN crec.period_num=12 THEN sales_mtl_cost_month12
        ELSE 0
      END item_material_cogs_period12,
      CASE
        WHEN crec.period_num=12 THEN sales_mtl_ovhd_cost_month12
        ELSE 0
      END item_mtl_ovhd_cogs_period12,
      CASE
        WHEN crec.period_num=12 THEN sales_res_cost_month12
        ELSE 0
      END item_resource_cogs_period12,
      CASE
        WHEN crec.period_num=12 THEN sales_op_cost_month12
        ELSE 0
      END item_op_cogs_period12,
      CASE
        WHEN crec.period_num=12 THEN sales_ovhd_month12
        ELSE 0
      END item_ovhd_cogs_period12,
        CASE
        WHEN crec.period_num=12 THEN sales_units_month12
        ELSE 0
      END extended_amount_us_period12,
      CASE
        WHEN crec.period_num=2 THEN sales_cost_month2
        ELSE 0
      END item_cogs_period2,
       CASE
        WHEN crec.period_num=3 THEN sales_cost_month3
        ELSE 0
      END item_cogs_period3,
       CASE
        WHEN crec.period_num=4 THEN sales_cost_month4
        ELSE 0
      END item_cogs_period4,
       CASE
        WHEN crec.period_num=5 THEN sales_cost_month5
        ELSE 0
      END item_cogs_period5,
      CASE
        WHEN crec.period_num=6 THEN sales_cost_month6
        ELSE 0
      END item_cogs_period6,
      CASE
        WHEN crec.period_num=7 THEN sales_cost_month7
        ELSE 0
      END item_cogs_period7,
       CASE
        WHEN crec.period_num=8 THEN sales_cost_month8
        ELSE 0
      END item_cogs_period8,
      CASE
        WHEN crec.period_num=9 THEN sales_cost_month9
        ELSE 0
      END item_cogs_period9,
       CASE
        WHEN crec.period_num=10 THEN sales_cost_month10
        ELSE 0
      END item_cogs_period10,
       CASE
        WHEN crec.period_num=11 THEN sales_cost_month11
        ELSE 0
      END item_cogs_period11,
      CASE
        WHEN crec.period_num=12 THEN sales_cost_month12
        ELSE 0
      END item_cogs_period12,
      a.fiscal_year   ,
      a.budget_entity  ,
      a.organization_code,
      a.customer_id  ,
      a.inventory_item_id ,
      NULL,
      NULL,
      a.created_by ,
      a.last_updated_by ,
      a.creation_date ,
      a.last_update_date ,
      'Copied From Sales to Forecast Table of Month '||crec.period_num,
      a.attribute2,
      a.attribute3 ,
      a.attribute4 ,
      a.attribute5 ,
      a.attribute6 ,
      a.attribute7 ,
      a.attribute8 ,
      a.attribute9 ,
      a.attribute10,
      a.attribute11,
      a.attribute12,
      a.attribute13,
      a.attribute14,
      a.attribute15
      bulk collect into t1
      FROM  xxc_sales_data a 
      where  a.fiscal_year          = crec.period_year
    having CASE
                 WHEN crec.period_num=1  THEN sum(sales_amount_month1)
                 WHEN crec.period_num=2  THEN sum(sales_amount_month2)
                 WHEN crec.period_num=3  THEN sum(sales_amount_month3)
                 WHEN crec.period_num=4  THEN sum(sales_amount_month4)
                 WHEN crec.period_num=5  THEN sum(sales_amount_month5)
                 WHEN crec.period_num=6  THEN sum(sales_amount_month6)
                 WHEN crec.period_num=7  THEN sum(sales_amount_month7)
                 WHEN crec.period_num=8  THEN sum(sales_amount_month8)
                 WHEN crec.period_num=9  THEN sum(sales_amount_month9)
                 WHEN crec.period_num=10 THEN sum(sales_amount_month10)
                 WHEN crec.period_num=11 THEN sum(sales_amount_month11)
                 WHEN crec.period_num=12 THEN sum(sales_amount_month12)
                END !=0;
      FORALL i IN t1.first .. t1.last
      INSERT INTO xxc_forecast2 VALUES t1(i);
    --commit;
    END LOOP;
    END;
    Thank You

  • Can we implement the custom sql query in CR for joining the two tables

    Hi All,
    Is there anyway to implement the custom sql query in CR for joining the two tables?
    My requirement here is I need to write sql logics for joining the two tables...
    Thanks,
    Gana

    In the Database Expert, expand the Create New Connection folder and browse the subfolders to locate your data source.
    Log on to your data source if necessary.
    Under your data source, double-click the Add Command node.
    In the Add Command to Report dialog box, enter an appropriate query/command for the data source you have opened.
    For example:
    SELECT
        Customer.`Customer ID`,
        Customer.`Customer Name`,
        Customer.`Last Year's Sales`,
        Customer.`Region`,
        Customer.`Country`,
        Orders.`Order Amount`,
        Orders.`Customer ID`,
        Orders.`Order Date`
    FROM
        Customer Customer INNER JOIN Orders Orders ON
            Customer.`Customer ID` = Orders.`Customer ID`
    WHERE
        (Customer.`Country` = 'USA' OR
        Customer.`Country` = 'Canada') AND
        Customer.`Last Year's Sales` < 10000.
    ORDER BY
        Customer.`Country` ASC,
        Customer.`Region` ASC
    Note: The use of double or single quotes (and other SQL syntax) is determined by the database driver used by your report. You must, however, manually add the quotes and other elements of the syntax as you create the command.
    Optionally, you can create a parameter for your command by clicking Create and entering information in the Command Parameter dialog box.
    For more information about creating parameters, see To create a parameter for a command object.
    Click OK.
    You are returned to the Report Designer. In the Field Explorer, under Database Fields, a Command table appears listing the database fields you specified.
    Note:
    To construct the virtual table from your Command, the command must be executed once. If the command has parameters, you will be prompted to enter values for each one.
    By default, your command is called Command. You can change its alias by selecting it and pressing F2.

  • Best approach to join multiple statistics tables into one

    I have read different approaches to join multiple statistics tables into one, they all have a column "productobjectid".
    I want to get all data for each product and put it to excel and output a jpg statistic with cfchart.
    How would you do this, the sql part?
    Thanks.

    A couple suggestions:
    1) when joining tables, its best to list both table/fields that you are joining in the FROM clause:
    FROM shopproductbehaviour_views INNER JOIN shopproductbehaviour_sails ON shopproductbehaviour_views.productobjectid = shopproductbehaviour_sails.productobjectid
    2) You add tables to a SQL join by placing another join statement after the SQL above:
    SELECT *
    FROM TableA INNER JOIN TableB on TableA.myField = TableB.myField
    INNER JOIN TableC on TableA.anotherField = TableC.anotherField
    3) If you have columns in the tables that are named the same, you can use column aliases to change the way they appear in your record set:
    SELECT TableA.datetimecreated 'tablea_create_date', TableB.datetimecreated 'tableb_create_date'
    4) Certainly not a requirement, but you might want to look into using <cfqueryparam> in your where clause:
    WHERE shopproductbehaviour_sails.productobjectid = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#all.productobjectid#">
     You might want to consider checking out one of the many tutorials on SQL available online.  Many of the questions you posed in your post are covered in pretty much every basic SQL tutorial.  Alternately, a good SQL book is worth its weight in gold for a beginning web applications developer.

Maybe you are looking for

  • Use navigateToURL  in a loop

    I'm trying to do a loop, and call a javascript function in flex for every loop. The loop only seems to call the javascript once the loop is done... and it only calls it for the last iteration of the loop. To reproduce the issue do the following: 1. C

  • I keep losing my IP address on my university's network

    Hey everyone, I have a macbook running OS X 10.6.4 2.14Ghz intel core 2 duo and all that jazz. My wifi works fine but when I plug in my ethernet cable I continually lose my IP address and have to go through network assistant and basically restart the

  • 10.9.4 Permissions disorder?

    What do I do about this? Configuration: Mac Mini 2.6 GHz I7, 16GB ram, 1TB (original) drive. OSX 10.9.4. All software is current according to the App Store. Several external USB drives accessed through a hub. A couple of weeks ago I started having tr

  • How to append the data list bod (JList)

    how to append the data list box (JList) Message was edited by: raju_2reddy

  • Launch with Chrome as Default

    When I launch iCloud on my Windows laptop, It uses Internet Explorer.  I want it to launch via Google Chrome.  How do I make the appropriate changes and where?