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

Tags: Database

Similar Questions

  • Not fully functional mouse with MacBook Pro 2010. I can scroll up and down, but can not move the cursor.  The mouse works with my new Macbook 12. No mouse problem but Macbook Pro?

    Not fully functional mouse with MacBook Pro 2010. I can scroll up and down, but can not move the cursor.  The mouse works with my new Macbook 12. No mouse problem but Macbook Pro?

    What specific mouse?

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

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

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

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




  • 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

    ;

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

  • Why the stop(); function interferes with another function?

    I have the code Ned Murphy to give me yesterday and it's going perfectly, but when I put the stop() function; so my frames are not crazy, this dose of code no longer works.

    The button (b4) which has this code is in a large movieclip with the other buttons, and the code is placed on the first layer in the main timeline, and not in the movieclip. So my question is... why the stop(); function interferes with this code? What I am doing wrong?

    (B4) button also has a code which is in position in the button and we have no problems with stop();

    The following code is located on the main timeline and it does not work when I put stop(); on the timeline of the movieclip that contains the button.

    bot.bott4._visible = false;

    B4.onRelease = function() {}

    bot.bott4._visible =! visible bot.bott4._;

    }

    The code that is in the button is:

    (release)

    {

    _root. Bot.gotoAndStop (5);

    _root.bott4.gotoAndStop (5);

    }

    Thank you

    Something seems wrong with the nomination that show you.  In the first set of code that you show that you're targeting bott4 as if it were a child to the bot, which means that they are not on the same timeline.  In the second set of code you bot target and bott4 as if they were on the same main timeline.

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

  • Create VO with CLAUSE

    I have need make a VO with CLAUSE as:
    SELECT Evento.CEDULA, 
           Evento.IDEVENTO, 
           Evento.IDPROYECTO, 
           Evento.DETALLE, 
           Evento.TOTALHORASNORMAL, 
           Evento.TOTALHORASEXTRA, 
           Evento.TOTALHORASESPECIAL
    FROM EVENTO Evento
    WHERE Evento.CEDULA IN (:p_persona_cedula)
    ORDER BY Evento.FECHAEVENTO,Evento.HORAINICIAL,Evento.HORAFINAL,Evento.CEDULA
    See the line: WHERE Evento.CEDULA IN (: p_persona_cedula)


    What type of use bind variable? P_persona_cedula is a String, I put only one value and I can't put multiple values in 'IN' clause

    Can I use any array, list or Collection as a Bind Variable Type? How can I do this?

    You cannot use a variable binding in an IN clause in a VO.
    Here are some workarounds: http://jobinesh.blogspot.com/2010/09/using-bind-variable-for-sql-statements.html
    http://blogs.Oracle.com/smuenchadf/examples/ sample 126 and 1

    Timo

  • How to call a function plugin with command line parameters

    I wrote a plugin that processes an open document. The treatment can be started by selecting a menu item in Acrobat. To start the processing of the command line, I also wrote a small Visual Basic executable file that currently a bit activates the menu command. However, I now have to pass some parameters to the plugin. I managed to call a function plugin with settings by loading the .api as a library file in the VB executable. But it seems that the entire Acrobat SDK functionality is not initialized in this way. So I can't work with the PDF file. How can I call my function plugin with settings in Acrobat? Thomas

    You must establish a form of IAC (communication monitor) of your VB application with your plugin.

    Whether COM, DDE, IPC, named pipes, shared memory files share, etc. is to you...

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

  • multiple with clause

    Hello guys.
    Can I use several time WITH clause in a single query.
    I can't find the way.
    I'm trying to do somtehing like:
    with a as
    (
    select 1 from x
    )
    with b as
    (
    select 2 from y
    )
    select a.1,b.2
    from a , b

    Hello

    Open a new Thread please

    ---

    Ramin Hashimzade

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

Maybe you are looking for

  • Do I need McAfee Security Scan with Firefox?

    Do I need to use the security program McAfee with Firefox?I just bought a new computer, and these are security programs installed. The default seems to be Firefox & I have to re-register in June for McAfee.

  • Y560P does support SATA 3?

    If I replace the hard drive with the sata ssd driver y560p 3, I work at full speed 6Gbs?

  • Adding 3D graphics path

    Hello I use the ActiveX tracking feature to display a time vs. frequency Impedance vs 3D illustration. Everything works fine. Now, I want to add a second story to the same graph without removing the first. I have read and tried everything / topic in

  • HandyCafe server filter

    not workinig me windows vista, I need a software...

  • Unable to start Vista

    original title: Vista does not at all - please help Hi I am running Windows Vista, but my laptop is no longer will allow me to access the windows.  He continues to go to the Startup Repair tool that never works. I tried all the options including we r