我有一个简单的存储过程:
SELECT NVL(pnum,0)
INTO emp_pnum
FROM employee_pnum
WHERE person_id = i_person_id
AND pn_status_id = (SELECT pn_status_id FROM ems.pn_status WHERE pn_status_desc = 'Active');
SELECT NVL(pnum,0)
INTO old_pnum
FROM employee_pnum_history
WHERE person_id = i_person_id
AND created_date = (SELECT MAX(created_date) FROM ems.employee_pnum_history WHERE person_id = i_person_id);
OPEN x_pnum_history
FOR SELECT emp_pnum,old_pnum
FROM dual;
因此返回游标x_pnum_history
。我想要的是将结果集读入类中,如下所示
EmployeePNum empPnum = new EmployeePNum();
empPnum.setCurrent_pnum(rs.getString("emp_pnum"));
empPnum.setOld_pnum(rs.getString("old_pnum"));
它说
CallableStatementCallback; bad SQL grammar [{call EMS.EMS_PKG.GET_EMP_PNUM(?, ?, ?, ?)}];
nested exception is java.sql.SQLException: Invalid column name
我不确定这里到底出了什么问题......我们非常感谢任何帮助。
答案 0 :(得分:0)
执行此操作时:
OPEN x_pnum_history
FOR SELECT emp_pnum,old_pnum
FROM dual;
...您正在从PL / SQL块的范围中选择值,但您生成的列没有名称。你可以看到与此类似的东西(通过SQL Developer运行):
var rc refcursor
declare
emp_pnum number;
begin
emp_pnum := 1;
open :rc for select emp_pnum as emp_pnum from dual;
end;
/
anonymous block completed
print rc
RC
---------------------------------------
:B1
---------------------------------------
1
请注意,列标题显示通用绑定标记:B1
。但是,如果我明确地对列进行别名,那么这就是:
declare
emp_pnum number;
begin
emp_pnum := 1;
open :rc for select emp_pnum as emp_pnum from dual;
end;
/
anonymous block completed
print rc
RC
---------------------------------------
EMP_PNUM
---------------------------------------
1
因此,在您的情况下,您需要更改您的程序以包含别名:
OPEN x_pnum_history
FOR SELECT emp_pnum as emp_pnum, old_pnum as old_pnum
FROM dual;
当然,假设您的驱动程序和版本可以处理命名参数。我认为您仍然可能需要在getString()
电话中使用大写名称。