我正在尝试从 Oracle 中的存储函数返回查询。这个简单的尝试失败了:
CREATE OR REPLACE TYPE GetObjectsForFolderObjectType IS OBJECT (
FOLDER_ID NUMBER(9), OBJECT_ID NUMBER(9)
);
CREATE OR REPLACE TYPE GetObjectsForFolderTableType IS
TABLE OF GetObjectsForFolderObjectType;
CREATE OR REPLACE FUNCTION GetObjectsForFolder
(FOLDER_ID INTEGER, FOLDER_DATA_TABLE VARCHAR2)
RETURN GetObjectsForFolderTableType IS
THE_RESULT GetObjectsForFolderTableType := GetObjectsForFolderTableType ( );
BEGIN
EXECUTE IMMEDIATE 'SELECT * FROM '||FOLDER_DATA_TABLE BULK COLLECT INTO THE_RESULT;
RETURN THE_RESULT;
END;
SELECT * FROM TABLE(GetObjectsForFolder(1, 'MY_TABLE_NAME'));
上面的结果是
ORA-00932: inconsistent datatypes: expected - got -
ORA-06512: at "USERNAME.GETOBJECTSFORFOLDER", line 6
00932. 00000 - "inconsistent datatypes: expected %s got %s"
*Cause:
*Action:
注意:虽然我在示例中掩盖了一些内容,但 ORA-00932 行确实显示“预期 - 得到 -”。