存储过程编译无误 测试出现ora 00904标识符无效错误
初学ORACLE 第一次写存储过程 麻烦各位大师帮忙
create or replace procedure PRO_MI_GETQCNOTE(QcId in varchar2, --质检单编号
SourceId in varchar2, --来源单编号
LogId in varchar2, --物流单编号
OpeStartDate in varchar2, --开始日期
OpeEndDate in varchar2, --开始日期
QcMan in varchar2, --质检人
GoodsId in varchar2, --商品编号
cur_qcinfo out sys_refcursor --查询信息列表
) is
str_sql varchar2(2000);
str_case varchar2(2000);
begin
str_sql := '';
-- 判断是否含有质检单编号
if Qcid is not null then
str_sql := ' and c1.IN_QC_ID = ' || QcId || '';
else
if SourceId is not null then
str_sql := str_sql || ' and c1.SOURCE_ID = ' || SourceId || '';
end if;
if LogId is not null then
str_sql := str_sql || ' and c1.LOG_ID = ' || LogId || '';
end if;
if OpeStartDate is not null and OpeEndDate is not null then
str_sql := str_sql || ' and ' || 'to_char(' ||'c1.Ope_Date' || ',' ||'''yyyy-mm-dd HH24:mi:ss'')' || ' between '||''''||OpeStartDate||''''||' and '||''''||OpeEndDate||'''';
end if;
if QcMan is not null then
str_sql := str_sql || ' and c1.Qc_Man = ' || QcMan || '';
end if;
if GoodsId is not null then
str_sql := str_sql || ' and c2.Goods_Id = ' || GoodsId || '';
end if;
end if;
str_case := 'select c1.IN_QC_ID,c1.ARRIVAL_ID,c1.LOG_id,c1.LOG_COM_ID,c1.STORAGE_ID,c1.MONEY,c1.QC_TYPE,c1.QC_MAN,c1.YIELD,c1.ADJUST_FLAG,c1.OPERATOR,c1.Ope_Date,c1.QC_DATE,c1.REMARK,c1.SOURCE_ID,c1.QC_FLAG,c1.MAKE_MAN,c1.MAKE_DATE,c2.Goods_Id
from T_RK_INQCNOTE c1 join T_RK_INQCDETAILNOTE c2 on c1.IN_QC_ID=c2.QC_ID where 1=1' ||
str_sql;
open cur_qcinfo for str_case;
end PRO_MI_GETQCNOTE;
------解决方案--------------------这样看编译不会有什么错,重点比对一下你的引号里面的字段,是不是有拼写错误
------解决方案--------------------建议你做test,拿出str_case中的sql在外边执行看看报错不。
str_sql := str_sql || ' and c1.Qc_Man = ' || QcMan || '';
上边这个与下边语句没有区别
str_sql := str_sql || ' and c1.Qc_Man = ' || QcMan;
如果要加引号应该为
str_sql := str_sql || ' and c1.Qc_Man = ''' || QcMan || '''';