Compile the creation of the error function, over and over again

I don't see anything wrong with this function. Everything I run with SQL Developer I get a compile error, I try to fix that and get five more who have no sense. All "inappropriate" generic syntax errors

There is something terribly wrong with my function? I have re-written so several times, I think that I did nothing, but tried to slip in with the DB knowing, which is not me to get anywhere.

I shows the log of compiler errors, but as I said, he continues to change and add an error with any change to the function

Any ideas? At this point, I think Developer SQL (for Mac) is just smoked. I often force quit
CREATE OR REPLACE FUNCTION emp_status
     (emp_first IN VARCHAR2, 
     emp_last IN VARCHAR2,                        
     emp_num IN NUMBER,
     staff_id IN NUMBER
     staff_rank IN VARCHAR2)                     
     
RETURN VARCHAR2 

IS  
     emp_information VARCHAR2(80) := emp_first || emp_last || ' has a rank of ' || staff_rank);          
    
          
BEGIN

SELECT employees.e_first, employees.e_last, staff.e_id, staff.s_rank
INTO emp_first, emp_last, staff_id, staff_rank
FROM Employees, Staff
WHERE employees.e_id = staff_id;

RETURN emp_information; 
END;
tables
-- Create tables 
CREATE TABLE EMPLOYEES
(e_id NUMBER(1),
e_first VARCHAR2(20),
e_last VARCHAR2(20));

CREATE TABLE STAFF
(s_id NUMBER(3),
e_id  NUMBER(1),
s_phone VARCHAR2(10),
s_rank VARCHAR2(8));

-- Insert into tables

INSERT INTO EMPLOYEES VALUES
(1, 'Holly', 'Foster');

INSERT INTO EMPLOYEES VALUES
(2, 'Robert', 'Combs');

INSERT INTO EMPLOYEES VALUES
(3, 'Harvy', 'Lambert');

INSERT INTO EMPLOYEES VALUES
(4, 'Sarah', 'Miller');


INSERT INTO STAFF VALUES
(001, 1, '9992221234', 'ADMIN');

INSERT INTO STAFF VALUES
(023, 2, '9992226789', 'SEC');

INSERT INTO STAFF VALUES
(006, 3, '9992223456', 'TECH');

INSERT INTO STAFF VALUES
(011, 4, '9992223535', 'HR');

Your function does not much sense in my opinion.

You have these variables to input emp_ * and staff_ * that you concatenate in an emp_information of VARCHAR2.

Then you try to SELECT those variables based on the query in the function (which is not allowed by the way) entry.

You probably want something like this I guess:

CREATE OR REPLACE FUNCTION emp_status (staff_id IN NUMBER)
RETURN VARCHAR2
IS
        emp_information VARCHAR2(80);
BEGIN
        SELECT employees.e_first || employees.e_last || ' has rank of ' || staff.s_rank
        INTO    emp_information
        FROM    Employees
        ,       Staff
        WHERE   STAFF.S_ID = staff_id
        AND     EMPLOYEES.E_ID = STAFF.E_ID; 

        RETURN emp_information;
END;

Your original code does not include a JOIN with the STAFF table I added.

However, in reality you do not have a function at all. you could just do the following:

CREATE VIEW EMP_INFORMATION_VW AS
        SELECT  staff.s_id
        ,       employees.e_first || employees.e_last || ' has rank of ' || staff.s_rank AS     emp_information
        FROM    Employees
        ,       Staff
        WHERE   EMPLOYEES.E_ID = STAFF.S_ID;  

Then, you could do:

SELECT EMP_INFORMATION FROM EMP_INFORMATION_VW WHERE S_ID = :STAFFID

HTH!

Tags: Database

Similar Questions

Maybe you are looking for