ORA-01489 sys_connect_by_path and previous solution does not

Hi all.

Oracle version:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
"CORE 11.2.0.1.0 Production."
AMT for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

I need to get directions in a card and the associated amount long distances to another.
map
--     9
  F ----------E
  | \         |
  |  \2       |6
  |   \   11  |
14|   C-------D
  |  / \10   /
  | /9  \   /15
  |/     \ /
  A-------B
     7
I have a query that gets the roads properly.
WITH distances AS
(
     SELECT 'A' n1, 'B' n2, 7 d FROM DUAL UNION
     SELECT 'A' n1, 'C' n2, 9 d FROM DUAL UNION
     SELECT 'A' n1, 'F' n2, 14 d FROM DUAL UNION
     SELECT 'B' n1, 'D' n2, 15 d FROM DUAL UNION
     SELECT 'B' n1, 'C' n2, 10 d FROM DUAL UNION
     SELECT 'C' n1, 'D' n2, 11 d FROM DUAL UNION
     SELECT 'C' n1, 'F' n2, 2 d FROM DUAL UNION
     SELECT 'D' n1, 'E' n2, 6 d FROM DUAL UNION
     SELECT 'F' n1, 'E' n2, 9 d FROM DUAL
)
SELECT
     'A'||sys_connect_by_path(n2,'-') path,
     SUBSTR(sys_connect_by_path(d,'+'),2) sum_dist
FROM distances
START WITH n1='A'
CONNECT BY NOCYCLE PRIOR n2=n1;

A-B          7
A-B-C          7+10
A-B-C-D          7+10+11
A-B-C-D-E     7+10+11+6
A-B-C-F          7+10+2
A-B-C-F-E     7+10+2+9
A-B-D          7+15
A-B-D-E          7+15+6
A-C          9
A-C-D          9+11
A-C-D-E          9+11+6
A-C-F          9+2
A-C-F-E          9+2+9
A-F          14
A-F-E          14+9
The problem is when there is a lot of knots, I get an ORA-01489: result of concatenating string is too long.

I followed this link.

SYS_CONNECT_BY_PATH & to_CLOB

I built the package specified but apparently is combining elements.

If it is called only once.
WITH distances AS
(
     SELECT 'A' n1, 'B' n2, 7 d FROM DUAL UNION
     SELECT 'A' n1, 'C' n2, 9 d FROM DUAL UNION
     SELECT 'A' n1, 'F' n2, 14 d FROM DUAL UNION
     SELECT 'B' n1, 'D' n2, 15 d FROM DUAL UNION
     SELECT 'B' n1, 'C' n2, 10 d FROM DUAL UNION
     SELECT 'C' n1, 'D' n2, 11 d FROM DUAL UNION
     SELECT 'C' n1, 'F' n2, 2 d FROM DUAL UNION
     SELECT 'D' n1, 'E' n2, 6 d FROM DUAL UNION
     SELECT 'F' n1, 'E' n2, 9 d FROM DUAL
)
SELECT
     'A'||'-'||hierarchy.branch(LEVEL,n2,'-') path
FROM distances
START WITH n1='A'
CONNECT BY NOCYCLE PRIOR n2=n1;

A-B
A-B-C
A-B-C-D
A-B-C-D-E
A-B-C-F
A-B-C-F-E
A-B-D
A-B-D-E
A-C
A-C-D
A-C-D-E
A-C-F
A-C-F-E
A-F
But if I call it twice in the same query...
WITH distances AS
(
     SELECT 'A' n1, 'B' n2, 7 d FROM DUAL UNION
     SELECT 'A' n1, 'C' n2, 9 d FROM DUAL UNION
     SELECT 'A' n1, 'F' n2, 14 d FROM DUAL UNION
     SELECT 'B' n1, 'D' n2, 15 d FROM DUAL UNION
     SELECT 'B' n1, 'C' n2, 10 d FROM DUAL UNION
     SELECT 'C' n1, 'D' n2, 11 d FROM DUAL UNION
     SELECT 'C' n1, 'F' n2, 2 d FROM DUAL UNION
     SELECT 'D' n1, 'E' n2, 6 d FROM DUAL UNION
     SELECT 'F' n1, 'E' n2, 9 d FROM DUAL
)
SELECT
     'A'||SUBSTR(hierarchy.branch(LEVEL,n2,'-'),2) path,
     hierarchy.branch(LEVEL,d,'+') sum_dist
FROM distances
START WITH n1='A'
CONNECT BY NOCYCLE PRIOR n2=n1;

A          7
A-C          7+10
A-10-D          7+10+11
A-10-11-E     7+10+11+6
A-10-F          7+10+2
A-10-2-E     7+10+2+9
A-D          7+15
A-15-E          7+15+6
A          9
A-D          9+11
A-11-E          9+11+6
A-F          9+2
A-2-E          9+2+9
As you can see, is to combine the node elements (A-10-11-E) - node distance - distance-

Do I have to create separate functions in the package, one per column?, or is there another way to solve this problem?, or better yet, another way to solve the original problem (ORA-01489)

Thank you very much.

Kind regards.

Package (by Solomon Yakobson) code:
CREATE OR REPLACE
  PACKAGE Hierarchy
    IS
        TYPE BranchTableVarchar2Type IS TABLE OF VARCHAR2(4000)
          INDEX BY BINARY_INTEGER;
        BranchTableVarchar2 BranchTableVarchar2Type;
        TYPE BranchTableClobType IS TABLE OF CLOB
          INDEX BY BINARY_INTEGER;
        BranchTableClob BranchTableClobType;
        FUNCTION Branch(
                        p_Level          IN NUMBER,
                        p_Value          IN VARCHAR2,
                        p_Delimiter      IN VARCHAR2 DEFAULT CHR(0)
                       )
          RETURN VARCHAR2;
        PRAGMA RESTRICT_REFERENCES(Branch,WNDS);
        FUNCTION Branch(
                        p_Level          IN NUMBER,
                        p_Value          IN CLOB,
                        p_Delimiter      IN VARCHAR2 DEFAULT CHR(0)
                       )
          RETURN CLOB;
        PRAGMA RESTRICT_REFERENCES(Branch,WNDS);
END Hierarchy;
/ 
CREATE OR REPLACE
  PACKAGE BODY Hierarchy
    IS
        ReturnValueVarchar2 VARCHAR2(4000);
        ReturnValueClob     CLOB;
    FUNCTION Branch(
                    p_Level        IN NUMBER,
                    p_Value        IN VARCHAR2,
                    p_Delimiter    IN VARCHAR2 DEFAULT CHR(0)
                   )
      RETURN VARCHAR2
      IS
      BEGIN
          BranchTableVarchar2(p_Level) := p_Value;
          ReturnValueVarchar2          := p_Value;
          FOR I IN REVERSE 1..p_Level - 1 LOOP
            ReturnValueVarchar2 := BranchTableVarchar2(I)|| p_Delimiter || ReturnValueVarchar2;
          END LOOP;
          RETURN ReturnValueVarchar2;
    END Branch;
    FUNCTION Branch(
                    p_Level        IN NUMBER,
                    p_Value        IN CLOB,
                    p_Delimiter    IN VARCHAR2 DEFAULT CHR(0)
                   )
      RETURN CLOB
      IS
      BEGIN
          BranchTableClob(p_Level) := p_Value;
          ReturnValueClob          := p_Value;
          FOR I IN REVERSE 1..p_Level - 1 LOOP
            ReturnValueClob := BranchTableClob(I)|| p_Delimiter || ReturnValueClob;
          END LOOP;
          RETURN ReturnValueClob;
    END Branch;
END Hierarchy;
/
Published by: sKr on 08-mar-2012 17:29
Added package code

Hello

sKr wrote:
Hi all.

Oracle version:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
"CORE 11.2.0.1.0 Production."
AMT for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

I need to get directions in a card and the associated amount long distances to another.

map
--     9
F ----------E
| \         |
|  \2       |6
|   \   11  |
14|   C-------D
|  / \10   /
| /9  \   /15
|/     \ /
A-------B
7

...

I wish we could mark questions as 'Useful' or 'Correct '. You get 10 points for sure.

Do I have to create separate functions in the package, one per column.

You need to separate the functions. A user-defined function should be enough, just like a built-in version of SYS_CONNECT_BY_PATH is sufficient. All that should be stored in their own country, he knows that he needs to keep a separate copy for each argument to which you call it with. The problem with the package, which had been initially posted, is that there is only a single BranchTableVarchar2 of internal variables. Instead of a variable, an array of similar variables and add an optional argument to the funtion branch to tell him which item in this table to use.

CREATE OR REPLACE
  PACKAGE Hierarchy
    IS
        TYPE BranchTableVarchar2Type IS TABLE OF VARCHAR2(4000)
          INDEX BY BINARY_INTEGER;
        BranchTableVarchar2 BranchTableVarchar2Type;

     TYPE VList     IS TABLE OF BranchTableVarchar2Type          -- ***  NEW  ***
       INDEX BY     BINARY_INTEGER;                         -- ***  NEW  ***
     vl     VList;                                      -- ***  NEW  ***

        TYPE BranchTableClobType IS TABLE OF CLOB
          INDEX BY BINARY_INTEGER;
        BranchTableClob BranchTableClobType;

        FUNCTION Branch(
                        p_Level          IN NUMBER,
                        p_Value          IN VARCHAR2,
                        p_Delimiter      IN VARCHAR2     DEFAULT CHR(0),
               p_PathNum      IN PLS_INTEGER     DEFAULT     1     -- ***  NEW  ***
                       )
          RETURN VARCHAR2;
        PRAGMA RESTRICT_REFERENCES(Branch,WNDS);

        FUNCTION Branch(
                        p_Level          IN NUMBER,
                        p_Value          IN CLOB,
                        p_Delimiter      IN VARCHAR2 DEFAULT CHR(0)
                       )
          RETURN CLOB;
        PRAGMA RESTRICT_REFERENCES(Branch,WNDS);
END Hierarchy;
/
SHOW ERRORS

PROMPT     ==========  FK BODY  ==========

CREATE OR REPLACE
  PACKAGE BODY Hierarchy
    IS
        ReturnValueVarchar2 VARCHAR2(4000);
        ReturnValueClob     CLOB;

    FUNCTION Branch(
                    p_Level        IN NUMBER,
                    p_Value        IN VARCHAR2,
                    p_Delimiter    IN VARCHAR2       DEFAULT CHR(0),
              p_PathNum        IN PLS_INTEGER DEFAULT 1     -- ***  NEW  ***
                   )
      RETURN VARCHAR2
      IS
      BEGIN
          vl (p_PathNum) (p_Level) := p_Value;               -- ***  CHANGED  ***
          ReturnValueVarchar2          := p_Value;
          FOR I IN REVERSE 1..p_Level - 1 LOOP
            ReturnValueVarchar2 := vl (p_PathNum) (I)          -- ***  CHANGED  ***
                         || p_Delimiter
                     || ReturnValueVarchar2;
          END LOOP;
          RETURN ReturnValueVarchar2;
    END Branch;

    FUNCTION Branch(
                    p_Level        IN NUMBER,
                    p_Value        IN CLOB,
                    p_Delimiter    IN VARCHAR2 DEFAULT CHR(0)
                   )
      RETURN CLOB
      IS
      BEGIN
          BranchTableClob(p_Level) := p_Value;
          ReturnValueClob          := p_Value;
          FOR I IN REVERSE 1..p_Level - 1 LOOP
            ReturnValueClob := BranchTableClob(I)|| p_Delimiter || ReturnValueClob;
          END LOOP;
          RETURN ReturnValueClob;
    END Branch;
END Hierarchy;
/
SHOW ERRORS

As you can see, I only changed the version of VARCHAR2. Let you change the CLOB as an exercise for you.

When you call branch, pass a unique number for each output column. If you do not explicitly give a default number is 0.
Here's your query modified to call it:

SELECT  'A' || SUBSTR ( hierarchy.branch ( LEVEL
                                       , n2
                          , '-'
                          )
                , 2
                )          AS path
,     hierarchy.branch ( LEVEL
                , d
                , '+'
                , 12
                )     AS sum_dist
FROM    distances
START WITH          n1 = 'A'
CONNECT BY NOCYCLE      PRIOR n2     = n1
;

Path, I called the branch with only 3 arguments, so that it uses vl (0) for internal storage for the path.
For sum_dist, I had to use a different integer. I couldn't decide if I should use 1 or 2, so I compromised and used 12. I could have used any integer, except 0.
Output:

PATH                           SUM_DIST
------------------------------ -----------------------------
A                              7
A-C                            7+10
A-C-D                          7+10+11
A-C-D-E                        7+10+11+6
A-C-F                          7+10+2
A-C-F-E                        7+10+2+9
A-D                            7+15
A-D-E                          7+15+6
A                              9
A-D                            9+11
A-D-E                          9+11+6
A-F                            9+2
A-F-E                          9+2+9
A                              14
A-E                            14+9

or is there another way to solve this problem?, or better yet, another way to solve the original problem (ORA-01489)

Given that you call a user-defined set, you might want to add other features to the package.
For starters, in addition to a function that returns a string like "7 + 10 + 11', it might be useful to have a string that maintains these numbers internally, but returns the value 7 + 10 + 11 = 28.
If you use this for problems when you want to find the less total path (or the highest total d, for that of importance, but for now, let's say you are only interested in the minimum), you might want a function that keeps track of the minimum total d met so far for each node. Whenever you find a different path to a node, the function can check if the total d is better than the previous best. If this isn't the case, it could return an indicator (kind of similar CONNECT_BY_ISCYCLE) which indicates not bore you with this path.

Tags: Database

Similar Questions

  • 1502 error previous solutions does not

    1502 error when you try to create exe. Previous versions of this code correctly. I tried different solutions found after search but none work. Application builder "set font.vi" current errors cannot build the exe with active debugging - exe a broken arrow. When I deselect the option 'Remove unused members of the libraries in the project' and build LV is 'lost' and can not find DSC controls, even after I point to the correct libraries (?). Thanks in advance.

    Under "Additional Exclusions", try to uncheck the definitions of type of disconnection and remove unused libraries project members.  Let me know if it helps.

  • "No preview available": there are several files that I need to be able to preview and search for text that Windows 7 (and previous Windows) does not.

    original title: "no preview available".

    There are fixes for older versions, but not Windows 7, I can find.  When I search the forums, the answers are pretty useless - along the lines of "well go on the forum of office" just because someone questioned the .doc files.  It is an old problem, old with MS and covered needs in a reasonable manner.

    Read this:

    No preview available for some files in the folder in Windows 7 and Vista Zip
    MRI http://www.Winhelponline.com/blog/no-Preview-available-certain-Files-zip-Folder-View-Windows-7-Vista/ !

  • Shortcuts "Next Page" and "Previous Page" does not?

    Acrobat Pro 9.4.5 the keyboard shortcut for "Next Page" is "Right arrow" and the keyboard shortcut for 'Previous Page' is 'left arrow '. On my system, these shortcuts work normally for the text of PDF files, but for PDF image only (that is, a PDF file including only digitized images) these shortcuts only 'push' a page of image slightly to the side. Everyone is faced with this problem?

    I think it's related to something else, namely the zoom level. If you see a zoom level, where the width of the page is more than your window (IE when there is a horizontal scroll bar at the bottom of the window), then the straight arrows will control this scroll bar rather than function as shortcuts next/previous page.

  • keyboard popping up during the call and previous button does not work...

    Why can't I write during a call? I tried other keyboards, but the result is the same...

    is there a solution?

    You have app smart key? If so, remove or disable the calls.

  • I'm unable to download lightroom 5 on my laptop.  I had a cat and their solution does not work.

    I want to call in a specialist.  What number to use.

    Hi wildman6654,

    Welcome to the community!

    The number is specific to the region, if you can say the exact error message and post a screenshot. Which will be useful or if you want to talk to someone to find the number here: http://www.adobe.com/company/contact.html?promoid=JOPDO

    Change your region of the lower left and go down the number.

    Thank you!

    Ankit

  • "Problem reports and Solutions" does not

    After scoring in my Windows Vista machine, I am bombarded with notifications "Problem reports and solution" does not. I tried to disable the service, but I still get notifications. I can't find PRS in the control panel. In the event viewer, I found the following:

    Error
    Log name: Application
    Source: Application error
    Event ID: 1000

    WerCon.exe application, version 6.0.6002.18005, time stamp 0x49e026db, module wercplsupport.dll, version 6.0.6000.16386, time stamp 0x4549d345, exception code 0xc000001d, offset error 0x000000000000ce84, 0xda0, failing application start 0x01cd140e4c7b7770 process id failed.

    I can't confirm or deny that usrename of the local administrator account has been changed. It is quite possible. I know that usernames on the pc have been changed to instead of creating new user accounts. I just can't confirm if one of these accounts was a local administrator.

    Any help would be greatly appreciated. It is a major pain in the back.

    SG

    Hello

    1. Your computer is connected to a domain?

    2. don't you make changes to the computer until the problem occurred?

    I suggest you to see link below and check if it helps.

    Windows Error Reporting and reports on problems and Solutions feature in Windows Vista: http://technet.microsoft.com/en-us/library/cc709644(v=ws.10).aspx

    Hope this information is useful.

  • I use a database program in a number of previous versions of windows and windows 7 does not allow the program to launch denial of service.

    Application of program compatibility does not start

    I use a database program in a number of previous versions of windows and windows 7 does not allow the program to launch denial of service.  What gives?

    If you have Windows 7 64 bit without BACK program can run because there is no 16-bit subsystem to run it.

    Try dosbox http://www.dosbox.com/. If that won't work your program, you'll need either a new database or run the BACK or on a 32-bit version of Windows in a virtual machine like VirtualBox https://www.virtualbox.org/.

  • ORA-28132: the MERGE syntax IN does not support security policy

    Hello

    With the help of Oracle 11 g R2.

    I have the following problem:

    If the user attempts to perform a MERGE INTO statement on a table (T1), it receives the error ORA-28132: The MERGE IN syntax does not support security policy.

    Is there a way I can solve this problem by giving the user more rights on this specific table, T1? Or I need to rewrite the SQL code using UPDATE and INSERT instead MERGER?

    I can't grant POLICE ACCESS TAX-FREE, it would be too powerful privilege...

    Please advise,

    M.R.

    You may need to recreate the political VPD:

    Note:

    In previous versions of Oracle database, when you created a strategy Oracle virtual private database on an application that included the MERGE INTO statement, the MERGE INTO declaration could be avoided with a ORA-28132: Merge into syntax does not support security policies error, due to the presence of the virtual private database policy. From Oracle Database 11 g Release 2 (11.2.0.2), you can create policies on applications that include MERGE INTO operations. To do this, in the DBMS_RLS . ADD_POLICY statement_types parameter, include the INSERT , UPDATE , and DELETE statements, or simply omit statement_types setting altogether. Refer to the Oracle Database Security Guide for more information on the application of the strategies on specific types of SQL statement.

    FUSION

  • cannot access iPad previous owner does not remember the account of what I can do

    I can't access

    Hey there gut123!

    Welcome to the communities of Apple Support! According to the title, you have an iPad that is in the lock of the Activation. This occurs when the previous owner does not sign off iCloud this device before passing along another person. You are on the right track and I definitely want you to have access to such a wonderful device. In this case, you do not want to continue to work with the former owner as they are the one who has the ultimate ability to regain control of the account. Here is an article that you can share with them that will help them locate important once again and remove it from your device:

    Turn off find my iPhone Activation Lock

    If you forgot your Apple ID

    Provide these links to the former owner, so they can get the help they need to re-have access to iCloud.

    Have a phenomenal day!

  • Remote control does not work, and the load does not appear on Apple TV

    Hello

    I just returned from vacation and my remote seems has stopped working.   Naturally, my first assumption was that the charge was simply exhausted.

    Apparently that was the case.   He seems to have just died.

    I did pay for more than two hours and it still does not appear under devices Apple TV.

    My Apple TV 4 works very well because I use the remote control of my phone to navigate through it.

    If I understand correctly what I look at you, it seems that the remote control is same not synchronized or recognized by Apple TV more.

    Any suggestions on how to fix this?

    A reset is complete? Restart... no change.

    Thank you

    Bob

    1. Have you tried pressing the menu and the button for a few seconds while it now an inch or two away from the Apple TV, if successful, you should see a message on the screen saying the remote was paired.
    2. If you have an older remote from a previous model MacBook or Apple TV, you can use to restore the Apple TV, which, in many cases, has been sufficient to reactivate the remote Siri. You must complete all upward to undertake a restoration.
    3. If you have a USB cable - C you can try to restore by connecting it to iTunes on a computer.
    4. If you have tried all of these steps, don't have a distance sooner or a USB - C cable or their use is too inconvenient, return it to the store where purchased for a replacement, or to couple for you.
  • I need to know how to remove the most recent version of Firefox. I JUST downloaded tonight and my computer does not have this edit bar little to work with, so I can download the reader good Adobe and my internet was screwed up ever since I downlo

    I need to know how to remove the most recent version of Firefox. I JUST downloaded tonight and my computer does not have this edit bar little to work with, so I can download the reader good Adobe and my internet was screwed up, since I downloaded the new version of Firefox. I want just the old version of this back because I can't download the Adobe stuff which is necessary to protect my computer against hackers apparently not. It would have been nice to know he had a problem with the new update of Firefox BEFORE I downloaded it. I have Vista, which is usually a problem with Adobe and Firefox. I don't seem to be able to run a lot of Adobe at all on my computer because of the Vista.

    This has happened

    Each time Firefox opened

    http://support.Mozilla.com/en-us/KB/installing+a+previous+version+of+Firefox

  • Satellite L305D-S5895 - keys to functions and the wifi does not work with Win XP

    Hello

    first sorry for my English

    I bought a Toshiba Satellite l305d s5895, with Windows XP, I need a software, but the function keys does not work.
    So I need a driver, but I can't, and wireless internet does not work.

    > Where could it find special XP BIOS?
    In my opinion, there is problem because most threads here are on the European laptop models. then come to question United States. Toshiba Europe and Toshiba U.S. do not work together and each of them is responsible for own models and provide support for specific country notebooks models.

    For most models, so here in Europe Toshiba has offered two BIOS. We were already on the delivered Vista laptops. The Toshiba page download available BIOS for Windows XP Home edition. in most cases, it was version 5. XX and this BIOS was designed to support public services and specific tools of Toshiba. For example, all the FN key features was only available with this BIOS WXP.

    So if any of you have laptop model US they would see how the solution with Toshiba U.S. or US forum under http://community.compuserve.com/n/pfx/forum.aspx?webtag=ws-laptop&redirCnt=1

    Bye and good luck!

  • I just 6 s phone and when I try to buy stuff, it says "enter a password for santosjim@***". It's not my apple ID and my password does not work

    I just 6 s phone and when I try to buy stuff, it says "enter a password for santosjim@***". It's not my apple ID and my password does not work

    The phone that you have just bought is not new. It is locked to its previous owner.

  • a pc that is sharing the printer and another pc does not accept the same network printer on xp pro sp3

    a pc that is sharing the printer and another pc does not accept the same network printer on xp pro sp3
    What is the solution?

    Check out these links

    http://TechNet.Microsoft.com/en-us/library/bb457001.aspx

    http://UIs.Georgetown.edu/software/documentation/WinXP/WinXP.network.printer.html

Maybe you are looking for