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
- 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
iCOL2
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
aniCOL2
etc, najprostszym sposobem uzyskania dostępu do tych właściwości jest użyciegetVar
, co spowoduje zwrócenie wartości dla danej nazwy z odwzorowania (lubVarList
):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
iCOL2
to nazwy kolumn zwróconego zestawu wynikowego. - 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