Solved

Oracle PL/SQL Function Syntax

Posted on 2014-09-30
3
593 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many‚Ķ
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

930 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now