bad result of 11 2 recursive with clause GR

This thread is a continuation of ORA-01790 11 GR 2 recursive with clause
select * from v$version;

BANNER
-------------------------------------------------------
Oracle Database 11g Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
with rec(dayc,LV) as(
select cast(date '2010-04-15' as date),1 from dual
union all
select cast(dayc+1 as date),LV+1
  from rec
 where LV<= 3)
select * from rec;

DAYC             LV
--------  ---------
10-04-15          1
10-04-14          2
10-04-13          3
10-04-12          4
Why the DAYC column is decreased?
I think correct resultSet is less than
DAYC             LV
--------  ---------
10-04-15          1
10-04-16          2
10-04-17          3
10-04-18          4

Indeed, a complete mess with dates as recursive columns:

If you repeat the column somehow it seems to work again:

SQL> with rec(lv, dayc, dayc2) as
(
select 1, cast(sysdate as date), null from dual
 union all
select  lv + 1, cast(dayc as date) + 1, dayc  from rec  where lv <= 3
)
--
--
select *  from rec
/
        LV DAYC       DAYC2
---------- ---------- ----------
         1 08.04.2010
         2 09.04.2010 08.04.2680
         3 10.04.2010 09.04.2680
         4 11.04.2010 10.04.2680

4 rows selected.

but after playing with it a bit, I would certainly avoid using dates in the form of recursive columns (yet).

Tags: Database

Similar Questions

  • recursive with clause

    Hi all

    I'm using oracle 11.2.0.4

    I m using this for the purpose of learning

    Below is my table and insert statement

    CREATE TABLE NUMBERS (NUMBER NUM);

    INSERT A NUMBER VALUES (1);

    INSERT A NUMBER VALUES (2);

    INSERT A NUMBER VALUES (3);

    INSERT THE 4 NUMBERS;

    WITH RSFC(ITERATION,RUNNING_FACTORIAL) AS

    (SELECT NUM AS ITERATION,

    1 AS RUNNING_FACTORIAL

    A NUMBER

    WHERE NUM = 1

    UNION ALL

    SELECT R.ITERATION + 1,

    R.RUNNING_FACTORIAL * B.NUM

    RSFC R INNER JOIN NUMBERS B

    ON (R.ITERATION + 1) + B.NUM

    )

    SELECT THE ITERATION, RUNNING_FACTORIAL

    THE RSFC

    I learn recursive with clause

    When I am trying to run the query, I get

    ORA-00920: invalid realtional operator

    What's not in this query, please help me


    Thanks and respect.

    Guylaine

    Hello

    2937991 wrote:

    Hi all

    I'm using oracle 11.2.0.4

    I m using this for the purpose of learning

    Below is my table and insert statement

    CREATE TABLE NUMBERS (NUMBER NUM);

    INSERT A NUMBER VALUES (1);

    INSERT A NUMBER VALUES (2);

    INSERT A NUMBER VALUES (3);

    INSERT THE 4 NUMBERS;

    WITH RSFC(ITERATION,RUNNING_FACTORIAL) AS

    (SELECT NUM AS ITERATION,

    1 AS RUNNING_FACTORIAL

    A NUMBER

    WHERE NUM = 1

    UNION ALL

    SELECT R.ITERATION + 1,

    R.RUNNING_FACTORIAL * B.NUM

    RSFC R INNER JOIN NUMBERS B

    ON (R.ITERATION + 1) + B.NUM

    )

    SELECT THE ITERATION, RUNNING_FACTORIAL

    THE RSFC

    I learn recursive with clause

    When I am trying to run the query, I get

    ORA-00920: invalid realtional operator

    What's not in this query, please help me

    Thanks and respect.

    Guylaine

    The error has actually nothing to do with the WITH clause.

    Join conditions (i.e. the conditions following the keyword WE) must be expressions that are evaluated to TRUE or FALSE.  The join condition, you have validated, however

    (R.ITERATION + 1) + B.NUM

    corresponding to a NUMBER.  The following would be a valid join condition:

    (R.ITERATION + 1) = B.NUM

    but I don't know if it of what you wanted or not.

  • Since Oracle11gR2, "recursive with clause" is supported.

    http://download.Oracle.com/docs/CD/E11882_01/server.112/e16579/Aggreg.htm#i1007241
    < i > note that the Oracle database does not support recursive use of the WITH < /i > clause
    This is false.

    Since recursive with clause Oracle11gR2 is supported.
    Correct this misrepresentation of the document.

    Like recursive with the clause - 8)

    I have passed this information along to the author of this manual.

  • RECURSIVE with clause - check if there are nodes descendants.

    Hello guys,.

    I have a question. I wanted to ask you if you could help with the recursive following with clause.

    Imagine the following scenario:

    [code]

    DROP TABLE departments;
    CREATE TABLE departments
    (
      dpt_id NUMBER(10),
      dpt_name VARCHAR2(100),
      parent_dpt_id NUMBER(10),
      is_valid NUMBER(1)
    );
    
    
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (1, 'MY COMPANY', NULL, 1);
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (2, 'SALES', 1, 1);
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (3, 'HR', 1, 1);
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (4, 'IT', 1, 1);
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (5, 'SECURITY', 1, 1);
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (21, 'LOCAL SALES', 2, 1);
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (22, 'INTERNATIONAL SALES', 2, 1);
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (31, 'RECRUITMENT', 3, 1);
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (32, 'LOGISTIC', 3, 1);
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (34, 'TRAINING', 3, 1);
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (41, 'HELPDESK', 4, 1);
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (42, 'HARDWARE', 4, 1);
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (43, 'SOFWARE', 4, 1);
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (44, 'LICENCING', 4, 1);
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (51, 'CONTROL', 4, 1);
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (52, 'POLICIES', 4, 1);
    
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (100, 'US', 22, 1);
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (101, 'RUSSIA', 22, 1);
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (102, 'AFRICA', 22, 1);
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (103, 'MOROCCO', 102, 0);
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (104, 'ALGERIA', 102, 0);
    
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (125, 'MANAGERS', 31, 1);
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (125, 'TECHNICAL PERSONS', 31, 1);
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (126, 'DBA', 125, 1);
    INSERT INTO departments(dpt_id, dpt_name, parent_dpt_id, is_valid) VALUES (127, 'ARCHITECT', 125, 0);
    

    [/ code]

    The following query illustrates the structure:

    [code]

    WITH tree(dpt_id, dpt_name, parent_dpt_id, lvl) AS
    (
      SELECT d.dpt_id, d.dpt_name, d.parent_dpt_id, 1
        FROM departments d
       WHERE parent_dpt_id IS NULL
       UNION ALL
      SELECT d.dpt_id, LPAD(' ',t.lvl + 1) || d.dpt_name AS dpt_name, d.parent_dpt_id, t.lvl + 1
        FROM departments d
       INNER JOIN tree t
               ON d.parent_dpt_id = t.dpt_id
    ) SEARCH DEPTH FIRST BY dpt_id SET A
    SELECT * FROM tree;
    

    [/ code]

    However, I need an additional indicator on all records. I need to know if a given "Ministry" has "descendant nodes.  But I don't know how I can do it. Is this possible with recursive clause with or I have to use a CONNECT BY?

    For example, in this scenario, the node 102 (AFRICA) has two childeren, but two invalids. So, it should return 0 for this node. Any idea?

    Thank you

    Hello

    user13117585 wrote:

    ... What I don't understand is how I can assess certain conditions using recursive queries on nodes descendants. Is it still possible?

    Ask yourself if you can include information about the child lines that you evaluate the WITH recursive clause?  Of course, but where you get this information?  You can join another copy of departments and call it c.  But since there is a one-to-many relationship between parents and children, you probably want to join an aggregate of departments, who has only 1 line by id.
    However, according to what results you want (you still have not shown or explained) there may be simpler and more effective to use a subquery (a scalar subquery, an EXISTS subquery or an IN subquery), either during or after the construction of the tree.

    Assuming you want to get these comes from the sample data you posted:

    PARENT_ VALID_

    DPT_ID DPT_NAME DPT_ID LVL CHILDREN HAS

    ------ ---------------------- ------- ------ -------- ------

    1. MY 1-4-1 COMPANY

    2   SALES                      1      2        2      2

    21 2 3 0 3 LOCAL SALES

    22 2 3 3 4 INTERNATIONAL SALES

    100     US                      22      4        0      5

    101. 22 4 0 6 RUSSIA

    102 22 4 0 7 AFRICA

    103 102 5 0 8 MOROCCO

    104 102 5 0 9 ALGERIA

    3   HR                         1      2        3     10

    RECRUITMENT OF 31 3 3 2 11

    125 31 4 1 12 MANAGERS

    126 125 5 0 13 S/N

    127 125 5 0 14 ARCHITECT

    125 PEOPLE 31 4 1 15 TECHNIQUES

    S/N 126 125 5 0 16

    127 125 5 0 17 ARCHITECT

    32 3 3 0 18 LOGISTICS

    34 3 3 0 19 TRAINING

    4   IT                         1      2        6     20

    41 4 3 0 21 HELPDESK

    42 4 3 0 22 MATERIAL

    43 4 3 0 23 SOFWARE

    44 4 3 0 24 LICENSES

    51 CONTROL 4 3 0 25

    52 4 3 0 26 POLICIES

    5 1 2 0 27 SECURITY

    Here's a way to do it:

    WITH got_valid_children AS

    (

    SELECT parent_dpt_id

    COUNT (*) AS valid_children

    Ministries

    WHERE is_valid! = 0

    GROUP BY parent_dpt_id

    )

    , tree (dpt_id, dpt_name, parent_dpt_id, lvl, valid_children) AS

    (

    SELECT d1.dpt_id

    d1.dpt_name

    d1.parent_dpt_id

    ,   1

    , NVL (c1.valid_children, 0)

    DEPARTMENT d1

    LEFT OUTER JOIN got_valid_children c1

    ON d1.dpt_id = c1.parent_dpt_id

    WHERE d1.parent_dpt_id IS NULL

    UNION ALL

    SELECT d.dpt_id

    , LPAD (' ', t.lvl + 1) | d.dpt_name AS dpt_name

    d.parent_dpt_id

    t.lvl + 1

    , NVL (c.valid_children, 0) AS valid_children

    DEPARTMENTS d

    INNER JOIN tree t

    ON d.parent_dpt_id = t.dpt_id

    LEFT OUTER JOIN got_valid_children c

    ON d.dpt_id = c.parent_dpt_id

    ) SEARCH FIRST BY dpt_id SET A DEPTH

    SELECT *.

    Tree

    ;

    However, in this case the ITI will be simpler and more effective to get the valid_children column after you have trained tree, like this:

    WITH the tree (dpt_id, dpt_name, parent_dpt_id, lvl, is_valid) AS

    (

    SELECT dpt_id

    dpt_name

    parent_dpt_id

    ,      1

    is_valid

    Ministries

    WHERE parent_dpt_id IS NULL

    UNION ALL

    SELECT d.dpt_id

    , LPAD (' ', t.lvl + 1) | d.dpt_name AS dpt_name

    d.parent_dpt_id

    t.lvl + 1

    d.is_valid

    DEPARTMENTS d

    INNER JOIN tree t

    ON d.parent_dpt_id = t.dpt_id

    ) SEARCH FIRST BY dpt_id SET A DEPTH

    SELECT m.*

    ,         (

    SELECT COUNT (*)

    Tree

    WHERE is_valid = 1

    AND parent_dpt_id = m.dpt_id

    ) AS valid_children

    M tree - m is for the home

    ;

  • Convert connected by recursive with clause

    Dear Experts,

    I'm using Oracle 12.1.02.

    Suite SQL returns all the date between the start_dt and end_dt provided.  How can I change this SQL in the WITH recursive clause

    WITH parms
         AS (SELECT   to_date('07/01/2015 00:00:00','MM/DD/YYYY HH24:MI:SS') start_dt, to_date('07/31/2015 23:59:59','MM/DD/YYYY HH24:MI:SS') end_dt
                    FROM   DUAL)
          SELECT       CAST (start_dt AS DATE) + (LEVEL - 1) ts_day
                   FROM   parms
             CONNECT BY   LEVEL <= TRUNC ( (CAST (end_dt AS DATE) - CAST (start_dt AS DATE)) + 1)
    

    Thank you.

    Hello

    Here's one way:

    WITH dates_wanted (ts_day) AS

    (

    SELECT TO_DATE (1 July 2015 ', "DD/MM/YYYY")- or what date you want start

    OF the double

    UNION ALL

    SELECT ts_day + 1

    OF dates_wanted

    WHERE ts_day< to_date="" ('07/31/2015',="" 'dd/mm/yyyy') ="" --="" or="" whatever="" end="" date="" you="">

    )

    SELECT *.

    OF dates_wanted

    ORDER BY ts_day

    ;

    In fact, I get an error when I do this in Oracle 11.2.0.2.0, but I think it's just a bug.  I don't have another version around that time.

    PS: as Andrew pointed out in response #4, below, "DD/MM" above should be "MM/DD".  My mistake.

    PPS: It works in Oracle 12.1.0.1.0 (and "MM/DD/YYYY", of course).

  • BAD RESULTS WITH OUTER JOINS AND TABLES WITH A CHECK CONSTRAINT

    HII All,
    Could any such a me when we encounter this bug? Please help me with a simple example so that I can search for them in my PB.


    Bug:-8447623

    Bug / / Desc: BAD RESULTS WITH OUTER JOINS AND TABLES WITH a CHECK CONSTRAINT


    I ran the outer joins with check queries constraint 11G 11.1.0.7.0 and 10 g 2, but the result is the same. Need to know the scenario where I will face this bug of your experts and people who have already experienced this bug.


    Version: -.
    SQL> select * from v$version;
    
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE    11.1.0.7.0      Production
    TNS for Solaris: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - Production

    Why do you not use the description of the bug test case in Metalink (we obviously can't post it here because it would violate the copyright of Metalink)? Your test case is not a candidate for the elimination of the join, so he did not have the bug.

    Have you really read the description of the bug in Metalink rather than just looking at the title of the bug? The bug itself is quite clear that a query plan that involves the elimination of the join is a necessary condition. The title of bug nothing will never tell the whole story.

    If you try to work through a few tens of thousands of bugs in 11.1.0.7, of which many are not published, trying to determine whether your application would be affected by the bug? Wouldn't be order of magnitude easier to upgrade the application to 11.1.0.7 in a test environment and test the application to see what, if anything, breaks? Understand that the vast majority of the problems that people experience during an upgrade are not the result of bugs - they are the result of changes in behaviour documented as changes in query plans. And among those who encounter bugs, a relatively large fraction of the new variety. Even if you have completed the Herculean task of verifying each bug on your code base, which would not significantly easier upgrade. In addition, at the time wherever you actually performed this analysis, Oracle reportedly released 3 or 4 new versions.

    And at this stage would be unwise to consider an upgrade to 11.2?

    Justin

  • Can I use a reference WITH clause in a JOIN?

    Is the syntactically correct query?

    WITH abc AS

    (

    SELECT a.col1 d,

    e a.col2

    substr(a.Col1,2) f

    FROM table1 a JOIN

    Table 1 b ON a.col1 = b.col1

    WHERE a.col2! = b.col2

    )

    SELECT id, name, date of birth, ssn

    FROM table3 LEFT OUTER JOIN (SELECT DISTINCT abc.d of ABC WHERE abc.f = 'EF') / * Please note the addition of the WHERE clause in the veiw inline * /.

    ON table3.id = abc.d

    I try to use "abc" with a JOIN. Are there restrictions WITH clause?

    Thank you!

    Post edited by: user11951344

    Hello

    user11951344 wrote:

    I apologize I addded the WHERE clause too in mode inline "abcd" (in your query) to understand the purpose. The purpose of doing an OUTER JOIN of "abc" with table3 is to check the "EF" State = abc.f. Please note the Add where clause to update in my original question now.

    I see the changes, but everything in #5 response still applies.  There is no need to make a join in this case.  The output depends entirely on table3.  You will get the same results no matter what, if anything it either, is in table1, so any reference to table1 does that complicate the query and makes probably slower.

  • Recursive WITH - I understood its mechanics correctly?

    Hello

    I searched the net for a 'simple' explanation of the works of the recursive WITH. I found a lot of information but not a pretty simple explanation. After a lot of reading and playing with him. I he conceptualized and would like verification or confirmation of people here who know much more than me, I'm not too far off the mark. Corrections to any misunderstanding, that I might have are greatly appreciated.

    Conceptualization follows an example using:
      consider the following recursive WITH applied to the EMP table:
    
      with X (tree, mgr, depth) as
        (
          --
          -- 1. seed
          --
          select cast(ename as varchar2(100)),
                 mgr,
                 0
            from emp
           where ename = 'MILLER'
         union all
         --
         -- 2. recursive rule
         --
          select cast(x.tree || ' --> ' || e.ename as varchar2(100)),
                 e.mgr,
                 x.depth + 1
            from emp e, x              -- THE SOURCE OF THE RECURSION
           where x.mgr = e.empno
        )
        --
        -- 3. Display the resulting set X
        --
      select tree leaf__branch__root
        from x
        --
        -- get all the levels in the result set
        --
       where depth in (select depth from x);
    
      STEP 1. Setup/Seed
    
      The set X needs an initial row or step 2 (the recursive rule)
      would return the empty set which would cause the recursion to
      end.
    
      STEP 2. Recursive rule
    
      The select statement joins the seed to the EMP set causing a
      new row to be added to set X.
    
      The addition of this new row causes a "problem", that is,
      the join "emp e, x" is now incomplete because the newly
      added row (into X) did not participate in the join.  To
      correct this "problem" the result of joining the newly added
      row and EMP is added to the result set (X) which causes yet
      another row to be added, which forces the join to be
      recalculated again.
    
      In the example above, MILLER causes CLARK to be added, therefore
      the join must be recalculated taking CLARK into account.
    
      CLARK causes KING to be added, the join is recalculated to take
      KING into account but, since KING has no managers, no row is
      added into X and the join no longer needs to be recalculated.
      (the addition of KING did not cause the result of the join to 
       change)
    
      Procedurally, the process could be conceptualized as follows:
    
      (recursive WITH seems to be tail recursive which can always be
       transformed into a loop)
    
      row_added := TRUE;   { because of STEP 1 }
    
      while row_added
        retrieve last row added
        if (result of join between last row and EMP is not
            the empty set  { STEP 2 })
           then add new row to X
           else row_added := false
      end-while
    Oversimplify or I missed something important? Is this a reasonably solid way of thinking how a recursive WITH work?

    All comments welcome :) Thank you!

    John.

    Hi, John,.

    440BX - 11 GR 2 wrote:
    ... STEP 1. The plant/seed program

    All X requires an initial line or step 2 (the recursive rule)
    Returns the empty set that would cause recursion to
    end.

    I think that the 'end condition.
    There is no need to produce lines; step 2 takes place regardless of the outcome of step 1.
    I don't know of any situation where it really matters, but for the record, step 2 is always executed at least once.

    STEP 2. Recursive rule

    The select statement joins seed to the EMP causing a
    new line to be added to the value of X.

    The addition of this new line causes a 'problem', i.e.
    now the join 'emp e, x' is incomplete because the newly
    the line added (in X) not participated in the join. TO
    fix this 'problem' the result of joining to the newly added
    line and EMP is added to the result (X) set which still causes
    another line to add, which forces the join to be
    recalculated again.

    I don't know that I follow what you mean by a 'problem '.

    In the example above, MILLER causes CLARK to add, which is why
    the join must be recalculated taking into account CLARK.

    CLARK made KING to add, the join is adjusted to take
    KING into account but, since KING has no managers, no line is
    added by X and the join should no longer be recalculated.
    (the addition of the KING did not cause the result of the join in)
    change)

    Procedurally, the process could be conceptualized as follows:

    (recursive WITH seems to be recursive tail which can always be)
    transformed into a loop)

    row_added: = TRUE; {due STEP 1}

    everything row_added
    retrieve the last line added
    If (result of the join between the last row and EMP is not
    the empty set {STEP 2})
    then add new line to X
    Another row_added: = false
    end-while that

    Oversimplify or I missed something important? Is this a reasonably solid way of thinking how a recursive WITH work? I don't know that I followed your way of thinking or the pseudocode above.
    I think what you're saying, is that the recursive step (step 2, the part after the UNION ALL) circulates over and over again, and set the results added to the result, until it produces no new line, at which point the process terminates. In the affirmative: Yes, it's true.

  • bad results for the search for context on the empty element tags

    I use Oracle DBMS 11.1 and 11.2 and created an index on an XML column context (article group: PATH_SECTION_GROUP).
    When you enter a query like

    SELECT count (*) FROM my_table t WHERE contains (t.co_xml,'hasPath(/tag1/tag2)') > 0

    I get bad results if tag2 is an empty element tag (< tag2 / >) that appears somewhere in the
    XML instance, but is NOT directly under tag1.

    For example, the following XML instance is (but shouldn't!):

    < a >
    blah blah < tag3 > < tag1 > < / tag3 > < / tag1 >
    blah < tag4 > < tag2 / > < / tag4 >
    < /a >

    This seems to happen only for the empty element tags. Is this a known bug and does anyone know of a workaround?

    Thank you in advance for your help!
    Roman

    Like you, I've been looking in the wrong places, bug of thought, rather than documented behavior. Finally, I came across the following excerpt from the next section of the documentation on haspath in Oracle text reference.

    http://download.Oracle.com/docs/CD/B28359_01/text.111/b28304/cqoper.htm#i997393

    Limits

    Because of the way in which XML data section are saved, false match may appear with XML sections that are completely empty as follows:

    
    

    A query of HASPATH(A/B/E) or HASPATH(A/D/C) falsely corresponds to this document. This type of fake correspondent can be avoided by inserting some text between the empty tags.

  • using the WITH Clause

    The sql statement is

    Select ename, job
    from emp, dept
    where emp.deptno = dep.deptno
    and emp.deptno = 10
    Union
    Select ename, job
    from emp, dept
    where emp.deptno = dep.deptno
    and emp.deptno = 20

    the statement above using the WITH Clause

    WITH dept10 AS
    (select ename, job, hiredate, sal, comm, dname, emp.deptno
    from emp, dept
    where emp.deptno = dept.deptno
    and emp.deptno = 10)
    dept20 AS
    (select ename, job, hiredate, sal, comm, dname, emp.deptno
    from emp, dept
    where emp.deptno = dept.deptno
    and emp.deptno = 20)
    SELECT *.
    OF dept10
    UNION
    SELECT *.
    OF dept20

    Correct me if I'm wrong...

    Thank you

    Hello

    SeenuGuddu wrote:
    the Question is how u would provide the statement above by using the Clause

    The answer is that the question is meaningless. You will not use a WITH clause for this work.

    Because you must use a WITH clause to get the same results as the first query, I think the best way would be:

    WITH     unnecessary_sub_query     AS
    (
         select DISTINCT
                    ename, job
    --     ,      hiredate, sal, comm, dname,emp.deptno     -- these columns are not in the original query
         from      emp
         ,      dept
         where      emp.deptno = dept.deptno
         and      emp.deptno IN (10, 20)
    )
    SELECT  *
    FROM     unnecessary_sub_query;
    

    is this correct using Clause WITH or correct me

    No, it's not ok to make queries more complex or slow they need to do.
    In addition to the extra columns, it seems that the second query that you posted (the one who has a WITH clause) produces the same results as the first request.

  • WITH CLAUSE DOUBT

    Hi all

    I use under version

    Connected to Oracle Database 11g Express Edition Release 11.2.0.2.0

    SQL > WITH

    2 EMP

    3 AS

    4 ("JOEL" SELECT ENAME,

    DEPTNO 40 5

    6 OF

    DOUBLE 7

    8 UNION ALL

    9. SELECT ENAME "MARY."

    10 50 DEPTNO

    11 DOUBLE)

    12. SELECT E.ENAME,

    13 D.DNAME

    14. TO EMP E

    FULL JOIN 15

    DEPT 16 D

    17-HELP

    18 (DEPTNO);

    ENAME DNAME

    ----- --------------

    ACCOUNTING

    SEARCH

    SALES

    JOEL OPERATIONS

    MARY

    My doubt is that I use EMP as with the name of clause.

    In the condition when I select of the EMP.

    It is guaranteed that extracts data from request formed in the with clause, because I have a table named EMP in my diagram.

    Thank you

    Hello

    2947022 wrote:

    Hi all

    I use under version

    Connected to Oracle Database 11g Express Edition Release 11.2.0.2.0

    SQL > WITH

    2 EMP

    3 AS

    4 ("JOEL" SELECT ENAME,

    DEPTNO 40 5

    6 OF

    DOUBLE 7

    8 UNION ALL

    9. SELECT ENAME "MARY."

    10 50 DEPTNO

    11 DOUBLE)

    12. SELECT E.ENAME,

    13 D.DNAME

    14. TO EMP E

    FULL JOIN 15

    DEPT 16 D

    17-HELP

    18 (DEPTNO);

    ENAME DNAME

    ----- --------------

    ACCOUNTING

    SEARCH

    SALES

    JOEL OPERATIONS

    MARY

    My doubt is that I use EMP as with the name of clause.

    In the condition when I select of the EMP.

    It is guaranteed that extracts data from request formed in the with clause, because I have a table named EMP in my diagram.

    Thank you

    Yes, if the emp is an alias and emp is also a real table, and both have a scope, then Oracle assumes you mean the alias.  To avoid confusion and errors, do not use the actual table as alias names.

    It goes same for columns and column aliases.

    In PL/SQL, the same type of confusion can arise between the variables and the column names.  When there is a choice, Oracle assumes you are talking about the variable.

  • Acrobat DC more bad results of the marking of Word 2010

    Does using Acrobat DC and Word 2010 usually produced marking poor results? Everything gets the tag, but 95% of the labels are incorrect and role mapping is in every sense (title 1 title [final paragraph, text body mapped to title 2, etc.). Fortunately, lists and tables come out well. The results were not significantly different between a Word well formatted, built from a solid model structure or file Word a bit chaotic, riddled with direct formatting.

    I am relatively new to mark the PDF files for accessibility, and I wonder if I would get better results by using Word 2010 with Acrobat X or XI or Word 2013 2016 with Acrobat DC. My goal is to have structured accessible PDF files without the need of treatment of syndrome of carpal for my hands.

    Yikes! Certainly worth a try a newer version of Word to see if you get the best results, although I use Word 2010 and 2015 and have not noticed a huge difference. A rate of 20% on average, cleaning is a reasonable expectation, IMHO.

  • How to use WITH Clause of Apex classic report

    Hello.

    I use Apex 4.2.1 on mod_plsq and Oracle 11 g 3.

    I need to create a report classic usiing a WITH clause in the SQL report.  Apex keeps throwing the error 'CAN finf SELECT statement.

    I then wrapped my report query in an envelope, SELECT * clause.  Apex then raises an error you need to use a variable LONG.

    How is - a uses a WITH clause in the report query.

    Here is my report query:

    SELECT *.

    Of

    (

    WITH W

    AS

    (

    SELECT

    MIN (W1. URMT_BTRS_PK URMT_BTRS_PK),

    MIN (W1. EARLIER_NOTICE_ID URMT_NOTICES_ID),

    TO_CHAR (MAX (W1. EARLIER_NOTICE_TYPE NOTICE_TYPE)),

    TO_CHAR (MAX (W1. NOTICE_TYPE)) | '- Day' EARLIER_NOTICE_TYPE_DESC,.

    MAX (W1. LATER_NOTICE_ID URMT_NOTICES_ID),

    TO_CHAR (MIN (W1. LATER_NOTICE_TYPE NOTICE_TYPE)),

    TO_CHAR (MIN (W1. NOTICE_TYPE)) | '- Day' LATER_NOTICE_TYPE_DESC,.

    W1. NOCHG_STATUS_ORDER,

    W1. CHG_STATUS_ORDER,

    W1. ADD_STATUS_ORDER,

    W1. REM_STATUS_ORDER

    Of

    (

    SELECT

    URMT_BTRS_PK,

    URMT_NOTICES_ID,

    NOTICE_TYPE,

    : P202_NOCHG_STATUS_ORDER AS NOCHG_STATUS_ORDER,

    : P202_CHG_STATUS_ORDER AS CHG_STATUS_ORDER,

    : P202_ADD_STATUS_ORDER AS ADD_STATUS_ORDER,

    : P202_REM_STATUS_ORDER AS REM_STATUS_ORDER

    Of

    V_URMT_COMPARE_NUCLIDE_DATA

    WHERE

    URMT_NOTICES_ID IN (TO_NUMBER(:P202_COMPARE_EARLER_NOTICE_ID), TO_NUMBER (:P202_COMPARE_LATER_NOTICE_ID))

    ) W1

    )

    ------------------

    SELECT

    CASE WHEN (X.STATUS IS NULL) THEN

    CASE WHEN (INSTR(X.MASS ||)

    X.NUCLIDE_FRACTION

    ((' *', 1, 1) > 0) THEN '< div class = "chg_highlight" >' | HTF. ESCAPE_SC (' changed (' |)) (SELECT EARLIER_NOTICE_TYPE |) ' => ' || LATER_NOTICE_TYPE | ((' W)) | "< / div >"

    Else 'no change '.

    END

    WHERE (X.STATUS = 'Added') THEN ' < div class = "add_highlight" > ' | HTF. ESCAPE_SC(X.STATUS ||) "To" | (BY SELECTING LATER_NOTICE_TYPE_DESC IN W)) || "< / div >"

    WHERE (X.STATUS = 'Deleted') THEN "< div class ="rem_highlight"> ' |" HTF. ESCAPE_SC(X.STATUS ||) 'From ' | (BY SELECTING EARLIER_NOTICE_TYPE_DESC IN W)) || "< / div >"

    OF OTHER X.STATUS

    END AS STATUS

    ----

    CASE WHEN (X.STATUS_ORDER IS NULL) THEN

    CASE WHEN (INSTR(X.MASS ||)

    X.NUCLIDE_FRACTION

    ((' *', 1, 1) > 0) THEN (SELECT CHG_STATUS_ORDER FROM W)

    OTHER (SELECT NOCHG_STATUS_ORDER FROM W)

    END

    OF OTHER X.STATUS_ORDER

    END AS STATUS_ORDER,

    ----

    X.NUCLIDE,

    ----

    CASE WHEN (X.STATUS IS NULL) THEN

    BOX WHEN (SUBSTR (X.MASS, 1, 1) = ' *') THEN SUBSTR (X.MASS, 2).

    OF OTHER X.MASS

    END

    OF OTHER X.MASS

    MASS OF THE END AS,

    ----

    CASE WHEN (X.STATUS IS NULL) THEN

    BOX WHEN (SUBSTR (X.NUCLIDE_FRACTION, 1, 1) = ' *') THEN SUBSTR (X.NUCLIDE_FRACTION, 2).

    OF OTHER X.NUCLIDE_FRACTION

    END

    OF OTHER X.NUCLIDE_FRACTION

    END AS NUCLIDE_FRACTION

    Of

    (

    -THE NUCLIDES EXIST IN * TWO * BEFORE AND AFTER VIEW.  SOME OF THEIR ATTRIBUTES (MASS, NUCLIDE_FRACTION, ETC.)  MAY HAVE CHANGED.

    SELECT

    STATUS AS NULL,

    VALUE NULL AS STATUS_ORDER,

    C.NUCLIDE,

    BOX WHEN (NVL (C.A_MASS, 'Null')! = NVL (C.B_MASS, 'Null')) THEN ' *' | '< div class = "chg_highlight" >' | HTF. ESCAPE_SC (NVL (C.A_MASS, 'Null') |) ' => ' || NVL (C.B_MASS, 'Null')) | "< / div >"

    Of ANOTHER NVL (C.B_MASS, 'Null')

    MASS OF THE END AS,

    ----

    BOX WHEN (NVL (C.A_NUCLIDE_FRACTION, 'Null')! = NVL (C.B_NUCLIDE_FRACTION, 'Null')) THEN ' *' | '< div class = "chg_highlight" >' | HTF. ESCAPE_SC (NVL (C.A_NUCLIDE_FRACTION, 'Null') |) ' => ' || NVL (C.B_NUCLIDE_FRACTION, 'Null')) | "< / div >"

    Of ANOTHER NVL (C.B_NUCLIDE_FRACTION, 'Null')

    END AS NUCLIDE_FRACTION

    Of

    (

    SELECT

    A.NUCLIDE,

    TO_CHAR(A.MASS, '999.99EEEE') AS A_MASS,

    TO_CHAR(A.NUCLIDE_FRACTION, '99999.999EEEE') AS A_NUCLIDE_FRACTION,

    ----

    TO_CHAR(B.MASS, '999.99EEEE') AS B_MASS,

    TO_CHAR(B.NUCLIDE_FRACTION, '99999.999EEEE') AS B_NUCLIDE_FRACTION

    Of

    V_URMT_COMPARE_NUCLIDE_DATA, A.

    V_URMT_COMPARE_NUCLIDE_DATA B

    WHERE

    1 = 1

    AND A.URMT_BTRS_PK = B.URMT_BTRS_PK

    AND A.NUCLIDE = B.NUCLIDE

    AND A.URMT_BTRS_PK = (SELECT URMT_BTRS_PK FROM W)-TO_NUMBER(:P202_URMT_BTRS_PK)

    AND A.URMT_NOTICES_ID = (SELECT EARLIER_NOTICE_ID FROM W) - TO_NUMBER(:P202_COMPARE_EARLER_NOTICE_ID) - PRIOR NOTICE (EXAMPLE: 30 DAYS)

    AND B.URMT_NOTICES_ID = (SELECT LATER_NOTICE_ID FROM W) - TO_NUMBER(:P202_COMPARE_LATER_NOTICE_ID) - FURTHER VIEWS (EXAMPLE: 7 DAYS.)  NOTE: PRIOR NOTICE IS COMPARED WITH OPINIONS LATER, FOR EXAMPLE, 30 DAYS IS COMPARED TO 7 DAYS)

    ) C

    UNION

    -ADDED NOTICE LATER NUCLIDES.  THEY DO NOT APPEAR IN THE EARLIER OPINION.

    SELECT

    "Added" AS the STATUS,

    (BY SELECTING ADD_STATUS_ORDER IN W) AS STATUS_ORDER,

    A.NUCLIDE,

    TO_CHAR(A.MASS, '999.99EEEE') AS A_MASS,

    TO_CHAR(A.NUCLIDE_FRACTION, '99999.999EEEE') AS A_NUCLIDE_FRACTION

    Of

    V_URMT_COMPARE_NUCLIDE_DATA HAS

    WHERE

    1 = 1

    AND A.URMT_BTRS_PK = (SELECT URMT_BTRS_PK FROM W)-TO_NUMBER(:P202_URMT_BTRS_PK)

    AND A.URMT_NOTICES_ID = (SELECT LATER_NOTICE_ID FROM W)-TO_NUMBER(:P202_COMPARE_LATER_NOTICE_ID)

    AND NOT EXISTS

    (SELECT NULL

    OF V_URMT_COMPARE_NUCLIDE_DATA B

    WHERE B.URMT_BTRS_PK = A.URMT_BTRS_PK

    AND B.NUCLIDE = A.NUCLIDE

    AND B.URMT_NOTICES_ID = (SELECT EARLIER_NOTICE_ID FROM W)-TO_NUMBER(:P202_COMPARE_EARLIER_NOTICE_ID)

    )

    UNION

    -DELETED THE PREVIOUS NOTICE NUCLIDES.  THEY DO NOT APPEAR IN THE NOTICE LATER.

    SELECT

    'Removed' AS the STATUS,

    (BY SELECTING REM_STATUS_ORDER IN W) AS STATUS_ORDER,

    A.NUCLIDE,

    TO_CHAR(A.MASS, '999.99EEEE') AS A_MASS,

    TO_CHAR(A.NUCLIDE_FRACTION, '99999.999EEEE') AS A_NUCLIDE_FRACTION

    Of

    V_URMT_COMPARE_NUCLIDE_DATA HAS

    WHERE

    1 = 1

    AND A.URMT_BTRS_PK = (SELECT URMT_BTRS_PK FROM W)-TO_NUMBER(:P202_URMT_BTRS_PK)

    AND A.URMT_NOTICES_ID = (SELECT EARLIER_NOTICE_ID FROM W)-TO_NUMBER(:P202_COMPARE_EARLER_NOTICE_ID)

    AND NOT EXISTS

    (SELECT NULL

    OF V_URMT_COMPARE_NUCLIDE_DATA B

    WHERE B.URMT_BTRS_PK = A.URMT_BTRS_PK

    AND B.NUCLIDE = A.NUCLIDE

    AND B.URMT_NOTICES_ID = (SELECT LATER_NOTICE_ID FROM W)-TO_NUMBER(:P202_COMPARE_LATER_NOTICE_ID)

    )

    ) X

    )

    I have searched this forum for clues but found nothing.

    Any help would be appreciated.

    Thank you.

    Elijah

    EEG wrote:

    I'll now try to place my report within a packaged procedure, and then run it from there.  You don't love doing cela, but seem to don't have is not a choice.

    Elijah

    Huh?  How can you put a SELECT statement in a procedure?  you return a cursor reference?

    You create VIEWS.  You have three sections.  Give an opinion on each of them.  Test them with SQL Developer (or SQL * more)

    Build from there.

    In fact, it looks like you are trying to compare two tables"and return a DIFF

    THINKING IN SETS

    Use the WITH clause to build a 'virtual' table for EARLIER_NOTICE and a 'virtual' table for LATER_NOTICE.

    Use FULL OUTER JOIN to compare the two.

    THE FORMAT OF THE EXAMPLE:

    select * from (
    with w as ( .... )
    ,table_A as ( -- build the Virtual Table for EARLIER_NOTICE
    SELECT *
     FROM
     V_URMT_COMPARE_NUCLIDE_DATA A1
       join W on (A1.urmt_btrs_pk, W.urmt_btrs_pk  and A1.earlier_notcie_id=W.earlier_notice_id)
    
    --  old code
    -- WHERE
    -- 1 = 1-- why???
    -- AND A.URMT_BTRS_PK     = (SELECT URMT_BTRS_PK FROM W)    --TO_NUMBER(:P202_URMT_BTRS_PK)
    -- AND A.URMT_NOTICES_ID = (SELECT EARLIER_NOTICE_ID FROM W)   --TO_NUMBER(:P202_COMPARE_EARLER_NOTICE_ID)
    ,table_b as ( -- build the Virtual Table for the LATER_NOTICE
    
     select *
     from
    
     V_URMT_COMPARE_NUCLIDE_DATA B1
       join W on (b1.urmt_btrs_pk = W.urmt_btrs_pk  and b1.urmt_notice_id=W.later_notice_id)
    )
    
    --/*** NOW - WE COMPARE THE TWO ***/
    select CASE
        when A.urmt_btrs_pk is null then 'ADDED'
        when B.urmt_btrs_pk is null then 'DELETED'
        else 'possibily updated'
    end CHANGES_MADE
      , A.*
      , B.*
    
    FROM TABLE_A A FULL OUTER JOIN B
    ON (
     A.URMT_BTRS_PK = B.URMT_BTRS_PK
    AND A.NUCLIDE = B.NUCLIDE )
    




  • 12 c - function plsql with clause

    Hi all

    I'm mucking around with 12 c:

    SQL> select *
      2    from v$version;
    
    
    BANNER                                                                               CON_ID
    -------------------------------------------------------------------------------- ----------
    Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production              0
    PL/SQL Release 12.1.0.1.0 - Production                                                    0
    CORE    12.1.0.1.0      Production                                                                0
    TNS for Linux: Version 12.1.0.1.0 - Production                                            0
    NLSRTL Version 12.1.0.1.0 - Production                                                    0
    
    
    5 rows selected.
    
    
    

    specifically, I'm trying to use the new functionality to a pl/sql function in the SQL statement WITH clause:

    docco here:

    http://docs.Oracle.com/CD/E16655_01/server.121/e17209/statements_10002.htm#BABJFIDC

    the example they give is:

    WITH
    FUNCTION get_domain(url VARCHAR2) RETURN VARCHAR2 IS
      pos BINARY_INTEGER;
      len BINARY_INTEGER;
    BEGIN
      pos := INSTR(url, 'www.');
      len := INSTR(SUBSTR(url, pos + 4), '.') - 1;
      RETURN SUBSTR(url, pos + 4, len);
    END;
    SELECT DISTINCT get_domain(catalog_url)
      FROM product_information;
    /
    
    
    

    and so I made my own version of the Hello World:

    with function add_number(num1 number, num2 number) return number is
    begin
       return num1 + num2;
    end;
    select add_number(1,2) from dual;
    /
    
    
    

    but it compiles just in Developer SQL or SQLPlus.   I need a version upgrade or something perhaps?

    the output is:

    SQL> with function add_number(num1 number, num2 number) return number is
      2  begin
      3     return num1 + num2;
    with function add_number(num1 number, num2 number) return number is
         *
    ERROR at line 1:
    ORA-06553: PLS-103: Encountered the symbol "end-of-file" when expecting one of the following:
    . ( * @ % & = - + ; < / > at in is mod remainder not rem
    <an exponent (**)> <> or != or ~= >= <= <> and or like like2
    like4 likec between || member submultiset
    
    
    
    
    SQL> end;
    SP2-0042: unknown command "end" - rest of line ignored.
    SQL> select add_number(1,2) from dual;
    select add_number from dual
           *
    ERROR at line 1:
    ORA-00904: "ADD_NUMBER": invalid identifier
    
    
    
    
    SQL> /
    select add_number from dual
           *
    ERROR at line 1:
    ORA-00904: "ADD_NUMBER": invalid identifier
    
    
    

    Hello

    This means that you still have the problem, even after the correction of this? Because I did not:

    SQL*Plus: Release 12.1.0.1.0 Production on Wed Jul 3 11:32:54 2013
    
    Copyright (c) 1982, 2013, Oracle.  All rights reserved.
    
    SQL> with function add_number(num1 number, num2 number) return number is
      2  begin
      3    return num1+num2;
      4  end;
      5  select add_number(1,2) from dual;
      6  /
    SP2-0640: Not connected
    SQL> connect / as sysdba
    Connected to an idle instance.
    SQL> startup
    ORACLE instance started.
    
    Total System Global Area  263090176 bytes
    Fixed Size                  2359904 bytes
    Variable Size             205524384 bytes
    Database Buffers           50331648 bytes
    Redo Buffers                4874240 bytes
    Database mounted.
    Database opened.
    SQL> with function add_number( num1 number, num2 number) return number is
      2  begin
      3    return num1+num2;
      4  end;
      5  select add_number(1,2) from dual;
      6  /
    
    ADD_NUMBER(1,2)
    ---------------
                  3
    
    SQL>
    

    Best regards

    Nikolai

  • disadvantages of subquery factoring (with clause)

    Hi all

    What are disadvantages of subquery factoring (with clause) (if any)?

    Features have no disadvantages, disadvantages depends on how use you them...

Maybe you are looking for

  • Blue LEDs are disabled on my laptop series Qosmio G40

    All the blue leds on the top of my laptop are gone. Does anyone know how to get back them on the?

  • Text questions

    Kind of a strange here. In my program, I have a pop-up dialog box that asks you a work order number and you can scan using a barcode reader or type it in and then the program stops and turns a Boolean true process station.  This part works as expecte

  • AMRT.msi installation package

    Remember - this is a public forum so never post private information such as numbers of mail or telephone! Ideas:AMRT.msi installation package. went to install the upgrade for the security of ca and some how it lost in the process and did a restore an

  • Windows 7 does not recognize that I am connected to my home wireless network.

    I've recently updated my desktop and my laptop at home for Win 7. I'm trying to set up a home network, but on my laptop, I can't change my home network location. Even though my laptop is connected to the internet via my wireless router, Windows don't

  • Images are not displayed as thumbnails

    How have the possibility to open photos and see photos with multiple programs when I right click on a photo, I don't have the pictures anymore, I use vista and used to have thumbnails. Email removed for privacy Remember - this is a vista pubon I can