2
CREATE OR REPLACE TYPE TY_1 AS OBJECT
(
FN VARCHAR2(100),
SL NUMBER,
HD DATE
);
-- Example 1
CREATE OR REPLACE FUNCTION FN_RET_COL
RETURN TY_1
AS
OBJ_TY_1 TY_1 := TY_1(NULL,NULL,NULL);
BEGIN
SELECT FIRST_NAME,SALARY,HIRE_DATE
INTO OBJ_TY_1.FN, OBJ_TY_1.SL, OBJ_TY_1.HD
FROM EMPLOYEES
WHERE EMPLOYEE_ID = 120;
RETURN OBJ_TY_1;
END;
-- Example 2
CREATE OR REPLACE FUNCTION FN_RET_COL
RETURN TY_1
AS
OBJ_TY_1 TY_1;
BEGIN
SELECT TY_1(FIRST_NAME,SALARY,HIRE_DATE)
INTO OBJ_TY_1
FROM EMPLOYEES
WHERE EMPLOYEE_ID = 100;
RETURN OBJ_TY_1;
END;
-- Query
SELECT FN_RET_COL() FROM DUAL;
-- Modified Example 1(Throws Reference to uninitialized composite)
CREATE OR REPLACE FUNCTION FN_RET_COL
RETURN TY_1
AS
OBJ_TY_1 TY_1;
BEGIN
SELECT FIRST_NAME,SALARY,HIRE_DATE
INTO OBJ_TY_1.FN, OBJ_TY_1.SL, OBJ_TY_1.HD
FROM EMPLOYEES
WHERE EMPLOYEE_ID = 120;
RETURN OBJ_TY_1;
END;
實例1和實例2都可以正常工作。兩者幾乎完成相同的工作。 但我的疑問是,當示例1中的集合未被初始化時,就像例2中那樣。它拋出錯誤。但在示例2中,它沒有初始化,但工作正常。那麼何時初始化一個集合變量,什麼時候不需要?在oracle中初始化一個集合
感謝您的及時迴應 – ramesh538