Przykłady procedury składowanej Oracle zwracającej tablicę

Poniższy przykład przedstawia sposób obsługi tablicy zwróconej przez procedurę składowaną.

Procedura

  1. W tym przykładzie nazwa typu danych tablicowych w procedurze Oracle to CUST.
    CallStoredProcedure("ORA_01", "GetCustomersByLocation", Sp_Parameter);
    
    Log("The first row of the Customer  array is " + Sp_Parameter.Name.elements[0]);
    Log("The second row of the Customer  array is " + Sp_Parameter.Name.elements[1]);

    Aby uzyskać dostęp do poszczególnych kolumn w zwróconych wierszach, składnia stosowana w IPL i JavaScript jest inna.

    Przykład IPL

    CallStoredProcedure("ORA_01", "GetCustomersByLocation", Sp_Parameter);
    
    Log("The first row of the Customer  array is " + Sp_Parameter.Name.elements[0]);
    
    Log("The first column in the first row of the Customer array has value " + Sp_Parameter.Name.elements[0].COL1);
    Log("The second column in the first row of the Customer array has value " + Sp_Parameter.Name.elements[0].COL2);
    

    Gdzie COL1 i COL2 to nazwy kolumn zwróconego zestawu wynikowego.

    Przykład JS

    Ponieważ do właściwości obiektu użyto notacji z kropką w języku JavaScript, a klasa com.micromuse.response.dblayer.VarList nie ma pola instancji publicznej ani metody o nazwie COL1 ani COL2 etc, najprostszym sposobem uzyskania dostępu do tych właściwości jest użycie getVar, co spowoduje zwrócenie wartości dla danej nazwy z odwzorowania (lub VarList):

    CallStoredProcedure("ORA_01", "GetCustomersByLocation", Sp_Parameter);
    
    Log("The first row of the Customer  array is " + Sp_Parameter.Name.elements[0]);
    
    Log("The first column in the first row of the Customer array has value " + Sp_Parameter.Name.elements[0].getVar('COL1'));
    Log("The second column in the first row of the Customer array has value " + Sp_Parameter.Name.elements[0].getVar('COL2'));

    Gdzie COL1 i COL2 to nazwy kolumn zwróconego zestawu wynikowego.

  2. Inny Przykład

    Procedura składowana Oracle:

    CREATE OR REPLACE PROCEDURE p_retData (p_result OUT SYS_REFCURSOR)
    AS
    BEGIN
    OPEN p_result FOR
    SELECT OWNER, TABLE_NAME
    FROM all_tables;
    END;
    /

    Strategia skryptu IPL:

    Sp_Parameter=NewObject();
    Sp_Parameter.p_result=NewObject();
    CallStoredProcedure("ooo", "p_retData", Sp_Parameter);
    
    Log("The first row of the returned array is " + Sp_Parameter.p_result.elements[0]);
    
    Log("The owner in the first row of the Customer array is " + Sp_Parameter.p_result.elements[0].OWNER);
    Log("The table_name in the first row of the Customer array is " + Sp_Parameter.p_result.elements[0].TABLE_NAME);

    Dziennik strategii IPL:

    [runProcIPLOracleGood][pool-5-thread-662]Parser log: The first row of the returned array is (OWNER=SYS, TABLE_NAME=DUAL)
    [runProcIPLOracleGood][pool-5-thread-662]Parser log: The owner in the first row of the Customer array is SYS
    [runProcIPLOracleGood][pool-5-thread-662]Parser log: The table_name in the first row of the Customer array is SYSTEM_PRIVILEGE_MAP

    Strategia skryptu Java:

    Sp_Parameter=NewObject();
    Sp_Parameter.p_result=NewObject();
    CallStoredProcedure("ooo", "p_retData", Sp_Parameter);
    
    Log("The first row of the returned array is " + Sp_Parameter.p_result.elements[0]);
    
    Log("The owner in the first row of the Customer array is " + Sp_Parameter.p_result.elements[0].getVar('OWNER'));
    Log("The table_name in the first row of the Customer array is " + Sp_Parameter.p_result.elements[0].getVar('TABLE_NAME'));

    Dziennik strategii skryptu Java:

    [runProcJSOracleGood][pool-5-thread-662]Parser log: The first row of the returned array is (OWNER=SYS, TABLE_NAME=DUAL)
    [runProcJSOracleGood][pool-5-thread-662]Parser log: The owner in the first row of the Customer array is SYS
    [runProcJSOracleGood][pool-5-thread-662]Parser log: The table_name in the first row of the Customer  array is SYSTEM_PRIVILEGE_MAP