Function to get the path using a parent-child relationship

Hello,
I have a table which uses parent-child relationship to store the options available. I need a function to give me the full path given the id of a particular option.
I have two different functions. One of them uses the Oracle built in function and the other uses simple queries with a loop.The code of the functions are given below.
Now, the problem is with their "performance". The difference in their performance is significant. The function using the Oracle function takes more than 2 hours to run a query whereas the other function takes less than 2 minutes.
I am having trouble trusting the other function. No matter how many tests I perform on the output of both the functions, it always comes out to be the same.
Any thoughts to help me understand this ??
Function 1
=====================
FUNCTION Gettree (opt_id IN NUMBER,i_app_id IN NUMBER)
RETURN VARCHAR2
IS
path VARCHAR2(32767);
application_no NUMBER;
BEGIN
SELECT ABC.APP_OPT_ID INTO application_no FROM ABC
WHERE ABC.APP_ID = i_app_id AND ABC.PARENT_ID IS NULL;
SELECT LPAD(' ', 2*LEVEL-1)||SYS_CONNECT_BY_PATH(app_opt_name, '=>') "Path" INTO path
FROM ABC
WHERE app_opt_id = opt_id
START WITH parent_id =application_no
CONNECT BY PRIOR app_opt_id =parent_id;
path := SUBSTR(path,INSTR(path,'>')+1,LENGTH(path));
RETURN path;
END Gettree ;
Function 2
======================
FUNCTION GetOptPath(opt_id NUMBER,app_id NUMBER)
RETURN VARCHAR2
IS
string VARCHAR2(900);
opt VARCHAR2(100);
pid NUMBER(38);
BEGIN
SELECT ABC.parent_id,ABC.app_opt_name INTO pid,string FROM ABC WHERE ABC.app_opt_id = opt_id;
IF pid IS NULL
THEN
RETURN 'root';
ELSIF pid IS NOT NULL
THEN
LOOP
SELECT ABC.app_opt_name,ABC.parent_id INTO opt, pid FROM ABC WHERE ABC.app_opt_id = pid;
EXIT WHEN pid IS NULL;
string := opt || '=>'|| string;
END LOOP;
RETURN string;
END IF;
END;

Hi,
user8653480 wrote:
Hello Frank,
The parameters taken by gettree & getoptpath are app_opt_id and app_id and both the functions return only one string i.e. the path of that particular option (app_opt_id) starting from its root and not all the descendants of that option/root node of that option.
So, does that mean that gettree first fetches all the descendants of the root node of the given option and then returns the required one ??Yes. It's a little like the situation where you need to meet with your co-worker Amy, so you send an e-mail to everyone in the department telling them to come to your office, and then, when they arrive, tell everyone except Amy that they can leave.
>
And if that is the case, then won't it be better to use the bottom-up approach to fetch the required path just for that particular option ?? 'coz my requirement is that only.. given an option_id get the full path starting from the root.Exactly!
I have used explain plan also for both the functions.. but since I did not know how to anlayze the output from plan_table so I just compared the value in the fields and they were exactly the same for both the queries.If you'd like help analyzing the plans, post them, as Centinul said.
I am attaching a sample data with the outputs of both the functions for the reference.
(tried attaching the file but could not find the option, so pasting the data here)
App_opt_ID     App_ID     Parent_ID     App_opt_name     "gettree(app_opt_id,app_id)"     "getoptpath(app_opt_id,app_id)"
1          1     NULL          application          NULL                    root
2          1     1          module1               module1                    module1
3          1     1          module2               module2                    module2
4          1     2          submod1               module1=>submod1          module1=>submod1
5          1     3          submod1               module2=>submod1          module2=>submod1
6          1     5          opt1               module2=>submod1=>opt1          module2=>submod1=>opt1
7          2     NULL          app2               NULL                    root
8          2     7          scr1               scr1                    scr1
9          2     8          opt1               scr1=>opt1               scr1=>opt1
10          2     7          scr2               scr2                    scr2Please help.The best solution is to do a bottom-up query, and write a function like reverse_path (described in my first message) to manipulate the string returned by SYS_CONNECT_BY_PATH. You seem to have all the PL/SQL skills needed for this.
Another approach is a revised form of gettree, like I posted earlier. Does it do what you want or not?
If you'd help, then post a little sample data in a form people can actually use, such as CREATE TABLE and INSERT statements. Post a few sets of parameters, and the results you need from each set, given the sample data posted.

Similar Messages

  • How to use GL Parent Child relationships in Discoverer?

    Subject: How to used GL Parent Child relationships in Discoverer?
    How to use GL Parent Child relationships in Discoverer?
    Please let me know how to incorporate the parent -child relation ships exsiting in GL Accouting flexfield Segments in Discoverer for drill downs? we have GL - BIS views installed.
    How to create the specific Parent -child relationship hierarchies in Discoverer from the FND_* tables?
    Please help.
    Thanks.
    KS.

    Hi,
    I'm also trying to implement this. If you have come any further in solving this any hints would be much appreciated...
    regards,
    AJ

  • Function to get the path without name of file

    Hello everyone!
    I'm using the function 'KD_GET_FILENAME_ON_F4', this function works very good but every time I choose a destination folder in the pop-up window it always asks me for a file name, but I need a function if it exist in SAP of course that only asks me for the destination folder and nothing else.
    I hope somebody could help me to find another function.
    Thanks for you time.

    Hi,
    Try the static method CL_GUI_FRONTEND_SERVICES=> DIRECTORY_BROWSE
    Thanks,
    Naren

  • Parent-Child Relationship between app

    Hi,
    I am trying to deploy 2 applications, which needs to have a parent-child relationship between them.
    One option is i should driectly change server.xml, and put parent tag in this Xml file and restart the container.
    Another option is i can use my Ant Target to invoke command line argument which uses admin.jar and which has parent attribute... so when i give the command to put parent-child relationship, the container gives the message that app2 has parent app1 but actually it doesnt put the required tag in server.xml and nor does it put the relationship in place.
    So any workaround for this... how can i put that relationship in place without modifying server.xml.
    We are running 9ias 9.0.2.3 on True64
    Thanks in advance

    Hi,
    Has anyone done sumthing like this before... even after trying everything i am still not able to do parent- child relationship between applications.
    Thanks & Regards

  • How to get the Path of the Current File using Import & Export File -Reg.

    Dear all,
    I have a mega (big) doubt. I have manually inserted the Figures from the figure folders. Now i need, fully automated. So How can I get the Figure path
    Example :
    PMString path = "E://development/Figures/";
    now i checked, How many subFolders is there in "path", get the All Subfolders and check to the Article Name.
    Example
    Article Name == subFolder name then get the Files from the SubFolders(E://development/Figures/ChapterF/*.eps files").
    now I paste the Document using to For Loop.
    Please any one can suggest me, How can We get the Path in SDK.
    Note:
    Should I have to create the relative path by myself?
    No method supplied in SDK to do this directly?
    Please I need a help of this Query as soon as posible.
    Thanks & Regards
    T.R.Harihara SudhaN

    http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/input_file.asp?frame=true
    When a file is uploaded, the file name is also submitted. The path of the file is available only to the machine within the Local Machine security zone. The value property returns only the file name to machines outside the Local Machine security zone. See About URL Security Zones for more information on security zones.
    i need to know on how to get the compelete path /directory of the filename
    using <input type="file"> tag You can't. Its a security thing.
    is there any other way to get an input file from a local host aside from <input type="file"> tag?No. Not using just html.
    You could always go into activex components, but thats different again.
    Cheers,
    evnafets

  • Use SQL function to get the original order number using the invoice number

    Hi All,
    wondering is someone can help me with this challenge I am having?  Often I need to return the original order numbers that created the resulting invoce.  This is a relatively simple seriese of joins in a query but I am wanting to simplify it using a SQL function that can be referenced each time easily from with in the SELECT statement.  the code i currently have is:
    Use SQL function to get the original order number using the invoice number
    CREATE FUNCTION dbo.fnOrdersThatMakeInvoice(@InvNum int)
    RETURNS nvarchar(200)
    AS
    BEGIN
    DECLARE @OrderList nvarchar(200)
    SET @OrderList = ''
    SELECT @OrderList = @OrderList + (cast(T6.DocNum AS nvarchar(10)) + ' ')
    FROM  OINV AS T1 INNER JOIN
          INV1 AS T2 ON T1.DocEntry = T2.DocEntry INNER JOIN
          DLN1 AS T4 ON T2.BaseEntry = T4.DocEntry AND T2.BaseLine = T4.LineNum INNER JOIN
          RDR1 AS T5 ON T4.BaseEntry = T5.DocEntry AND T4.BaseLine = T5.LineNum INNER JOIN
          ORDR AS T6 ON T5.DocEntry = T6.DocEntry
    WHERE T1.DocNum = @InvNum
    RETURN @OrderList 
    END
    it is run by the following query:
    Select T1.DocNum, dbo.fnOrdersThatMakeInvoice(T1.DocNum)
    From OINV T1
    Where T1.DocNum = 'your invoice number here'
    The issue is that this returns the order number for all of the lines in the invoice.  Only want to see the summary of the order numbers.  ie if 3 orders were used to make a 20 line inovice I only want to see the 3 order numbers retuned in the field.
    If this was a simple reporting SELECT query I would use SELECT DISTINCT.  But I can't do that.
    Any ideas?
    Thanks,
    Mike

    Thanks Gordon,
    I am trying to get away from the massive table access list everytime I write a query where I need to access the original order number of the invoice.  However, I have managed to solve my own problem with a GROUP BY statement!
    Others may be interested so, the code is this:
    CREATE FUNCTION dbo.fnOrdersThatMakeInvoice(@InvNum int)
    RETURNS nvarchar(200)
    AS
    BEGIN
    DECLARE @OrderList nvarchar(200)
    SET @OrderList = ''
    SELECT @OrderList = @OrderList + (cast(T6.DocNum AS nvarchar(10)) + ' ')
    FROM  OINV AS T1 INNER JOIN
          INV1 AS T2 ON T1.DocEntry = T2.DocEntry INNER JOIN
          DLN1 AS T4 ON T2.BaseEntry = T4.DocEntry AND T2.BaseLine = T4.LineNum INNER JOIN
          RDR1 AS T5 ON T4.BaseEntry = T5.DocEntry AND T4.BaseLine = T5.LineNum INNER JOIN
          ORDR AS T6 ON T5.DocEntry = T6.DocEntry
    WHERE T1.DocNum = @InvNum
    GROUP BY T6.DocNum
    RETURN @OrderList 
    END
    and to call it use this:
    Select T1.DocNum, dbo.fnOrdersThatMakeInvoice(T1.DocNum)
    From OINV T1
    Where T1.DocNum = 'your invoice number'

  • How 2 get the path of a file Using jsp

    how 2 get the path of a file Using jsp
    i have tried getPath...but i'm geting the error
    The method getPath(String) is undefined for the type HttpServletRequest
    any idea how 2 get the path of a file

    You need ServletContext#getRealPath().
    API documentation: http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)

  • Is there any function module to get the variables used in a query?

    Hi experts
    Please, do you know if is there any function module to get the variables used in a query?
    Thanks and regards
    Luis

    Hi Srini
    Yes, I have checked the tables but I need a function module
    Thanks anyway!
    Luis

  • How to get the path of  my webapp?

    example mywebapp: " http://xxxx.com/test/index.html"
    The "test" is the path of my webapp,is there any function use to get the path in the HttpServlet?
    thanks!

    request.getContextPath();

  • How to get the path of the selected Jtree node for deletion purpose

    I had one Jtree which show the file structure of the system now i want to get the functionality like when i right click on the node , it should be delete and the file also deleted from my system, for that how can i get the path of that component
    i had used
    TreePath path = tree.getPathForLocation(loc.x, loc.y);
    but it gives the array of objects as (from sop)=> [My Computer, C:\, C:\ANT_HOME, C:\ANT_HOME\lib, C:\ANT_HOME\lib\ant-1.7.0.pom.md5]
    i want its last path element how can i get it ?

    Call getLastSelectedPathComponent() on the tree.

  • F4 Help to get the path for a File source directory

    There are numerous function modules for browsing a particular file in desktop and getting the file path (including the fine name)  , like F4_FILENAME , KD_GET_FILENAME_ON_F4 , WS_FILENAME_GET etc. But can anyone tell me how to fetch only the directory path to the field were the F4 help is given. Actually the filename has to come in some other field in the selection screen. Is there separate funtion modules for these OR will changing parameters in the above function modules work?
    Pls Help....
    Also are there function modules for providing F4 help for getting the path to a file in application directory?

    Try this method CL_GUI_FRONTEND_SERVICES.
    It is a Global CLASS which is having different methods for different purposes
    see the documentation of it and use the methods of it
    see
    CL CL_GUI_FRONTEND_SERVICES
    Short Text
    Frontend Services
    Functionality
    The class CL_GUI_FRONTEND_SERVICES contains static methods for the following areas:
    File functions
    Directory functions
    Registry
    Environment
    Write to / read from clipboard
    Upload / download files
    Execute programs / open documents
    Query functions, such as Windows directory, Windows version, and so on
    Standard dialogs (open, save, directory selection)
    Example
    Determine the temp directory on your PC:
    DATA: TEMP_DIR TYPE STRING.
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>GET_TEMP_DIRECTORY
    CHANGING
    TEMP_DIR = TEMP_DIR
    EXCEPTIONS
    CNTL_ERROR = 1
    ERROR_NO_GUI = 2.
    IF SY-SUBRC 0.
    Error handling
    ENDIF.
    flush to send previous call to frontend
    CALL METHOD CL_GUI_CFW=>FLUSH
    EXCEPTIONS
    CNTL_SYSTEM_ERROR = 1
    CNTL_ERROR = 2
    OTHERS = 3.
    IF SY-SUBRC 0.
    Error handling
    ENDIF.
    WRITE: / 'Temporary directory is:', TEMP_DIR.
    Notes
    The class CL_GUI_FRONTEND_SERVICES is based on the Control Framework. See the documentation for more information, in particular on CL_GUI_CFW=>FLUSH which must be called after many CL_GUI_FRONTEND_SERVICES methods.
    Migration Information
    The old file transfer model was based on function modules of the function group GRAP. The old features have been replaced by the class CL_GUI_FRONTEND_SERVICES. The following list contains the old function modules (italic) and the new methods (bold) that replace them:
    CLPB_EXPORT
    CLIPBOARD_EXPORT
    CLPB_IMPORT
    CLIPBOARD_IMPORT
    DOWNLOAD
    GUI_DOWNLOAD, dialog replaced by FILE_SAVE_DIALOG
    PROFILE_GET
    No replacement, use REGISTRY_* methods instead
    PROFILE_SET
    No replacement, use REGISTRY_* methods instead
    REGISTRY_GET
    REGISTRY_GET_VALUE, REGISTRY_GET_DWORD_VALUE
    REGISTRY_SET
    REGISTRY_SET_VALUE, REGISTRY_SET_DWORD_VALUE
    UPLOAD
    GUI_UPLOAD, dialog replaced by FILE_OPEN_DIALOG
    WS_DDE
    Obsolete: This function is no longer supported.
    SET_DOWNLOAD_AUTHORITY
    Obsolete: This function is no longer supported.
    WS_DOWNLOAD
    GUI_DOWNLOAD
    WS_DOWNLOAD_WAN
    Obsolete: This function is no longer supported.
    WS_EXCEL
    Obsolete: This function is no longer supported.
    WS_EXECUTE
    EXECUTE
    WS_FILENAME_GET
    FILE_SAVE_DIALOG, FILE_OPEN_DIALOG
    WS_FILE_ATTRIB
    FILE_SET_ATTRIBUTES, FILE_GET_ATTRIBUTES
    WS_FILE_COPY
    FILE_COPY
    WS_FILE_DELETE
    FILE_DELETE
    WS_MSG
    Obsolete: This function is no longer supported.
    WS_QUERY
    CD (current directory)
    DIRECTORY_GET_CURRENT
    EN (read/write environment)
    ENVIRONMENT_GET_VARIABLE
    ENVIRONMENT_SET_VARIABLE
    FL (determine file length)
    FILE_GET_SIZE
    FE (check if file exists)
    FILE_EXIST
    DE (check if directory exists)
    DIRECTORY_EXIST
    WS (determine Windows system)
    GET_PLATFORM
    OS (operating system)
    GET_PLATFORM
    WS_UPLDL_PATH
    Obsolete: This function is no longer supported.
    WS_UPLOAD
    GUI_UPLOAD
    WS_VOLUME_GET
    Obsolete: This function is no longer supported.
    Reward points if useful.

  • How can i get the path to config folder placed inside the jar file?

    Hi i have developed an RCP application using eclipse.
    In my application config directory is there.
    When i export my RCP application as JNLP Project the jar file is created which contains config folder inside it.
    When i download the application using java web start , how can i get the path to config folder placed inside the jar file?
    Will the config folder exists in local cache in my system?
    Help needed.
    -Deepak

    -- This works in CS6:
    tell application "Adobe InDesign CS6"
      set myDocument to active document
      set selectedRectangles to selection of myDocument
      set theGraphicsLink to file path of item link of (graphic 1 of (item 1 of selectedRectangles))
    --> "Macintosh HD:folder/folder/filename.tif"
    end tell

  • How to get the path of local folder in native services in windows phone 8.1 ?

    I used to get the path of local folder path in managed code by following -Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;But now I need to get the local folder path in native services .Please help me out ?

    What do you mean by "native services"? Windows.ApplicationData.Lo alFolder is the way to access the local folder.

  • To Get The Path of A File

    hi
    i wanted to get the path of the file.i just need to get the path not the file.i wanted to do using swing.may be filechooser or tree. but i need to know how could i get tht if i know the exampl for this it would be useful for me ..

    i need it in a way that like in windows explore.. so tht if i get the path of it i can use that in another class file.
    anyway i am looking out in File class also.

  • How to get the path of the image stored in DMS

    Hi everyone..
    My question is that I have attached an image with an order through transaction jha2n..
    Now my requirement is to get the image in report..
    I know the Logical id in ISM_l_ord class and physical id in ISM_P_Ord class.
    I know that link between image and order is in SKWG_BREL.
    But i am not able to get the path so that i can show the image in docking control.
    pls help to retrive the path of the image stored...
    Thanks
    Pooja

    EpicMaster wrote:Now the problem is when I run the application through the .jar file in the dist/ directory the images simply wont load...
    ..lblProduct.setIcon(new ImageIcon("Resources.zip/res/Product.png"));
    Now the problem is when I Build&Clean the whole project which creates a /dist directory containing the complied and execulatble .Jar file for the application AND a folder called "lib" which contains the Resource.Zip folderThe String based constructor to ImageIcon presumes the String represents a File path. File objects do not work with resources inside Jar or Zip archives, for those, you need an URL. Gain the URL using something like..
    URL urlToImage = this.getClass().getResource("/res/Product.png");

Maybe you are looking for

  • Boot Camp 2.1 will not install in Windows 7 beta 1

    I have installed the 32-bit Windows 7 beta 1 on my MacBook using Boot Camp 2.0. I cannot for the life of me get the 2.1 update installed. After downloading in Windows, I run the setup and it asks me if it's okay to allow that file to make changes to

  • URGENT - PLEASE READ MY MIND AND GIVE ME THE CODE

    I AM DOING AN URGENT PROJECT AND I NEED SOME CODE. PLEASE PROVIDE THE CODE WITHOUT DELAY. I AM SENDING DETAILS OUT ON MIND FREQUENCY 42 GigaHz at 10 GigaWatt. STOP WHATEVER ELSE YOU ARE DOING AND SEND ME THE CODE NOW!

  • Prevent row in ADF BC Row from being deleted

    I'm using ADF/BC for my data; I'm attempting to prevent a row from being deleted based upon some condition. I'd like to do this in the Impl classes of the EO or VO for the given row but I'm not sure where this should be done or if it's even possible

  • Seperating presentation from 'business logic'

    I have a program for keeping track of games played and keeping a league table. However, I currently think the way I do the output of the league table using the toString() function shown later is a pretty poor way to do it. OK, let's be honest, it suc

  • Font Folio 11 - OTF printing issues

    I need help with a HP LaserJet 5200 (tabloid size laser printer) and OTF fonts. Ever since i switched to .otf fonts, I am having issues printing helvetica LT STD or any of the LT STD fonts for that matter. the fonts are all activated using Suitcase F