問題1:
自己寫一個包來調用:
CREATE OR REPLACE PACKAGE Random AS
PROCEDURE ChangeSeed(p_NewSeed IN NUMBER);
-- Returns a random integer between 1 and 32767.
FUNCTION Rand RETURN NUMBER;
PROCEDURE GetRand(p_RandomNumber OUT NUMBER);
FUNCTION RandMax(p_MaxVal IN NUMBER) RETURN NUMBER;
PROCEDURE GetRandMax(p_RandomNumber OUT NUMBER,
p_MaxVal IN NUMBER);
END Random;
/
CREATE OR REPLACE PACKAGE BODY Random AS
v_Multiplier CONSTANT NUMBER := 22695477;
v_Increment CONSTANT NUMBER := 1;
v_Seed number := 1;
PROCEDURE ChangeSeed(p_NewSeed IN NUMBER) IS
begin
v_Seed := p_NewSeed;
END ChangeSeed;
FUNCTION Rand RETURN NUMBER IS
begin
v_Seed := MOD(v_Multiplier * v_Seed + v_Increment,
(2 ** 32));
RETURN BITAND(v_Seed/(2 ** 16), 32767);
END Rand;
PROCEDURE GetRand(p_RandomNumber OUT NUMBER) IS
begin
p_RandomNumber := Rand;
END GetRand;
FUNCTION RandMax(p_MaxVal IN NUMBER) RETURN NUMBER IS
begin
RETURN MOD(Rand, p_MaxVal) + 1;
END RandMax;
PROCEDURE GetRandMax(p_RandomNumber OUT NUMBER,
p_MaxVal IN NUMBER) IS
begin
p_RandomNumber := RandMax(p_MaxVal);
END GetRandMax;
----------------------------------------------------------
問題2:
用數組作輸入輸出參數﹐可以變通一下﹐先建一個TYPE
CREATE TYPE EXAM AS OBJECT (
aaa NUMBER(4),
bbb NUMBER(4),
ccc NUMBER(4)
);
存儲過程中﹕
CREATE OR REPLACE PROCEDURE CheckOut(
A IN NUMBER,
B IN EXAM) AS
begin
DBMS_OUTPUT.PUT_LINE(TO_CHAR(EXAM.AAA));
end;
------------------------------------------------------------
問題3:
在Oracle的SP中一下返回一個數據集可能不行﹐因為在Oracle的SP中不
可以寫SELECT xxx FROM xxx 只能用SELECT INTO 給參數的