Solved

Oracle PL/SQL Function Syntax

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

Title # Comments Views Activity
Oracle query output question 4 48
How to free up undo space? 3 50
Component is listed with a Protocol more than once 3 42
Error in creating a view. 8 23
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

829 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