Solved

Oracle PL/SQL Function Syntax

Posted on 2014-09-30
3
573 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
Comment Utility
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
Comment Utility
Wonderful,

Thanks,
0
 

Author Closing Comment

by:Dovberman
Comment Utility
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.

Join & Write a Comment

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

762 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

11 Experts available now in Live!

Get 1:1 Help Now