View vs Inline with clause

Dear technicians,

Here, I've seen two request giving the same result. Please someone who track better and more tell the optimizer

query to display online or at the request of the clause.

Select / * + RESULT_CACHE FIRST_ROWS_1 * / * of

(select

ID, ACTIVATIONSTATUS, BENAADHAARNO, BENACCOUNTNO, BENACCOUNTTYPE, BENADDRESS, BENBANKID,

BENCARDNO, BENMOBILENO, BENNAME, BENNICKNAME, IFSCCODE, INITIATORBANKID, INITIATORMOBILENO,

MAS, NBIN, OFT_INDICATOR, TRANSFERMODE to CONFIGDETAILS where

INITIATORMOBILENO = "12345678" and INITIATORBANKID = '789' and LOWER)

BENNICKNAME) = Lower ('ABC')) where rownum < = 1;

with a MODEL like

(select / * + RESULT_CACHE FIRST_ROWS_1 * /)

ID, ACTIVATIONSTATUS, BENAADHAARNO, BENACCOUNTNO, BENACCOUNTTYPE, BENADDRESS, BENBANKID,

BENCARDNO, BENMOBILENO, BENNAME, BENNICKNAME, IFSCCODE, INITIATORBANKID, INITIATORMOBILENO,

MAS, NBIN, OFT_INDICATOR, TRANSFERMODE to CONFIGDETAILS where

INITIATORMOBILENO = "12345678" and INITIATORBANKID = '789' and LOWER)

BENNICKNAME) = LOWER ('ABC'))

SELECT * FROM DUMMY where rownum < = 1;

Help, please

You should check the query plan.

As a general rule, when you write a query that I would normally use with the clause when the subquery is referred more than once, otherwise I would go for the void inline query. Then, I would check the plan.

Tags: Database

Similar Questions

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

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




  • Want to get an overview with the photo viewer and open with Photoshop

    Hello.  In all previous versions of Windows, I was able to do.  Right-click on an image and the 'Preview' option would open the image in the Windows Photo Viewer, and the option 'Open' it would open in Photoshop (or whatever the editor, I had chosen).  I just installed Windows 7 and I seem to be unable to get to do this.  If I select "Photo Viewer" as the default program for jpg files, I have TWO options 'Preview' in the right click menu.  Both will open it in Photo Viewer.  If I select Photoshop as the default program for jpg files, I get a 'Preview' and 'Open' option, but both open the image in Photoshop.

    How can I configure "Preview" with Photo Viewer, and 'open' with Photoshop?

    Thanks for the tips of registry.  I managed to find and fix the problem.  I tried to fix paint.net as the program open by default, and it has open in paint.net and presented in preview in Photo Viewer.  So I thought it was something to go astray with Photoshop.  Under HKEY_Classes_Root\Photoshop.JPEGFile.9\shell, there is a key-file for 'Preview '.  I deleted who, and now it opens in photoshop and previews in Photo Viewer.

  • net view \\addressIPserver fails with error 53

    Computer, net view \\addressIPserver fails with error 53, while it works from b
    If I restart the server, then it works.
    -online what command can I enter to make it work again, without having to restart the server?

    Server, computer, b are all seven windows

    ipconfig/all shows that Netbios over tcp/ip is enabled

    Hello

    Find computers on a domain network?
    If the computers are on a domain network, the question you posted would be better suited to the TechNet community. Please visit the link below to find a community that will provide the support you want.
  • 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.

  • What version of VMware View is compatible with vSphere 5.1?

    Greetings,

    I checked the compatibility tables and I watched that indicated that no version of VMware View was compatible with vSphere 5.1.

    Tom

    You will have to wait until VMware releases a hotfix or an update that is compatible with vSphere 5.1. Usually short gap between the release of vSphere and a compatible version of the view.

    André

  • 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

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

  • We can create a view or table with a form button?

    We can create a view or table with a form button using forms 6i?
    If Yes, what will be the command?

    Gul says:
    We can create a view or table with a form button using forms 6i?
    If Yes, what will be the command?

    Yes. You can. Use the FORMS_DDL built-in. For example

    BEGIN
      Forms_DDL('create table temp(n NUMBER)');
      IF NOT FORM_SUCCESS THEN
        Message ('Table Creation Failed');
      ELSE
        Message ('Table Created');
      END IF;
    END; 
    

    Hope this helps

    Hamid

  • Blog post notes - automation View 4.5 with Powershell

    As I did, I posted on my blog site, a summary of the notes of the recent view video Bootcamp. I don't know why this one discusses View 4.5 instead of 4.6, but there was still some good information overview. I liked the fact that the speaker has shown a lot of living examples.

    http://thevirtualheadline.com/2011/07/27/VMware-view-Bootcamp-notes-automating-view-4-5-with-PowerShell/

    Pete

    --------

    www.thevirtualheadline.com

    Thanks for this article.

  • 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

Maybe you are looking for