若需要使用到Mutil Thread 就必須利用JVM,
將任務丟給Java並繼續執行下段Statment。
本次的範例為:輸入指定的隊伍人數,JVM會自動產出隊伍成員,且回傳整支隊伍。
Oracle Function :
CREATE OR REPLACE FUNCTION CreatTeam(Num IN NUMBER) RETURN TEAMWITHPLAYER AS tempNum Number; BEGIN FOR i IN 1..Num loop SELECT ROUND(DBMS_RANDOM.VALUE(20,30))into tempNum FROM DUAL; --addPlayer(姓名、地址、年齡)都採Random輸出 AddPlayerToTeam.addPlayer('Name A'||i ,'Taipei No.'||i*10,tempNum); end loop; RETURN AddPlayerToTeam.getAll(); END;
上段程式碼為主程式,藉由輸入的Num數產生所成員數目。
最後再傳回整個Team的資料。
Oracle Package
CREATE OR REPLACE PACKAGE AddPlayerToTeam IS Procedure addPlayer( NameStr IN VARCHAR2 , AddrStr IN VARCHAR2 , AgeStr IN VARCHAR2 ); Function getAll Return TEAMWITHPLAYER; End AddPlayerToTeam; CREATE OR REPLACE PACKAGE BODY AddPlayerToTeam IS Procedure addPlayer( NameStr IN VARCHAR2 , AddrStr IN VARCHAR2 , AgeStr IN VARCHAR2 ) as language java name 'Kunde.Test.Java.AddPlayerToTeam.addString(java.lang.String,java.lang.String,java.lang.String)'; Function getAll Return TEAMWITHPLAYER as language java name 'Kunde.Test.Java.AddPlayerToTeam.getLog() return oracle.sql.ARRAY'; End AddPlayerToTeam;