我的业务需求是创建一个返回select语句的函数。我使用数据库类型成功创建了一个函数。但是,现在的要求是用 record type 替换数据库类型,这样做后我的函数现在给出错误 “PLS-00103:在期望以下之一时遇到符号“文件结束”:开始函数杂注过程“
下面是运行良好的代码:
create or replace type type_TRAUDIT040 as object
(X VARCHAR2(1000),
DOCUMENT_ID VARCHAR2(1000 ),
PR3_ID VARCHAR2(1000 ),
MICROFILM_ID VARCHAR2(1000 ),
CNT_PR3_ID VARCHAR2(1000 ),
CNT_MICRO_ID VARCHAR2(1000 ),
CREATE_USERID VARCHAR2(1000 ),
PAYEE_PRVR_EXT_ID VARCHAR2(1000 ),
RECCNT VARCHAR2(1000 ),
cp_claim_types_desc VARCHAR2(1000 ),
cp_claim_status_desc VARCHAR2(1000 ),
count_document_id VARCHAR2(1000 )
);
create or replace type table_TRAUDIT040 is table of type_TRAUDIT040;
create or replace function fn_traudit040
(
p_Ambulance varchar2
)
return table_TRAUDIT040
as test_type table_TRAUDIT040;
BEGIN
SELECT type_TRAUDIT040(
x,document_id,PR3_ID,MICROFILM_ID,CNT_PR3_ID,CNT_MICRO_ID,create_userid,PAYEE_PRVR_EXT_ID,RecCnt,'1' ,'2','3'
)
BULK COLLECT INTO test_type
FROM TRAUDIT040;
RETURN test_type;
END;
现在,当我用记录类型替换数据库类型时,我的代码停止工作。有人可以指导我下面的代码有什么问题吗:
create procedure p_traudit040(p_name varchar2)
is
TYPE type_rec_summary IS RECORD (
bhs_id VARCHAR2(40),
Name VARCHAR2(40),
bh_inst_id NUMBER
);
TYPE type_tab_sum IS
TABLE OF type_rec_summary;
FUNCTION f_get_data return type_tab_sum
as test_type type_tab_sum ;
begin
SELECT type_rec_summary(
bhs_id, Name, bh_inst_id
)
BULK COLLECT INTO test_type
FROM blu_benefit_holder_sections tr040
where Name = p_name;
return test_type;
end;
以下是错误截图:
提前非常感谢。
你的过程结构和函数定义是错误的:
CREATE OR REPLACE PROCEDURE p_traudit040(p_name VARCHAR2)
IS
-- Define record type
TYPE type_rec_summary IS RECORD (
bhs_id VARCHAR2(40),
name VARCHAR2(40),
bh_inst_id NUMBER
);
-- Define a table type of records
TYPE type_tab_sum IS
TABLE OF type_rec_summary;
-- Function to get data
FUNCTION f_get_data(p_name_in VARCHAR2) RETURN type_tab_sum
IS
test_type type_tab_sum;
BEGIN
SELECT type_rec_summary(
bhs_id,
name,
bh_inst_id
)
BULK COLLECT INTO test_type
FROM blu_benefit_holder_sections tr040
WHERE name = p_name_in;
RETURN test_type;
END f_get_data;
BEGIN
-- You can call the function `f_get_data` inside the procedure's main body.
DECLARE
data_summary type_tab_sum;
BEGIN
data_summary := f_get_data(p_name);
-- You can now process the data_summary or other staff here
FOR i IN 1..data_summary.COUNT LOOP
dbms_output.put_line('bhs_id: ' || data_summary(i).bhs_id || ', Name: ' || data_summary(i).name || ', bh_inst_id: ' || data_summary(i).bh_inst_id);
END LOOP;
END;
END p_traudit040;
/