CREATE OR REPLACE FUNCTION employer_details_func
RETURN VARCHAR(20);
IS
e_name VARCHAR(20);
BEGIN
SELECT emp_name INTO e_name
FROM employees WHERE emp_no = '5';
RETURN e_name;
END employer_details_func;
编译上述程序时,我收到此错误
错误(2,18):PLS-00103:遇到符号“(”,当遇到下列情况之一时:。@%;使用authid作为集群顺序使用 外部字符确定性parallel_enable流水线 聚合result_cache
更新:
CREATE OR REPLACE FUNCTION employer_details_func
RETURN VARCHAR2(20);
IS
e_name VARCHAR2(20);
BEGIN
SELECT emp_name INTO e_name FROM employees WHERE emp_no ='5';
RETURN e_name;
END employer_details_func;
错误:
Error(2,19): PLS-00103: Encountered the symbol "(" when expecting one of the following: . @ % ; is authid as cluster order using external character deterministic parallel_enable pipelined aggregate result_cache
我的代码出了什么问题?请告诉我。
答案 0 :(得分:2)
使用RETURN VARCHAR
代替RETURN VARCHAR(20);
。
http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_5009.htm上的Oracle文档说 RETURN子句...数据类型无法指定长度,精度或比例......
修改强>
我使用此代码在SQL Fiddle上仔细检查了它,它似乎有用(返回bob):
CREATE TABLE employees(emp_name VARCHAR2(20), emp_no VARCHAR2(20))
/
CREATE OR REPLACE FUNCTION employer_details_func
RETURN VARCHAR
IS
e_name VARCHAR(20);
BEGIN
SELECT emp_name INTO e_name FROM employees WHERE emp_no ='5';
RETURN e_name;
END employer_details_func;
/
insert into employees values('bob','5');
select employer_details_func() from dual;
答案 1 :(得分:0)
这应该解决它:
CREATE OR REPLACE FUNCTION employer_details_func
RETURN VARCHAR2
IS
e_name VARCHAR2(20);
BEGIN
SELECT emp_name INTO e_name FROM employees WHERE emp_no ='5';
RETURN e_name;
END employer_details_func;
答案 2 :(得分:0)
创建或替换
FUNCTION employer_details_func
RETURN VARCHAR2
IS
e_name VARCHAR2(20);
BEGIN
SELECT last_name INTO e_name FROM employees WHERE employee_id ='100';
RETURN e_name;
END employer_details_func;
您不能提及由oracle引擎管理的返回类型的大小。
答案 3 :(得分:0)
您也可以尝试这样
创建或替换功能employer_details_func
RETURN employees.e_name%TYPE
IS
e_name employees.e_name%TYPE;
BEGIN
SELECT emp_name INTO e_name FROM employees WHERE emp_no ='5';
RETURN e_name;
END employer_details_func;