【问题标题】:While INSERT got error like PLS-00904: txt.col1 is invalid identifier虽然 INSERT 出现 PLS-00904 之类的错误:txt.col1 is invalid identifier
【发布时间】:2018-11-07 22:24:21
【问题描述】:

在我的存储过程中,我希望 col1col2 的值与员工匹配,然后插入员工的唯一记录。如果未找到,则将 col1col2col3 的值与 employee 匹配匹配然后插入值。如果在匹配所有这些列时也找不到,则使用另一列插入记录。 我们必须使用 collection 以及 condition 然后 insert。 还有一件事我想通过传递另一列值来找到像 emp_id 这样的值列表,如果单个记录不能 ma​​tch 然后制作 emp_id 作为 NULL

我还想在与 txt 以及其他具有 emp 等数据的表匹配后一次插入一条记录。

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;

empstud 是我必须与 txt 匹配的不同表格。 在那个存储过程中,我想以批处理模式将数据从 txt 加载到 ma​​in_table 中。数据将被一条一条记录匹配,然后如果匹配条件匹配则加载到主表中。 像 emp 表有 (col1, eid, ename, addr) 列和stud 表具有(col2sidsnameaddr)。我如何创建存储过程,以便在批处理中通过上述逻辑一一加载数据。你能帮我分享你的想法吗?谢谢

【问题讨论】:

  • 请提供tbl1和txt的create table语句。
  • @shahinP 如果您希望我们为您提供帮助,请向我们提供表格结构。如果没有结构,我们就无法判断问题发生在哪里。
  • 你在代码中使用的emp是什么?请重新检查您的程序,有很多错误。
  • @VimalBhaskar emp, stud 是另一个表。我们将值与 txt 列匹配。
  • @shahinP 你能提供表格的“结构”吗?对两个表都使用 Desc 表名并将其放入问题中。

标签: sql oracle stored-procedures plsql


【解决方案1】:

我们仍然没有得到你的表格结构,所以我要给你一个关于你能做的最愚蠢的事情的基本想法。如果您希望我们帮助您提供最佳解决方案,请提供表格结构。没有测试,所以请测试,如果您有任何疑问,请告诉我。

create or replace
procedure sp_ex
as
cursor c1 is select txt.col1,txt.col2,txt.col3,(select emp.col1 from emp where emp.col1=txt.col1) as empcol1,(select stud.col2 from stud where stud.col2=txt.col2)studcol1 from txt;
v_col1 txt.col1%type;
type record is table of c1%rowtype;  --Staging table
v_rc record := record();
begin
open c1;
loop 
    fetch c1 bulk collect into v_rc limit 1000;
    exit when v_rc.count=0;
        for i in 1..v_rc.count loop

        --Your logic goes here 

            end loop;


    end loop;
    close c1;
end sp_ex;

【讨论】:

  • 感谢您给我答复,但 empcol1studcol1 呢?现在我可以像上述条件一样匹配。
  • 是的,你可以匹配。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-04
相关资源
最近更新 更多