Auto cross join

Hello.

Why Cross join on a table without specifying alias does not work properly ?


with
    t1 as (
      select 1 as q1, 2 as q2 from dual union 
      select 3, 4 from dual union 
      select 5, 6 from dual
  )
select *
  from t1
    cross join t1
order by 1
        Q1         Q2         Q1         Q2
---------- ---------- ---------- ----------
         1          2          1          2 
         1          2          1          2 
         1          2          1          2 
         3          4          3          4 
         3          4          3          4 
         3          4          3          4 
         5          6          5          6 
         5          6          5          6 
         5          6          5          6 

 9 rows selected 

11.2.0.3.0 - 64 bit

2837285 wrote:

Ok.

Why 10 gr 2 we have error ORA-00918 (same self-join) and 11 g works, but the wrong result?

Why don't you ask Oracle via a support request, it's a bug.

You can't say he is working on 11g "but which gives bad result."  Clearly if it is to give a wrong result then it doesn't work.

What happens on 11g is the fact that it runs without the exception of ambiguous column.  There are a few known bugs in the way SQL ANSI has implemented compared to the regular SQL Oracle syntax.  Oracle worked to correct.

I don't have 12 c to test, but it may have already been corrected in this version.

Tags: Database

Similar Questions

  • [8i] need help with full outer join combined with a cross join...

    I can't understand how to combine a full outer join with a different type of join... is it possible?

    Here are some create table and insert for examples of database:
    CREATE TABLE     my_tab1
    (     record_id     NUMBER     NOT NULL     
    ,     workstation     VARCHAR2(4)
    ,     my_value     NUMBER
         CONSTRAINT my_tab1_pk PRIMARY KEY (record_id)
    );
    
    INSERT INTO     my_tab1
    VALUES(1,'ABCD',10);
    INSERT INTO     my_tab1
    VALUES(2,'ABCD',15);
    INSERT INTO     my_tab1
    VALUES(3,'ABCD',5);
    INSERT INTO     my_tab1
    VALUES(4,'A123',5);
    INSERT INTO     my_tab1
    VALUES(5,'A123',10);
    INSERT INTO     my_tab1
    VALUES(6,'A123',20);
    INSERT INTO     my_tab1
    VALUES(7,'????',5);
    
    
    CREATE TABLE     my_tab2
    (     workstation     VARCHAR2(4)
    ,     wkstn_name     VARCHAR2(20)
         CONSTRAINT my_tab2_pk PRIMARY KEY (workstation)
    );
    
    INSERT INTO     my_tab2
    VALUES('ABCD','WKSTN 1');
    INSERT INTO     my_tab2
    VALUES('A123','WKSTN 2');
    INSERT INTO     my_tab2
    VALUES('B456','WKSTN 3');
    
    CREATE TABLE     my_tab3
    (     my_nbr1     NUMBER
    ,     my_nbr2     NUMBER
    );
    
    INSERT INTO     my_tab3
    VALUES(1,2);
    INSERT INTO     my_tab3
    VALUES(2,3);
    INSERT INTO     my_tab3
    VALUES(3,4);
    And, the results that I want to get:
    workstation     sum(my_value)     wkstn_name     my_nbr1     my_nbr2
    ---------------------------------------------------------------
    ABCD          30          WKSTN 1          1     2
    ABCD          30          WKSTN 1          2     3
    ABCD          30          WKSTN 1          3     4
    A123          35          WKSTN 2          1     2
    A123          35          WKSTN 2          2     3
    A123          35          WKSTN 2          3     4
    B456          0          WKSTN 3          1     2
    B456          0          WKSTN 3          2     3
    B456          0          WKSTN 3          3     4
    ????          5          NULL          1     2
    ????          5          NULL          2     3
    ????          5          NULL          3     4
    I tried a number of different things, google my problem and no luck yet...
    SELECT     t1.workstation
    ,     SUM(t1.my_value)
    ,     t2.wkstn_name
    ,     t3.my_nbr1
    ,     t3.my_nbr2
    FROM     my_tab1 t1
    ,     my_tab2 t2
    ,     my_tab3 t3
    ...
    So, what I want, it's a full outer join of t1 and t2 on workstation and a cross join of one with the t3. I wonder if I can't find examples of it online because it is not possible...

    Note: I'm stuck dealing with Oracle 8i

    Thank you!!

    Hello

    The query I posted yesterday is a little more complex that it should be.
    My_tab2.workstation is unique, there is no reason to make a separate subquery as mt1. We can join my_tab1 to my_tab2 and get the SUM in a subquery.

    SELECT       foj.workstation
    ,       foj.sum_my_value
    ,       foj.wkstn_name
    ,       mt3.my_nbr1
    ,       mt3.my_nbr2
    FROM       (     -- Begin in-line view foj for full outer join
              SELECT        mt1.workstation
              ,        SUM (mt1.my_value)     AS sum_my_value
              ,        mt2.wkstn_name
              FROM        my_tab1   mt1
              ,        my_tab2   mt2
              WHERE        mt1.workstation     = mt2.workstation (+)
              GROUP BY   mt1.workstation
              ,        mt2.wkstn_name
                            --
                    UNION ALL
                            --
              SELECT      workstation
              ,      0      AS sum_my_value
              ,      wkstn_name
              FROM      my_tab2
              WHERE      workstation     NOT IN (     -- Begin NOT IN sub-query
                                               SELECT      workstation
                                       FROM      my_tab1
                                       WHERE      workstation     IS NOT NULL
                                     )     -- End NOT IN sub-query
           ) foj     -- End in-line view foj for full outer join
    ,       my_tab3  mt3
    ORDER BY  foj.wkstn_name
    ,       foj.workstation
    ,       mt3.my_nbr1
    ,       mt3.my_nbr2
    ;
    

    Thanks for posting the CREATE TABLE and INSERT statements, and very clear expected results!

    user11033437 wrote:
    ... So, what I want, it's a full outer join of t1 and t2 on workstation and a cross join of one with the t3.

    She, exactly!
    The trickiest part is when and how get SUM (my_value). You could address the question of exactly what my_tab3 must be attached to a cross that's exactly what should look like the result set of the full outer join between my_tab1 and my_tab2 to. To do this, take your desired results, remove columns that do not come from the outer join complete and delete duplicate rows. You will get:

    workstation     sum(my_value)     wkstn_name
    -----------     -------------   ----------
    ABCD          30          WKSTN 1
    A123          35          WKSTN 2
    B456          0          WKSTN 3
    ????          5          NULL          
    

    So the heart of the problem is how to get these results of my_tab1 and my_tab2, which is done in the subquery FOJ above.

    I tried to use auto-documenté in my code names. I hope you can understand.
    I could spend hours explaining the different parts of this query more in detail, but I don't know that I would lose some of that time, explain things that you already understand. If you want an explanation of the specific element (s), let me know.

  • Inline query vs cross join

    Hi all

    Two tables which have no relationship with each other. For example, an Employees table and a systemparameter with a startworktime table.

    We need a query with the data in the two tables:

    Get all employees and the startworktime (which is the same for everyone)

    Which is cheaper: an inline query or a product Cartesian or crossjoin?

    Inine:

    Select name, function

    (by selecting startworktime in systemparameter)

    employees;

    Cartesian product:

    SELECT name, function, startwoime

    rktfrom used

    Cross join systemparameter;

    Your opinion about this.

    Both these do the same thing. I seriously doubt if we would have the benefits of performance on the other.

    Kind regards

  • Difference between a CROSS JOIN and a Cartesian product of the noted comma?

    Hello everyone,

    Oracle version: Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit
    OS: Linux Fedora Core 17 (x86_64)

    I was practicing on recursive subquery factoring based on oracle examples available in the documentation
    http://docs.Oracle.com/CD/E11882_01/server.112/e26088/statements_10002.htm#i2129904

    I was working on an example that displays the hierarchy of each manager with related employees. Here's how
    WITH tmptab(empId, mgrId, lvl) AS
    (
        SELECT  employee_id, manager_id, 0 lvl
        FROM employees
        WHERE manager_id IS NULL
        UNION ALL
        SELECT  employee_id, manager_id, lvl+1
        FROM employees, tmptab
        WHERE (manager_id = empId)
    )
    SEARCH DEPTH FIRST BY mgrId SET order1
    SELECT LPAD(' ', lvl * 3, ' ') || empId AS empId
    FROM tmptab;
    Which gives the desired result
    EMPID
    ---------------------
    100
       101
          108
          109
          110
          111
          112
          113
          200
          203
          204
          205
          206
       102
          103
          104
          105
          106
          107
       114
          115
          116
          117
          118
          119
       120
          125
          126
          127
          128
          180
          181
          182
          183
       121
          129
          130
          131
          132
          184
          185
          186
          187
       122
          133
          134
          135
          136
          188
          189
          190
          191
       123
          137
          138
          139
          140
          192
          193
          194
          195
       124
          141
          142
          143
          144
          196
          197
          198
          199
       145
          150
          151
          152
          153
          154
          155
       146
          156
          157
          158
          159
          160
          161
       147
          162
          163
          164
          165
          166
          167
       148
          168
          169
          170
          171
          172
          173
       149
          174
          175
          176
          177
          178
          179
       201
          202
    
    107 rows selected.
    
    SQL> 
    However, by chance, I noticed that if I put CROSS JOIN instead of put a comma between table names, the same query behaves differently.

    In other words, if instead of writing
    . . .
    UNION ALL
        SELECT  employee_id, manager_id, lvl+1
        FROM employees, tmptab
        WHERE (manager_id = empId)
    I am writing
    . . .
    UNION ALL
        SELECT  employee_id, manager_id, lvl+1
        FROM employees CROSS JOIN tmptab
        WHERE (manager_id = empId)
    I get the following error message
    ERROR at line 4:
    ORA-32044: cycle detected while executing recursive WITH query
    Any idea?
    Correct me if I'm wrong, but I remember, oracle supports as many JOIN CROSSROADS notation for Cartesian product (vector product =). For example
    SQL> WITH tmptab1 AS
      2  (
      3      SELECT 'a1' AS colval FROM DUAL UNION ALL
      4      SELECT 'a2' AS colval FROM DUAL UNION ALL
      5      SELECT 'a3' AS colval FROM DUAL
      6  ),
      7  tmptab2 AS
      8  (
      9      SELECT 'b1' AS colval FROM DUAL UNION ALL
     10      SELECT 'b2' AS colval FROM DUAL
     11  )
     12  SELECT t1.colval, t2.colval
     13  FROM tmptab1 t1 CROSS JOIN tmptab2 t2;
    
    CO CO
    -- --
    a1 b1
    a2 b1
    a3 b1
    a1 b2
    a2 b2
    a3 b2
    
    6 rows selected.
    
    SQL> LIST 13
     13* FROM tmptab1 t1 CROSS JOIN tmptab2 t2
    SQL>
    SQL>
    SQL> CHANGE /CROSS JOIN/,
     13* FROM tmptab1 t1 , tmptab2 t2
    SQL> 
    SQL>
    SQL> LIST
      1  WITH tmptab1 AS
      2  (
      3  SELECT 'a1' AS colval FROM DUAL UNION ALL
      4  SELECT 'a2' AS colval FROM DUAL UNION ALL
      5  SELECT 'a3' AS colval FROM DUAL
      6  ),
      7  tmptab2 AS
      8  (
      9  SELECT 'b1' AS colval FROM DUAL UNION ALL
     10  SELECT 'b2' AS colval FROM DUAL
     11  )
     12  SELECT t1.colval, t2.colval
     13* FROM tmptab1 t1 , tmptab2 t2
    SQL> 
    SQL> /
    
    CO CO
    -- --
    a1 b1
    a2 b1
    a3 b1
    a1 b2
    a2 b2
    a3 b2
    
    6 rows selected.
    
    SQL> 
    So if the two rated commas and CROSS JOIN have the same semantics, why do I get a cycle mentioned above cites recursive subquery factoring while the same query works pretty well with comma between table instead of CROSS JOIN names? Because if a cycle is detected (= current element ancestor) it means that the product with the CROSS JOIN notation produces duplicates which are absent in the result of the Cartesian product rated comma.

    I would appreciate it if you could kindly shed some light.

    Thanks in advance,

    Kind regards
    Dariyoosh

    Hello

    dariyoosh wrote:
    ... Oracle terminology could become really confusing. But once again, according to the online glossary, a Cartesian product is apparently regarded as a join
    http://docs.Oracle.com/CD/E11882_01/server.112/e25789/glossary.htm?type=popup#CNCPT44493
    >

    There is no doubt that a Cartesian product (also called cross join) is a join. If loops in a WITH recursive clause are detected after completing the joins, but before other conditions apply, the relevant question here is "what are the requirements to join?
    In the ANSI syntax, the distinction is always clear. Join conditions occur in the... Clause WE

    SELECT  employee_id, manager_id, lvl + 1
    FROM      employees
    JOIN        tmptab          ON  (manager_id = empId)     -- Join condition
    ;
    

    and other conditions occur in the WHERE (or HAVING or CONNECT BY) clause.

    SELECT  employee_id, manager_id, lvl + 1
    FROM            employees
    CROSS JOIN         tmptab
    WHERE  (manager_id = empId)     -- NOT a join condition
    ;
    

    In the joins of the former, it seems to be the case that any condition involving 2 or more tables (or the + indicator of outer join) is a condtion of join:

    SELECT  employee_id, manager_id, lvl + 1
    FROM      employees
    ,         tmptab
    WHERE  (manager_id = empId)     -- Join condition
    ;
    
  • CARTESIAN/CROSS JOIN

    Hello
    I use OBIEE version 11.1.1.6.0. I created made dummy table and column in the physical layer. and join all the dimension table with this fact. but I don't know how the business model to deal with it. can someone help me to create a cross join?
    Thank you

    Published by: 968086 on October 30, 2012 12:59 AM

    Follow this link
    http://www.rittmanmead.com/2009/08/Oracle-BI-EE-10-1-3-4-1-reporting-on-non-transactional-dimension-values-equivalence-of-outer-joins/

    Score pls help if

  • Extract multiple lines using the technique of the cross join

    Hello.

    Can someone suggest a method to return 3 lines of a query when otherwise would return only one line?

    I am trying to reach the analog SQL logic to this topic-
    SELECT x.foo, p.id, p.name FROM people p CROSS JOIN (SELECT 1 AS foo UNION ALL SELECT 2 UNION ALL SELECT 3) x;
    Reason: I want a result three rows (n) force and use GROUP BY with case statements to create 3 levels summary.

    Here is a simple SQL logical expression that works for my setup - OBI
    SELECT
         "- Nx_CSDG0_Repair_Orders (Depot Repair Views)".Repair_Number saw_0,
         "- Nx_CSDG0_Repair_Orders (Depot Repair Views)".SR_Operating_Unit_Name saw_1
    FROM
         "[Noetix-NoetixGlobalRepository] NoetixViews for Oracle Service"     
    WHERE 
         ("- Nx_CSDG0_Repair_Orders (Depot Repair Views)".Repair_Number = '338246')
    But I think that I can't do--
    SELECT
         "- Nx_CSDG0_Repair_Orders (Depot Repair Views)".Repair_Number saw_0,
         "- Nx_CSDG0_Repair_Orders (Depot Repair Views)".SR_Operating_Unit_Name saw_1
    FROM
         "[Noetix-NoetixGlobalRepository] NoetixViews for Oracle Service"
         CROSS JOIN (SELECT 1 AS foo UNION ALL SELECT 2 UNION ALL SELECT 3)
    WHERE 
         ("- Nx_CSDG0_Repair_Orders (Depot Repair Views)".Repair_Number = '338246')
    But what peut do?

    Thank you.

    -cs

    Hi CSeelig,

    The BI server uses the ANSI SQL standard. Then all the SQL that follows this specification in OBIEE will work.

    I did an example with intensification:
    http://gerardnico.com/wiki/dat/OBIEE/logical_sql/obiee_sql_densification

    You will see a cross join to make a densification.

    See you soon
    Nico

  • Pivot + cross join

    Hello

    I wrote the following query, which works very well:
    select * from
    (
         select
              to_char(SCB_OPENTIME, 'YYYY-MM') as curr_date,
              SCB_TASK
         from EM_DATA_MSR_SC
    )
    pivot
    (
         count(SCB_TASK) for curr_date in
         (
              '2011-01',
              '2011-02',
              '2011-03',
              '2011-04',
              '2011-05',
              '2011-06',
              '2011-07',
              '2011-08',
              '2011-09',
              '2011-10',
              '2011-11',
              '2011-12'
         )
    );
    Now, I need to apply a cross thereon join:
    select * from
    (
         select
              to_char(SCB_OPENTIME, 'YYYY-MM') as curr_date,
              SCB_TASK
         from EM_DATA_MSR_SC
         where
              EMSCG_STATUS = status.name
    )
    pivot
    (
         count(SCB_TASK) for curr_date in
         (
              '2011-01',
              '2011-02',
              '2011-03',
              '2011-04',
              '2011-05',
              '2011-06',
              '2011-07',
              '2011-08',
              '2011-09',
              '2011-10',
              '2011-11',
              '2011-12'
         )
    )
    cross join
    (
        select 0, 'Closed' as name from DUAL union
        select 1, 'Denied' from DUAL union
        select 2, 'Open' from DUAL
    ) status;
    When I try to run this query, I get this error message:
    "STATUS"."NAME": invalid identifier
    However, SQL is supposed to have brought on a deep level table references.
    I'm doing something wrong?

    Hello

    If this is what you want, then you don't want a cross join. The inner join in the view online with no name is the only reference to beaches you need.

    with ranges as
    (
        select 0, 0 as mini, 20 as maxi from DUAL union
        select 1, 21, 50 from DUAL union
        select 2, 51, 300 from DUAL
    )
    select * from
    (
         select  r.mini,
              r.maxi,
              to_char (t.DAT, 'YYYY-MM')     as curr_date,
              t.NUM
         from      TEST     t
         join      RANGES     r     on      t.NUM >= r.mini
                        and      t.NUM <= r.maxi
    )
    pivot
    (
         count(NUM) for curr_date in
         (
              '2011-01',
              '2011-02',
              '2011-03',
              '2011-04',
              '2011-05',
              '2011-06',
              '2011-07',
              '2011-08',
              '2011-09',
              '2011-10',
              '2011-11',
              '2011-12'
         )
    )
    ORDER BY  mini
    ;
    

    Depending on your data and your needs, you might want an outer join, not an inner join, like this:

    ...     from          RANGES     r
         LEFT OUTER JOIN     TEST     t     on      t.NUM >= r.mini
                             and      t.NUM <= r.maxi
    

    Published by: Frank Kulash, November 7, 2011 12:20
    Alternative ADED of outer join

  • cross join?

    I was asked if the veiw (select what is wrttien to make the view) has a cross join and follwing some ANSI compliance. So my question is... as table 3 below is used by alias tp and same table3 is used by alias tp2... commandeer that be considered as a cross join?

    Sorry, I'm very new to SQL...
    select col1, col2, col3 from table1 t, table2 t1, table3 tp
    where
    ---
    ---
    ---
    AND tp.phs_id =
                          (SELECT tp2.phs_id
                             FROM table3 tp2
                            WHERE tp2.id = tsp.id
                             AND ROWNUM < 2)
    Published by: user11168115 on May 14, 2009 12:43

    Hello (and welcome)
    No, would not be a CROSS JOIN, since your alias tp2 JOINED tp (I guess you mean tp even if you have a TSP). A CROSS JOIN is where no JOIN condition at all is specified for a table (also known as the Cartesian product ), and if it's compatible ANSI SQL will actually be the words CROSS JOIN specified in the JOIN clause. For example:

    SELECT *
       FROM table1
     CROSS JOIN table2;
    

    Otherwise, non-compliant ANSI:

    SELECT *
      FROM table1, table2;
    
  • Cross join to Hi in oracle

    Hello

    I have below the text values.

    Platimum

    Silver

    VIP

    Bronze

    I want to get cross-from above like four

    PlatimumSilverVIPBronze
    PlatimumVIPSilverBronze
    PlatimumBronzeVIPSilver
    PlatimumSilverVIPBronze

    And so on. It should give me 16 combinations that I guess.

    How can I achieve this?

    Kind regards

    Mahesh

    Another way to generate permutations (if nocycle seems suspicious)

    with

    data in the form of

    (select "Platimum" val of union double all the)

    Select 'Cash' of all the double union

    Select 'VIP' of all the double union

    Select "Bronze" double

    ),

    permutator (swap) as

    (select val

    from the data

    Union of all the

    Select swap. «, » || Val

    data,.

    permutator

    where instr (permutation, val) = 0

    )

    Select the permutation

    of the permutator

    where regexp_count (permutation, ',') = 3

    order by swapping

    PERMUTATION
    Bronze, Platimum, silver, VIP
    Bronze, Platimum, VIP, Silver
    Bronze, Silver, Platimum, VIP
    Bronze, Silver, VIP, Platimum
    Bronze, VIP, Platimum, Silver
    Bronze, Silver, VIP, Platimum
    Platimum, Bronze, silver, VIP
    Platimum, Bronze, Silver, VIP
    Platimum, silver, Bronze, VIP
    Platimum, silver, VIP, Bronze
    Platimum, VIP, Bronze, silver
    Platimum, VIP, silver, Bronze
    Silver, Bronze, Platimum, VIP
    Silver, Bronze, VIP, Platimum
    Money, Platimum, Bronze, VIP
    Silver, Platimum, VIP, Bronze
    Silver, VIP, Bronze, Platimum
    Silver, VIP, Platimum, Bronze
    VIP, Bronze, Platimum, silver
    VIP Bronze, silver, Platimum
    VIP, Platimum, Bronze, silver
    VIP, Platimum, silver, Bronze
    VIP, silver, Bronze, Platimum
    VIP, money, Platimum, Bronze
  • Line that auto cross

    I was looking at the previous posts regarding how to determine if a LINE intersects itself...

    and the orientation was use sdo_intersection to do a free intersection on the line (i.e. pass in the same line with two args)

    then use sdo_getvertices and County

    I tried to do however get (what I think) is the strange results.

    Two examples:

    In an example here, I have a line that starts and ends at the same point, and the point that has a count > 1 is not the starting point / end.

    Select t.x, t.y, count (*) total

    Of

    TABLE)

    () sdo_util.getVertices

    sdo_geom. () SDO_INTERSECTION

    (select SDO_GEOMETRY (2002, 8265, NULL, SDO_ELEM_INFO_ARRAY (1,2,1), SDO_ORDINATE_ARRAY ()))

    -122.3117777778, 47.4498888889,

    -122.3, 47.45,

    -122.5375277777,48.7926944444,

    -122.3117777778, 47.4498888889

    () as double geom)

    ,

    (select SDO_GEOMETRY (2002, 8265, NULL, SDO_ELEM_INFO_ARRAY (1,2,1), SDO_ORDINATE_ARRAY ()))

    -122.3117777778, 47.4498888889,

    -122.3, 47.45,

    -122.5375277777,48.7926944444,

    -122.3117777778, 47.4498888889

    () as double geom)

    0.005))

    ) t

    Group of t.x, t.y;

    The above returns this point as the point of intersection free?

    -122.5375277777,48.7926944444

    I also have a more complex example that contains a line with many points, I'm expecting TWO x, y of the points as a free intersection points...

    There are THREE of them.  The I wasn't expecting to have a number of 2 is - 122.5903, 48.8563

    Based on below why would '-122.5903, 48.8563' be considered a free intersection point?

    Select t.x, t.y, count (*) total

    Of

    TABLE)

    () sdo_util.getVertices

    sdo_geom. () SDO_INTERSECTION

    (select SDO_GEOMETRY (2002, 8265, NULL, SDO_ELEM_INFO_ARRAY (1,2,1), SDO_ORDINATE_ARRAY ()))

    -122.3117777778, 47.4498888889,-122.2955, 47.7347,-122.293, 47.8181,-122.2904, 47.9015,-122.2879, 47.9849,-122.3108, 48.0519,-122.3332, 48.1356,-122.3808, 48.2197,-122.3788, 48.2864,-122.4015, 48.3701,-122.4247, 48.4371,-122.4732, 48.5045,-122.5222, 48.5551,-122.5209, 48.6052,-122.5448, 48.6555,-122.5435, 48.7055,-122.5431, 48.7222,-122.5418, 48.7723,-122.5903, 48.8563,-122.6422, 48.8068,-122.6434, 48.7567,-122.6198, 48.6897,-122.544, 48.6889,-122.5431, 48.7222,-122.5667, 48.7892,-122.6426, 48.7901,-122.6695, 48.7236,-122.6711, 48.6569,-122.6731, 48.5735,-122.7002, 48.4903,-122.3117777778 47.4498888889

    () as double geom)

    ,

    (select SDO_GEOMETRY (2002, 8265, NULL, SDO_ELEM_INFO_ARRAY (1,2,1), SDO_ORDINATE_ARRAY ()))

    -122.3117777778, 47.4498888889,-122.2955, 47.7347,-122.293, 47.8181,-122.2904, 47.9015,-122.2879, 47.9849,-122.3108, 48.0519,-122.3332, 48.1356,-122.3808, 48.2197,-122.3788, 48.2864,-122.4015, 48.3701,-122.4247, 48.4371,-122.4732, 48.5045,-122.5222, 48.5551,-122.5209, 48.6052,-122.5448, 48.6555,-122.5435, 48.7055,-122.5431, 48.7222,-122.5418, 48.7723,-122.5903, 48.8563,-122.6422, 48.8068,-122.6434, 48.7567,-122.6198, 48.6897,-122.544, 48.6889,-122.5431, 48.7222,-122.5667, 48.7892,-122.6426, 48.7901,-122.6695, 48.7236,-122.6711, 48.6569,-122.6731, 48.5735,-122.7002, 48.4903,-122.3117777778 47.4498888889

    () as double geom)

    0.005))

    ) t

    Group of t.x, t.y;

    I could do something wrong but I wanted to see if the experts knew why these two example of free intersection tests do not seem to return the results, I expect.

    Thanks in advance

    See you soon

    Look at the geometry out of just sdo_geom. SDO_INTERSECTION (no count and not sdo_util.getVertices). Both your examples are closed loops, and the SDO_INTERSECT is producing a reorganization but closed loop, it starts at a different point. By definition, a closed loop has the Summit even at the beginning and at the end, so the starting point will be a number two. The Geometry produced by sdo_geom. SDO_INTERSECTION is a legitimate topological representation of the intersection of the two loops: this is another representation of the object of the geometic.

    I conclude that the SDO_INTERSECTION trick for line self intersections requires more work where the line is a closed loop. If you know that the input is a closed circuit, so I think excluding the last Summit of the intersection works:

    Select t.x, t.y, count (*) total

    de)

    Select sdo_geom. () SDO_INTERSECTION

    SDO_GEOMETRY (2002, 8265, NULL, SDO_ELEM_INFO_ARRAY (1,2,1), SDO_ORDINATE_ARRAY ())

    -122.3117777778, 47.4498888889,

    -122.3, 47.45,

    -122.5375277777,48.7926944444,

    -122.3117777778, 47.4498888889

    ))

    ,

    SDO_GEOMETRY (2002, 8265, NULL, SDO_ELEM_INFO_ARRAY (1,2,1), SDO_ORDINATE_ARRAY ())

    -122.3117777778, 47.4498888889,

    -122.3, 47.45,

    -122.5375277777,48.7926944444,

    -122.3117777778, 47.4498888889

    ))

    0.0001) I

    the double) ii

    , ARRAY)

    t sdo_util.getVertices (II.i))

    where rownum<>

    Group of t.x, t.y

    Incidentally, you should use a smaller tolerance, tolerance 0.005 tell 0.0001 - there are other free intersections that were not given by the SDO_INTERSECTION Tower. The line between - 122.5667, 48.7892 and - 122.6426, 48.7901 is less than 0, 05 - 122.5903, 48.8563

  • Expected to a join behaviours?

    Hello

    formalities:

    Select * from version of v$.

    Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

    PL/SQL Release 11.2.0.3.0 - Production

    CORE Production 11.2.0.3.0

    AMT for 64-bit Windows: Version 11.2.0.3.0 - Production

    NLSRTL Version 11.2.0.3.0 - Production

    the question:

    I was just wondering why this "join" between A and B do not work. A has no lines, B a 1 row

    > my first answer... it should give 1 rank...

    but alas... it doesn't!

    the original request:

    SELECT A.*,
      B.*,
    CASE WHEN A.METH = 'PAL' THEN '1'
      ELSE A.CFGNR_OFRESTPAL 
    END VWNR_OFRESTPAL
    FROM    CDCROBOTVERDICHTLOCSTATVW A,
      CDCVERDICHTSETTINGSVW B
    

    > No rows returned

    so I checked the counts:

    Select count (*) in the CDCROBOTVERDICHTLOCSTATVW A;

    0

    Select count (*) in the CDCVERDICHTSETTINGSVW B;

    1

    Hmmm... very strange

    so I ran a few tests more:

    SELECT  A.*, B.*, CASE WHEN A.METH = 'PAL' THEN '1' ELSE A.CFGNR_OFRESTPAL END VWNR_OFRESTPAL
    FROM    CDCVERDICHTSETTINGSVW B , CDCROBOTVERDICHTLOCSTATVW A 
    

    > no line

    SELECT A.*, B.*, CASE WHEN A.METH = 'PAL' THEN '1' ELSE A.CFGNR_OFRESTPAL END VWNR_OFRESTPAL
    FROM    CDCVERDICHTSETTINGSVW B cross join CDCROBOTVERDICHTLOCSTATVW A 
    

    > no line

    SELECT A.*, B.*, CASE WHEN A.METH = 'PAL' THEN '1' ELSE A.CFGNR_OFRESTPAL END VWNR_OFRESTPAL
    FROM    CDCVERDICHTSETTINGSVW B full outer join CDCROBOTVERDICHTLOCSTATVW A on 1 =1
    

    > This returns the line from B correctly

    ARTNR PROJECTNR VARIANT PROVIDER QMAX PRIO METH PALLETS SOMQTY FULLPALS RESTQTY RESTPALS CFGNR_OFRESTPAL FREELOCS DUMMYRECIP GEEN_VERDICHTING MAXSRCPALS MAXOPENPICKSETS NR_OF_RESTPAL ORDTYPE PRIO_ARTNR VERD_INRGRP VWNR_OFRESTPAL
    VERDICHT1143VERDICHTQSE00918CLL80CDCROB

    SELECT A.*, B.*, CASE WHEN A.METH = 'PAL' THEN '1' ELSE A.CFGNR_OFRESTPAL END VWNR_OFRESTPAL
    FROM  CDCVERDICHTSETTINGSVW B left join CDCROBOTVERDICHTLOCSTATVW A on 1 = 1
    

    > it is also returns the same rank B

    Does anyone have an idea on how to fix this... or where to look to fix this?

    This is a cross join. It is a Cartesian product. If there are no rows in a table, then you get no rows in the result.

    SQL> with a as (select 1 x from dual), b as (select 1 y from dual where 1=0)
      2  select a.*, b.*
      3  from a, b;                                                             
    
    no rows selected
    

    A left or right, or full outer join is apparently what you wanted.

  • Join Oracle

    Hello

    I have the following data

    create or replace view offdays as

    (

    Select 1 empid, to_date('23/01/2015','dd/mm/yyyy') dt, 1 offday for all double union

    Select 2 empid, to_date('23/01/2015','dd/mm/yyyy') dt, 1 offday for all double union

    Select 3 empid, to_date('21/01/2015','dd/mm/yyyy') dt, 1 double offday

    );

    create or replace view payrolldates as

    (

    Select to_date('21/01/2015','dd/mm/yyyy') as dt of union double all the

    Select to_date('22/01/2015','dd/mm/yyyy') as dt of union double all the

    Select to_date('23/01/2015','dd/mm/yyyy') as dt of union double all the

    Select to_date('24/01/2015','dd/mm/yyyy') as dt of union double all the

    Select to_date (' 25/01/2015 ',' dd/mm/yyyy') in the double dt

    );

    Select * from payrolldates and b offdays left outer join on b.dt order = b.empid a.dt, a.dt;

    With the above query, I get after release

    DATE

    EMPID

    OFF

    23/01/2015

    1

    1

    23/01/2015

    2

    1

    21/01/2015

    3

    1

    22/01/2015

    < NULL >

    < NULL >

    24/01/2015

    < NULL >

    < NULL >

    25/01/2015

    < NULL >

    < NULL >

    But I need the output as follows

    DATE

    EMPID

    OFF

    21/01/2015

    1

    0

    22/01/2015

    1

    0

    23/01/2015

    1

    1

    24/01/2015

    1

    0

    25/01/2015

    1

    0

    21/01/2015

    2

    0

    22/01/2015

    2

    0

    23/01/2015

    2

    1

    24/01/2015

    2

    0

    25/01/2015

    2

    0

    21/01/2015

    3

    1

    22/01/2015

    3

    0

    23/01/2015

    3

    0

    24/01/2015

    3

    0

    25/01/2015

    3

    0

    I use oracle 10 g.

    Help, please

    According to the power requested that each record in the view offdays should be repeated as many times as the number of records in the view of payrolldates-, this could be done via the cross join and a simple CASE statement to get an output of the column offday.

    Select a.dt

    empid

    case when a.dt = b.dt

    then offday

    0 otherwise

    end offday

    of payrolldates one

    offdays b

    order of b.empid, a.dt;

  • join with condition

    Hi all

    Is there a possible way to cross the join with condition?

    I want something like this:

    Table A: custid, accu_id, sum

    CustID, accu_id unique =

    CustomerID amount accu_id

    10 25 400

    10 35 447

    10 29 420

    20 30 510

    30 35 472

    .

    .

    .

    Table b: accu_id, description

    accu_id description

    shoes 25

    Book 29

    30 computer

    pen 35

    Note: in table A, it is a mismatch of the accu_id values that do not use. Please, take into account this.

    I want to see all the columns in the TABLE B for each custid in A. TABLE (something like cross join but with ONE article.) The following query does not work.

    Select * from a right join B on A.accu_id = B.accu_id;

    10-25

    10-29

    10-30

    10-35

    20-25

    20-29

    20-30

    20-35

    30 25

    30 29

    30 30

    30-35

    What should I do for this?

    Thanks in advance

    Use partition outer join:

    with a (too)

    Select double union all 10 custid, accu_id 25, amount 400

    Select 10,35,447 from all the double union

    Select 10,29,420 from all the double union

    Select 20,30,510 from all the double union

    Select double 30,35,472

    ),

    b like)

    Select accu_id 25, "shoe" description of all the double union

    Select 29, 'book' from dual union all

    Select 30, 'computer' from dual union all

    Select 35, 'pen' from dual

    )

    Select a.custid,

    a.accu_id,

    a.amount,

    b.

    a

    by (a.custid) partition

    right join

    b

    On a.accu_id = b.accu_id

    order of a.custid,

    a.accu_id

    /

    AMOUNT ACCU_ID CUSTID DESCRIPT
    ---------- ---------- ---------- --------
    10 25 400 shoe
    10 29 420 book
    10 35 447 pen
    10 computer
    20 30 510 computer
    shoe 20
    book 20
    20                       pen
    30 35 472 pen
    30 shoe
    30 book

    AMOUNT ACCU_ID CUSTID DESCRIPT
    ---------- ---------- ---------- --------
    30 computer

    12 selected lines.

    SQL >

    SY.

  • Join dba_segments to dba_indexes

    Oracle 11.2.0.2.0

    Oracle 5.6 Linux 64 bit

    The following query is based on one I've seen on AskTom.  The first is to generate the sql code to move the tables to one tablespace to another.  I am trying to add logic to

    (1) to generate code for a single table, as specified by the user

    (2) also generate code to rebuild all the indexes on the selected table.

    Here's what I have so far.  Note that all "tables" are seen in the standard dictionary.

    Select decode (segment_type, 'TABLE',

    nom_segment, table_name) order_col1,.

    Decode (segment_type, 'TABLE', 1, 2) order_col2.

    'Edit ' | segment_type. ' ' || nom_segment |

    Decode (segment_type, 'TABLE', 'move', 'rebuild') |

    Decode (segment_type, 'TABLE', "tablespace stageb",

    ' (rebuild tablspace stage_idx') |

    ';'

    from dba_segments,.

    (select table_name, index_name dba_indexes)

    where segment_type in ('TABLE', 'INDEX')

    and nom_tablespace in ('STAGE', 'STAGE_IDX')

    and (segment_type = 'TABLE' and nom_segment = upper ('& tblnme'))

    and nom_segment = index_name

    order by 1, 2

    I tried various permutations, or return the code for all indexes regardless of their association of table, or no index at all.  Having trouble getting my head wrapped around it.

    Like this? I've highlighted in RED user input values.

    SQL > with my_segment
    2 as
    (3)
    4. Select the owner 'STAGE', 'TABLE', 'My_table' double nom_segment segment_type
    5 Union all the
    6. Select the owner 'STAGE', 'TABLE', 'FUBAR' double nom_segment segment_type
    7 union of all the
    8. Select owner 'STAGE', 'INDEX', 'UK_ATTR_GROUP' nom_segment double segment_type
    9)
    10, my_index
    11 as
    (12)
    13. Select owner 'STAGE' index_name 'UK_ATTR_GROUP', 'STAGE' table_owner, table_name "My_table", nom_tablespace "STAGE".
    14 double
    all 15 union
    16. Select index_name 'PK_MY_TABLE', 'STAGE' table_owner, table_name 'My_table', owner 'STAGE', 'STAGE_IDX' nom_tablespace
    17 of the double
    18)
    19 select coalesce (table_script, index_script) script
    20 of)
    21 select case when rno = 1 then
    22 'alter table ' | owner | '.' || nom_segment | "move the tablespace STAGE_B;
    end 23 table_script
    24, "alter index". owner | '.' || index_name | 'rebuild TABLESPACE STAGE_IDX;' index_script
    25 years of)
    26 select s.owner
    27, s.segment_name
    28, i.index_name


    29, row_number() over NWR (partition by order of s.segment_name of i.index_name)
    30                           , ind
    s my_segment 31
    32                        left
    Join 33 my_index I
    34 on s.owner = i.table_owner
    35 and s.segment_name = i.table_name
    36 cross join (select level double ind connect by level<=>
    37 where s.segment_type = 'TABLE '.
    38 and s.segment_name = 'my_table '.
    39                   )
    where the 40 (rno = 1 and ind (1, 2))
    41 or (rno > 1 and ind in (1))
    42         );

    SCRIPT
    -------------------------------------------------------------
    ALTER table STEP. My_table move tablespace STAGE_B;
    change the index STEP. PK_MY_TABLE rebuild TABLESPACE STAGE_IDX;
    change the STAGE.UK_ATTR_GROUP TABLESPACE STAGE_IDX index rebuild;

    SQL >

  • left outer join, after summarizing

    Hello

    I need to create a summary of a lot of tables and join the result set with another table. The other table must do a left outer join. When I do a left outer join, the column which do not appear in the second table appear as a draft. However, I would like to than all results in the table on the right to replicate once for each row in the left table.  Here is a sample data set:

    CREATE THE TRIGHT TABLE

    (

    PKEY CHAR(1),

    AMT NUMERIC (13.2).

    GRP TANK (4),

    FILTER TANK (3)

    )

    INSERT INTO TRIGHT VALUES ('A', 200 ' GRP1 "," XXX ");

    INSERT INTO TRIGHT VALUES ('A', 500, "GRP2', 'XXX'");

    INSERT INTO TRIGHT VALUES ('A', 150 'GRP1', 'YYY');

    INSERT INTO TRIGHT VALUES ('A', 100, "GRP2', 'YYY'");

    CREATE THE TLEFT TABLE

    (

    PKEY CHAR (1)

    )

    INSERT INTO VALUES TLEFT ('A')

    INSERT INTO TLEFT VALUES ('B')

    SELECT A.PKEY, GRP, SUM (AMT) OF TLEFT A LEFT JOIN

    (SELECT PKEY, GRP, SUM (AMT) AS AMT IN TRIGHT)

    WHERE FILTER = "XXX".

    PKEY, GRP) B

    ON A.PKEY = B.PKEY

    A.PKEY GROUP, GRP

    The result I get is:

    A 200 GRP1

    A 500 GRP2

    B (white) (white)

    Instead, I would like the following:

    A 200 GRP1

    A 500 GRP2

    GRP1 B 0

    B GRP2 0

    Can anyone help? Thanks in advance.

    Sorry, I couldn't find the button skip yet, although there is an urgent need for such a feature in this forum.

    That is why another chance for you:

    SELECT

    a.PKEY

    GRP

    SUM (case

    When a.pkey = b.pkey

    can AMT 0 otherwise

    AMT end)

    Of

    TLEFT HAS

    Cross JOIN

    TRIGHT B

    where FILTER = "XXX".

    GROUP BY a.PKEY, GRP

    ORDER BY a.PKEY, GRP

    PKEY GRP AMT
    A GRP1 200
    A GRP2 500
    B GRP1 0
    B GRP2 0

Maybe you are looking for