Solved

Oracle PL/SQL Function Syntax

Posted on 2014-09-30
3
668 Views
Last Modified: 2014-09-30
This is a simple function that I copied from a tutorial.

The following error is triggered when I try to compile:

"The name in the text editor differs from the specified object name"

Here is the function:

 
CREATE OR REPLACE FUNCTION DBM_Add_ColComment 
    
RETURN VARCHAR(20);
 IS 

    emp_name VARCHAR(20); 
 
    BEGIN 
 
        SELECT ename INTO emp_name
        FROM employee WHERE EmpNo = 6;
        
        RETURN emp_name;

 END;
 / 

Open in new window


This statement executes in the SQL window:

SELECT ename
        FROM employee WHERE EmpNo = 6;

What am I missing?

Thanks,
0
Comment
Question by:Dovberman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 500 total points
ID: 40353307
Remove the semi-colon (;) from the first RETURN (after the CREATE)
. .  And the "( 20)" also, and replace IS with AS and:
CREATE OR REPLACE FUNCTION Dbm_Add_Colcomment
   RETURN VARCHAR2
AS
   Emp_Name       VARCHAR2 ( 20 );
BEGIN
   SELECT Ename
     INTO Emp_Name
     FROM Employee
    WHERE Empno = 6;

   RETURN Emp_Name;
END;
/

Open in new window

;)
PS: You may also want to use "VARCHAR2" data type.
0
 

Author Comment

by:Dovberman
ID: 40353431
Wonderful,

Thanks,
0
 

Author Closing Comment

by:Dovberman
ID: 40353435
Thank you,
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question