虽然 INSERT 出现错误 PLS-00904:stud.col3 是无效标识符
While INSERT got error PLS-00904: stud.col3 is invalid identifier
在我的存储过程中,如果 col1 & col2 的值与员工匹配,则插入员工的唯一记录。如果未找到,则将 col1、col2 & col3 的值与 [ 匹配=19=]employee 匹配然后插入值。如果在匹配所有这些列时也没有找到,则使用另一列插入记录。
还有一件事我想通过传递另一列值找到像 emp_id 这样的值列表,如果单个记录不能 match 然后使 emp_id 为 NULL.
此外,我想在与 txt 以及其他 table 具有 emp[=37= 等数据的匹配后一次插入一条记录].
create or replace procedure sp_ex
as
cursor c1 is select * from txt%rowtype;
v_col1 tbl1.col1%type;
type record is table of txt%rowtype; --Staging table
v_rc record := record();
begin
open c1;
loop
fetch c1 bulk collect into v_rc limit 1000;
loop
for i in 1..v_rc.count loop
select col1 into v_col1 from tbl1
where exists (select col1 from tbl1 where tbl1.col1 = emp.col1);
insert
when txt.col1 = emp.col1 and txt.col2 = stud.col2 then
into main_table(columns) values(v_rc(i).col1, ...)
when txt.col1 = emp.col1 and txt.col2 = stud.col2 and txt.col3 = stud.col3 then
into main_table(columns) values(v_rc(i).col1, ...)
else
insert into main_table(columns) values(v_rc(i).col1, ...)
select * from txt;
end loop;
exit when v_rc.count < limit;
end loop;
close c1;
end sp_ex;
虽然 emp、stud 是不同的 table,但我必须匹配 txt 。
在该存储过程中,我想以批处理模式将数据从 txt 加载到 main_table 中。数据会一条一条记录匹配,如果匹配条件匹配则载入主table。我如何创建存储过程,以便数据将在批处理中按上述逻辑一个接一个地加载。你能帮我分享你的想法吗?谢谢
语法好像比较混乱。
Multi-table insert是这样的:
insert all -- alternatively, "insert first"
when dummy = 'X' then
into demo (id) values (1)
when dummy = 'Y' then
into demo (id) values (2)
else
into demo (id) values (3)
select * from dual;
或者您想要 PL/SQL case
statement:
case
when dummy = 'X' then
insert into demo (id) values (1);
when dummy = 'Y' then
insert into demo (id) values (2);
else
insert into demo (id) values (3);
end case;
相反,似乎是两者的混合。
还有一个缺失的 end loop
和一个没有 into
子句的隐式游标 (select col1 from tbl1
)。
在我的存储过程中,如果 col1 & col2 的值与员工匹配,则插入员工的唯一记录。如果未找到,则将 col1、col2 & col3 的值与 [ 匹配=19=]employee 匹配然后插入值。如果在匹配所有这些列时也没有找到,则使用另一列插入记录。
还有一件事我想通过传递另一列值找到像 emp_id 这样的值列表,如果单个记录不能 match 然后使 emp_id 为 NULL.
此外,我想在与 txt 以及其他 table 具有 emp[=37= 等数据的匹配后一次插入一条记录].
create or replace procedure sp_ex
as
cursor c1 is select * from txt%rowtype;
v_col1 tbl1.col1%type;
type record is table of txt%rowtype; --Staging table
v_rc record := record();
begin
open c1;
loop
fetch c1 bulk collect into v_rc limit 1000;
loop
for i in 1..v_rc.count loop
select col1 into v_col1 from tbl1
where exists (select col1 from tbl1 where tbl1.col1 = emp.col1);
insert
when txt.col1 = emp.col1 and txt.col2 = stud.col2 then
into main_table(columns) values(v_rc(i).col1, ...)
when txt.col1 = emp.col1 and txt.col2 = stud.col2 and txt.col3 = stud.col3 then
into main_table(columns) values(v_rc(i).col1, ...)
else
insert into main_table(columns) values(v_rc(i).col1, ...)
select * from txt;
end loop;
exit when v_rc.count < limit;
end loop;
close c1;
end sp_ex;
虽然 emp、stud 是不同的 table,但我必须匹配 txt 。 在该存储过程中,我想以批处理模式将数据从 txt 加载到 main_table 中。数据会一条一条记录匹配,如果匹配条件匹配则载入主table。我如何创建存储过程,以便数据将在批处理中按上述逻辑一个接一个地加载。你能帮我分享你的想法吗?谢谢
语法好像比较混乱。
Multi-table insert是这样的:
insert all -- alternatively, "insert first"
when dummy = 'X' then
into demo (id) values (1)
when dummy = 'Y' then
into demo (id) values (2)
else
into demo (id) values (3)
select * from dual;
或者您想要 PL/SQL case
statement:
case
when dummy = 'X' then
insert into demo (id) values (1);
when dummy = 'Y' then
insert into demo (id) values (2);
else
insert into demo (id) values (3);
end case;
相反,似乎是两者的混合。
还有一个缺失的 end loop
和一个没有 into
子句的隐式游标 (select col1 from tbl1
)。