CTE in Oracle

Hi all

I tried to translate T - SQL, PL/SQL using editor scratch in SQL Developer. The T - SQL code consists of the CTE on his request.

T SQL

CREATE FUNCTION [dbo]. [Get_ChannelHierarchy]

(Int @ChannelID)

RETURNS @ChannelHierarchy TABLE

([ChannelId%] int Primary Key,)

Int [ParentChannelID],

RowID int)

AS

BEGIN

WITH [ChildChannelTree] ([ChannelID], [ParentChannelID], [RowID]) AS

(

SELECT

[ChannelId%]

[ParentChannelID]

1 AS [RowID]

TABLE [dbo]. [Channels] WITH (NOLOCK)

WHERE ChannelID = @ChannelID

UNION ALL

SELECT

[c]. [ChannelId%]

,[c]. [ParentChannelID]

[CTC]. [RowID] + 1

TABLE [dbo]. [Channels] HAVE [c] WITH (NOLOCK)

INNER JOIN [ChildChannelTree] AS [CTC] ON [c]. [ChannelId%] = [CTC]. ParentChannelID

WHERE [c]. [ChannelID] <>0

),

-Superset Channel ETC

[ChannelTree] ([ChannelID], [ParentChannelID], [RowID]) AS

(

SELECT

[ChannelId%]

[ParentChannelID]

[RowID]

FROM [ChildChannelTree] AS [CTC] WITH (NOLOCK)

UNION ALL

SELECT

[c]. [ChannelId%]

,[c]. [ParentChannelID]

[CTC]. [RowID] + 1

TABLE [dbo]. [Channels] HAVE [c] WITH (NOLOCK)

INNER JOIN [ChildChannelTree] AS [CTC] WITH (NOLOCK) ON [c]. [ChannelId%] = [CTC]. ParentChannelID

WHERE [c]. [ChannelId%] = 0 - Core channel only

AND [CTC]. [ChannelID] <>0

)

INSERT INTO @ChannelHierarchy

SELECT * from [ChannelTree]

OPTION (MAXRECURSION 20);

RETURN;

END

Output, translated by the editor from scratch.

SQL > CREATE OR REPLACE FUNCTION Get_ChannelHierarchy)

v_ChannelID NUMBER 2)

3 Get_ChannelHierarchy_pkg.tt_v_ChannelHierarchy_type RETURN PIPELINED

4 AS

5 v_temp SYS_REFCURSOR;

6 v_temp_1 TT_V_CHANNELHIERARCHY % ROWTYPE;

7. START

8. WITH 'ChildChannelTree' ('ChannelId%', 'ParentChannelID', / * 'ChannelId%', 'ParentChannelID', * / "Row_ID") AS

9 (SELECT ChannelID,

ParentChannelID 10,

Row_ID 11 1

12 CHANNELS

13 WHERE ChannelID = v_ChannelID

14 UNION ALL

15 SELECT c.ChannelID,

c.ParentChannelID 16,

17 TDC. Row_ID + 1

18 c strings

19 ChildChannelTree JOIN CTC

20 c.ChannelID = TDC. ParentChannelID

21. WHERE c.ChannelID <>0 - exclude Core channel because of the infite loop w/ParentChannelID

(22),

23 on-set channel ETC

24 'ChannelTree' ('ChannelId%', 'ParentChannelID', / * 'ChannelId%', 'ParentChannelID', * / "Row_ID") AS

25 (SELECT ChannelID, ParentChannelID, CTC Row_ID OF ChildChannelTree

26. ANY TRADE UNION

27 c.ChannelID SELECT,

c.ParentChannelID 28,

29 TDC. Row_ID + 1

30 OF c strings

31 ChildChannelTree JOIN TDC

32 c.ChannelID = TDC. ParentChannelID

33. WHERE c.ChannelID = 0 - Core channel only

34 AND the common customs tariff. ChannelID <>0

35)

36 select * from ChannelTree;

37 INSERT INTO tt_v_ChannelHierarchy

38 (SELECT * FROM ChannelTree)

39             ) ;

40 v_temp OPEN for SELECT * FROM tt_v_ChannelHierarchy;

41 LOOP

42 FETCH v_temp INTO v_temp_1;

EXIT 43

44. WHEN v_temp % NOTFOUND;

LINE pipe of 45 (v_temp_1);

46 END OF LOOP;

END 47;

Execution of this PL/SQL because of errors:

8/1 PL/SQL: statement ignored

19/7 PL/SQL: ORA-00942: table or view does not exist

37/2 PL/SQL: statement ignored

38/19 PL/SQL: ORA-00942: table or view does not exist

Should table "ChannelTree" must be created first? I cross-check in the db of the source (MSSQL), no user "ChannelTree" table exists.

Waiting for your advice on what I'm kinda new to PL/SQL.

Thank you!!

This is because

line36 should precede the line 8

so:

INSERT INTO...

WITH...

SELECT... OF;

HTH

Tags: Database

Similar Questions

  • How to convert the hierarchical query of SQL Server (CTE) to Oracle?

    How to convert the hierarchical query of SQL Server (CTE) to Oracle?

    WITH cte (col1, col2) AS
    (
    SELECT col1, col2
    FROM dbo. [tb1]
    WHERE col1 = 12
    UNION ALL
    SELECT c.col1, c.col2
    FROM dbo. [tb1] AS c INNER JOIN cte AS p ON c.col2 = p.col1
    )
    DELETE one
    FROM dbo. [tb1] AS an INNER JOIN b cte
    ON a.col1 = b.col1

    Hello
    Something like this maybe:

    DELETE FROM dbo.tb1 a
     WHERE EXISTS (
      SELECT 1
        FROM dbo.tb1 b
      WHERE a.co11 = b.col1
          AND a.col2 = b.col2
       START WITH b.col1 = 12
      CONNECT BY b.col2 = PRIOR b.col1)
    

    Although you need to do here is to check that CONNECT it BY SELECT, returns records you wait first, then the DELETION should work too.

  • With the help of CTE in Oracle

    How it is possible to do it in Oracle?

    SQL Server:

    WITH cte (col1, col2) AS
    (
    SELECT col1, col2
    OF dbo.tb1
    WHERE col1 = 12
    UNION ALL
    SELECT c.col1, c.col2
    FROM dbo.tb1 AS c INNER JOIN cte AS p ON c.col2 = p.col1
    where c.col1 = c.col2
    )
    SELECT * FROM cte

    It is probably necessary to START WITH... CONNECT BY FRONT?

    I tried to do so:

    WITH cte AS (SELECT col1, col2 col2 col1
    OF tb12
    WHERE col1 = 12
    UNION ALL
    C.Col1 SELECT col1, col2 c.col2
    OF tb12 c INNER JOIN cte p ON c.col2 = p.col1
    where c.col1 = c.col2)
    SELECT * FROM cte
    order by NULLS FIRST lvl;

    Result:
    ORA-32031: illegal reference to a query with the clause name

    What version of Oracle you are on? My 10.2.0.3 returns:

    with my_tab as (select 1 col1, null col2, 'root' val from dual union all
                    select 2 col1, 1 col2, 'user1' val from dual union all
                    select 3 col1, 1 col2, 'user2' val from dual union all
                    select 4 col1, 1 col2, 'user3' val from dual union all
                    select 5 col1, 2 col2, 'user4' val from dual union all
                    select 6 col1, 2 col2, 'user5' val from dual union all
                    select 7 col1, 3 col2, 'user6' val from dual union all
                    select 8 col1, 3 col2, 'user7' val from dual union all
                    select 9 col1, 4 col2, 'user8' val from dual union all
                    select 10 col1, 5 col2, 'user9' val from dual union all
                    select 11 col1, 5 col2, 'user10' val from dual union all
                    select 12 col1, 6 col2, 'user11' val from dual union all
                    select 13 col1, 6 col2, 'user12' val from dual union all
                    select 14 col1, 7 col2, 'user13' val from dual union all
                    select 15 col1, 7 col2, 'user14' val from dual)
    -- end of mimicking your data; USE SQL BELOW:
    select col1, col2
    from   my_tab
    start with col1 = 12
    connect by prior col1 = col2
    order by col1;
    
          COL1       COL2
    ---------- ----------
            12          6
    
  • CTE - possible in Oracle?

    I picked up this clever code of a SQL Server forum.

    Is this possible in Oracle?

    with data as (
     
    select * from ( values
      
    (1,1,'one'),
      
    (2,1,'two'),
      
    (3,1,'three'),
      
    (5,1,'five'),
      
    (6,1,'six')
     
    ) data(PKID, FKID, MYTEXT)
    )
    select lhs.*, sequence = count(*)
    from data lhs
    left join data rhs on rhs.FKID = lhs.FKID
     
    and rhs.PKID <= lhs.PKID
    group by
      lhs
    .PKID,
      lhs
    .FKID,
      lhs
    .MYTEXT

    ;

    Hello

    The common Table Expressions (aka "CTE", "Subquery factoring" or "WITH the terms") work in Oracle 9 and more.

    There other things in the query that you posted this will not work in Oracle.  For an equivalent of the Oracle, you may need to SELECT the table double literals.  There is an example of this in the FAQ forum:

    https://community.Oracle.com/message/9362002#9362002

    under the terms of paragraph 7.

  • CTE Oracle problem

    We are PL/SQL Release 11.2.0.3.0 - Production version

    I have this SQL...

    WITH

    (AS MemberSpanLast)

    SELECT MEMBERS. CONTRACT_NBR,

    Count (*) AS Contract_Count

    OF AMIOWN. MEMBERS

    GROUP OF MEMBERS. CONTRACT_NBR

    ORDER BY THE MEMBER. CONTRACT_NBR)

    SELECT *.

    OF MemberSpanList

    ;

    When I run it, I get this error...

    ORA-00942: table or view does not exist

    00942 00000 - "table or view does not exist.

    * Cause:

    * Action:

    Error on line: column 9: 9

    What I am doing wrong?

    Hoping someone can help out me.

    Thanks in advance.

    PSULionRP

    Maybe misspelling?

    WITH

    MemberSpanlast AS)

    .....

    IN MemberSpanlist

    ;

  • Staged beginning CTE and CTE

    Hello
    Can someone please shed some light on the available environments, we have for Crm od. Can we have total 4 environments in total? (production, staging, leading CTE, Trailing ETC)?

    Receive a quick response.

    Thank you
    my

    Staging environment - this will be a copy of your production environment, but the data and configuration will be as good as the last time that your environment has been refreshed. You can use this as a test environment to test all changes before migrating to production

    CTE-attack - this will be the basis of the CRMOD environment without any of your business or the configuration data. I think that for a certain fresh oracle will do a refresh for you (not sure). You can use as a dev environment to do all your development changes and migrate the code in your test environment by using the new migration tools provided by Oracle. This environment will be the first environment that is upgraded. Any changes which should be out in the new versions of all will be in CTE leading the environment even before the upgrade is done on the staging.

    CTE - leak - this is similar to CTE - Leading except this happen only after your production upgrade is (correct me if am wrong)

  • Java plugin for Oracle hangs after the last update

    As part of the requirement of the Oracle, we run JRE 1.7.60
    To update firefox this morning and now the plugin is constantly crashing.

    Hello

    Thanks for your reply, but I doubt that flash player is related to do with Java.

    And the Java applet crashing in my browser, I guess, should not be linked to my graphics driver, especially since the only update that took place was an update of firefox.

    In any case, Firefox for some reason any launches 2 additional tabs when executing the Java Applet (IE does not work). In the past, I'm used to close the first tab, since it contains nothing except an Oracle logo.
    However, it seems that after the last update of firefox, if this tab is closed, it cause Java to crash.

    Therefore, do not close the additional tabs by the Java Applet. However, this has never happened before, do not know what has changed in the latest version of Firefox to make it happen now?

    Thank you

  • Installed firefox 31 and now I can't seem to our oracle enterprise manager URL 12 c

    Hello

    Monday, I've upgraded to Firefox 31 and now I can not connect to our site Web of Oracle Enterprise Manager Cloud Control. I get the following error message:

    The secure connection failed

    An error occurred during a connection to lmoemxs101q.atl2.dc.sita.aero:7799. The issuer certificate is not valid. (Error code: sec_error_ca_cert_invalid)

       The page you are trying to view cannot be shown because the authenticity of the received data could not be verified.
       Please contact the website owners to inform them of this problem. Alternatively, use the command found in the help menu to report this broken site.
    

    I don't know what to do to get rid of this message. I need to use OEM to monitor our Oracle databases, and I am no longer able to do this.

    Help, please.

    Thank you
    Roya

    Maybe you can remove or distrust 'problematic' certificates are part of the authorities and add it again. Please refer to this post.

  • So I can update my Oracle Java Applet plugin Development Kit 7, update 65, can you link me to the correct page of download of Oracle from your update of the Plugin page?

    When I accessed to periodically your Plugin Check and updates the web page in the past, I really appreciated that you connect to the right webpage updates of the Plugin of the seller when I clicked on the button update now red. "" This time, however, your Applet Java plug-in 'Update Now' button link I Oracle Java "Release Notes for updates to 7u65 ' rather than the usual download page. It seems rather unexpected for me, or any other user conscientious, to search for the appropriate file "JDK 7U65" download on the Oracle website.

    Thank you

    I usually use this page: http://www.java.com/en/download/testjava.jsp

    I hope that someone will fix the plugin check site.

  • When I use Firefox to display Oracle WebLogic EM, Firefox will not display the scroll bar on some pages. But Google Chrome.

    It is a problem specific to Oracle Web Logic EM.

    In our society, we use the logical Web as a basis for the application server.

    In the EM logic web server, users can use a Web Logic EM (EM is a portal to view processes on Web Logic application) to verify the data.

    I found when I use EM to check online XML, sometimes the page does not appear the scroll bar.

    If I use Google Chrome or Opera, and do the same thing, the page will display scroll bar.

    But I need Firefox because it is my main browser.

    How to overcome this issues?
    And how to prove?

    Hello, cor - el

    Please, please read this thread first:
    https://support.Mozilla.org/en-us/questions/976345

    I found there is that some people have the same problems.

    I check the data of the source code viewer, the data displayed are "pure XML.

    So my question is "pop-up windows display XML data in Firefox.

    I searched the KB and found an expert suggests a whole 'dom.disable_window_open_feature.scrollbars', 'true '.

    This solution not solve my problem.

    And thank you once again, cor - el.

    I can give up google chrome forever.

  • How will I know if Java is installed/enabled in the Firefox browser on my Linux system? I went to the Oracle/Java test page and it does not have Java installed.

    I see that Javascript is enabled. Is javascript and java, the same thing?

    To avoid confusion:

    Note that you need the Web-IcedTea Plugin installed and it is a different implementation of Java as the Oracle's Java plugin (formerly Sun), while the Oracle does not detect this plugin.

  • I have a macbook pro 10.11.2, I would use netbeans/eclipse/oracle/mysql, which I can't... so is an alternative to my problem or advice on what he should do.

    I have a macbook pro(10.11.2/2.7GHz/8GB(RAM)/256GB), I would use netbeans/eclipse/oracle/mysql, which I can't... so is an alternative to my problem or advice on what he should do.

    I installed netbeans three times, but everytime I open the app I can't find the java section that comes with the installation package.

    You should consult with manufacturers of these applications of tierce partie for help on the installation and execution of their products.

  • incompatibility of Oracle with the latest version. How can I download patch # 12877995

    I tried to enter a Web site today and I was told that my browser is not compatible with Oracle presentation programs. I googled this and told me that the new version is not and my options were to uninstall and reinstall an older version of firefox, or there may be a patch available at oralcle. I signed up with Oracle, but can not find patch and you must have a certain number of work to ask a question. I can not find a way to get a number of work and do not want to uninstall firefox lest I lose bookmarks and passwords. Any suggestions?

    Patch 12877995 currently only run Linux, bookmark this page, if she releases maybe they'll write it on the updates section

  • How to install the Oracle database on mac?

    Can someone send the procedure step by step to install the database oracle on mac

    Sorry, Oracle DB is not an Apple product, go to their forum to get advice.

  • How to install oracle on mac?

    I installed the next step in virtual machine to install oracle please someone help me I am a student and the teacher requirement is to install the oracle software is required for the Conference otherwise you will not sit in DB Conference Monday.

    Hello! First Oracle is a company, then perhaps you are referring to a specific software made by them?

    If its Java you do not need to put a virtual machine, it works fine on a Mac, and the installation process its fairly simple. What program or DK you trying to install?

Maybe you are looking for

  • &gt; "&lt; account icloud"

    My father has icould account but now when it has been updated to 9.3 then to step active iphone because he forgot his account vaissaille the answer to security issues... tell me what shall we do now? put 5 s for recycling may be P/s: my father try to

  • Satellite Pro L500-11V memory configuration

    Looking to buy, but the memory configuration is confusing. Care say 2 total slots with 1 free slot but already installed 1024Mo & 2048Mb. Card mother 1024Mo is mounted?

  • T400 card reader?

    The order form called a card reader 4 in 1 for the PC Card slot, but it seems that it only takes SD cards. Does anyone know the story on this? Thank you.

  • I need assistance with Outlook Express

    I need assistance with my outlook express. Please

  • Replace windows 7 with XP on a Sony Vaio

    Have 2 PC Sony Vaio.  One with another XP with Windows 7. You want to load XP on more recent (June 2011) computer instead of windows 7. Cannot go back to dealer to the United Kingdom where we bought it because we are long term on a sailboat to the Pa