我想存储一些值,然后检索相同的值,就像我们使用oracle实际表一样。
我有以下包头:
create or replace PACKAGE test_record AS
-- 1. Type definition
type status_change_t is record (
action varchar2(30),
production_order varchar2(30),
job_status varchar2(30),
operator varchar2(200),
reg_date date
);
-- 2. type table of record
type status_change_table_t is table of status_change_t index by binary_integer;
-- 3. procedure where it is passed as parameter
procedure StatusChange(p_transaction_id in varchar2,
p_status_change_table in status_change_table_t);
END test_record;
包裹体:
create or replace PACKAGE BODY test_record as
-- Procedure
procedure StatusChange(p_transaction_id in varchar2,
p_status_change_table in status_change_table_t)
is
l_app varchar2(50) := 'xxgex_test_record.StatusChange';
l_status_change_rec status_change_t;
l_return_status varchar(9000);
l_job_status varchar(100);
begin
--InitContext;
--xxgex_util.debuglog(l_app, 'called');
for i in p_status_change_table.first .. p_status_change_table.last loop
l_status_change_rec := p_status_change_table(i);
dbms_output.put_line('record ' || i || ': action = ' || p_status_change_table(i).action || '. production_order = ' || p_status_change_table(i).production_order || ', status = ' || p_status_change_table(i).job_status);
--select job status
select l.meaning
into l_job_status
from wip_discrete_jobs disc,
wip_entities ent,
mfg_lookups l
where ent.wip_entity_name = l_status_change_rec.production_order
and ent.wip_entity_id = disc.wip_entity_id
and disc.status_type = l.lookup_code
and l.lookup_type = 'WIP_JOB_STATUS';
--the job must not be in closed status
if upper(l_job_status) = 'CLOSED' then
RAISE_APPLICATION_ERROR(-20001, 'Job must not be in Closed status');
dbms_output.put_line('Job must not be in Closed status, job name:' || l_status_change_rec.production_order);
end if;
if upper(l_status_change_rec.job_status) = 'RELEASED' then
dbms_output.put_line('invalid job_status: ' || l_status_change_rec.job_status);
else
dbms_output.put_line('invalid job_status: ' || l_status_change_rec.job_status);
RAISE_APPLICATION_ERROR(-20001, 'invalid job_status: ' || l_status_change_rec.job_status);
end if;
end loop;
end StatusChange;
end test_record;
现在我很困惑:我怎么能调用这个函数?
这是我的执行脚本,但它会抛出错误:
declare
l_status_rec test_record.status_change_table_t;
begin
select class_code
into l_status_rec
from wip_discrete_jobs
where wip_entity_id= 226003;
test_record.StatusChange(1, l_status_rec);
end;
这是错误:
在命令行中从第1行开始出错 - 声明 l_status_rec test_record.status_change_table_t;开始从wip_discrete_jobs中选择class_code到l_status_rec wip_entity_id = 226003; test_record.StatusChange(1,l_status_rec);结束;错误报告 - ORA-06550:第5行,第8列:PLS-00597:表达式'L_STATUS_REC'in INTO列表的类型错误ORA-06550:第6行第3列:PL / SQL: ORA-00904 ::无效标识符ORA-06550:第4行第3列:PL / SQL: SQL语句被忽略了 06550. 00000 - “行%s,列%s:\ n%s” *原因:通常是PL / SQL编译错误。 *操作:
答案 0 :(得分:1)
Edit2:问题现在完全不同了
您现在正在尝试将单个列选择为具有多个列的表类型的变量。我不知道您的数据模型,但您应该尝试选择此类型所需的所有列,例如:
nil
答案 1 :(得分:1)
PLS-00597:INTO列表中的表达式'L_STATUS_REC'类型错误
您的记录在其定义中有五列:
type status_change_t is record (
action varchar2(30),
production_order varchar2(30),
job_status varchar2(30),
operator varchar2(200),
reg_date date
);
但您的SELECT语句在其预测中只有一列:
select class_code
into l_status_rec
from wip_discrete_jobs
SELECT的投影必须与INTO变量的签名匹配。