[英]How to Select column from joined table in PL/SQL table
I'm creating a PL/SQL function that returns an employe's information, by asking for the employee's id.我正在创建一个 PL/SQL function,它通过询问员工的 ID 来返回员工的信息。 The function get this code/ID and searches for the employee's info.
function 获取此代码/ID 并搜索员工信息。
My problem is that I also need to add another column that I get from joining another table but I get PL/SQL: ORA-00904: "EMPLOYE"."IDEMPLOYE": identificateur non valide
.我的问题是我还需要添加另一列,这是我通过加入另一个表获得的,但我得到了
PL/SQL: ORA-00904: "EMPLOYE"."IDEMPLOYE": identificateur non valide
。 is it possible to?是否有可能?
Here is my code:这是我的代码:
CREATE OR REPLACE FUNCTION fNombreProjet(id_employe IN employe.idemploye%type)
RETURN sys_refcursor is data_emp sys_refcursor;
BEGIN
OPEN data_emp for
SELECT emp_recherché.IDEMPLOYE ,emp_recherché.NOMEMPLOYE
FROM Employe emp_recherché
WHERE idEmploye = id_employe;
RETURN data_emp;
END;
/
SELECT fNombreProjet(2000) result FROM dual;
this is the query Im trying to join in the PL/SQL select (where the column I want is count(*))这是我试图加入 PL/SQL select 的查询(我想要的列是计数(*))
SELECT employe.IDEMPLOYE, employe.NOMEMPLOYE, count(*)
FROM employe
join ressourcesprojet on employe.idemploye=ressourcesprojet.idemploye
group by employe.IDEMPLOYE, employe.NOMEMPLOYE;
The PL/SQL mix of the two Ive been trying without success.(Doesnt work)两者的 PL/SQL 组合我一直在尝试但没有成功。(不起作用)
CREATE OR REPLACE FUNCTION fNombreProjet(id_employe IN employe.idemploye%type)
RETURN sys_refcursor is data_emp sys_refcursor;
BEGIN
OPEN data_emp for
SELECT emp_recherché.IDEMPLOYE ,emp_recherché.NOMEMPLOYE, count(*)
FROM Employe emp_recherché
join ressourcesprojet on employe.idemploye=ressourcesprojet.idemploye
WHERE idEmploye = id_employe
group by emp_recherché.IDEMPLOYE ,emp_recherché.NOMEMPLOYE;
RETURN data_emp;
END;
/
I fixed it.我修好了它。 I had to use
emp_rechercé
instead of employe
and place where before the group by.我不得不使用
emp_rechercé
而不是employe
并将 where 放在 group by 之前。 And a few more little details.还有一些小细节。 here it is:
这里是:
CREATE OR REPLACE FUNCTION fNombreProjet(id_employe IN employe.idemploye%type)
RETURN sys_refcursor is data_emp sys_refcursor;
BEGIN
OPEN data_emp for
SELECT emp_recherché.IDEMPLOYE ,emp_recherché.NOMEMPLOYE, count(*)
FROM Employe emp_recherché
join ressourcesprojet on emp_recherché.idemploye=ressourcesprojet.idemploye
WHERE emp_recherché.idEmploye = id_employe
group by emp_recherché.IDEMPLOYE ,emp_recherché.NOMEMPLOYE;
RETURN data_emp;
END;
/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.