I have an error at this function. I have no idea why 开发者_如何学Cit doesn't work.
Can you help me please?
CREATE OR REPLACE FUNCTION EMPNAM(empno in number)
RETURN VARCHAR2 IS
DECLARE nam VARCHAR2(40);
BEGIN
SELECT BEZEICHNUNG
INTO nam
FROM PROJ_PROJEKT
WHERE PROJEKTID = empno;
RETURN nam;
END EMPNAM;
Here is the error message:
ERROR: Error at line 7:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
( begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
continue close current delete fetch lock
insert open rollback savepoint set sql execute commit forall
merge pipe purge
5. select BEZEICHNUNG into nam from PROJ_PROJEKT where PROJEKTID=empno;
6. return nam;
7. END EMPNAM;
I don't think you need the DECLARE
keyword there. The syntax is:
create or replace function foo
return return-type
is
(vars)
begin
(code)
end foo;
You need to remove the DECLARE
keyword
For example:
CREATE OR REPLACE FUNCTION patient_func
RETURN VARCHAR2
IS
patient_name VARCHAR(20);
BEGIN
SELECT first_name
INTO patient_name
FROM patient_tbl
WHERE patientID = 123;
RETURN patient_name;
END patient_func;
Declare must not be used in your code and
SELECT BEZEICHNUNG
INTO nam
FROM PROJ_PROJEKT
WHERE PROJEKTID = empno;
In above statement what is "BEZEICHNUNG"... if it is a name it can't directly moved to nam the column name can be moved into the identifier... the above code must be like as follows
select lastname into nam
from proj_projekt
where projektid=empno;
here "lastname" is the column name which is moved into identifier "name"
精彩评论