oracle中的sql函数

cigdeys3  于 2021-07-29  发布在  Java
关注(0)|答案(1)|浏览(365)

所以我试图创建一个函数

Edit: Deleted this and created a new code

我得到了一个错误警告:函数是用编译错误创建的。所以指导是有帮助的。如果你能告诉我怎么执行我会很有帮助的
编辑:创建一个新代码以返回相同的错误

CREATE OR REPLACE FUNCTION EmpNoFunc(p_empno IN Employee01.EmpNo%TYPE)
RETURN VARCHAR2
IS Emp_Detail VARCHAR2(130);
BEGIN
SELECT 'E_Name-'|| Employee01.EName ||,
'Job-'|| Employee01.Job ||, 'Hired-'|| Employee01.HiredDate ||,
INTO Emp_Detail
FROM Employee01
WHERE EmpNo = p_empno;
RETURN(Emp_Detail);
END EmpNoFunc;
/

错误是-

5/1      PL/SQL: SQL Statement ignored
5/39     PL/SQL: ORA-00936: missing expression

但似乎解决不了。

wsxa1bj1

wsxa1bj11#

你很接近;类似于你的table上的工作示例(scott的emp):

SQL> CREATE OR REPLACE FUNCTION empnofunc (p_empno IN emp.empno%TYPE)
  2     RETURN VARCHAR2
  3  IS
  4     emp_detail  VARCHAR2 (130);
  5  BEGIN
  6     SELECT    'EName-'
  7            || e.ename
  8            || ', Job-'
  9            || e.job
 10            || ', Hired-'
 11            || e.hiredate
 12       INTO emp_detail
 13       FROM emp e
 14      WHERE e.empno = p_empno;
 15
 16     RETURN (emp_detail);
 17  END empnofunc;
 18  /

Function created.

SQL> SELECT empnofunc (empno) result
  2    FROM emp
  3   WHERE empno = 7369;

RESULT
-----------------------------------------------------------------------------
EName-SMITH, Job-CLERK, Hired-17.12.80

SQL>

相关问题