Return course name for an employee id : Query Select Columns « Select Query « Oracle PL / SQL






Return course name for an employee id

   
SQL> CREATE TABLE emp
  2     (id         VARCHAR2(10) NOT NULL,
  3      course     VARCHAR2(10),
  4      year       VARCHAR2(4),
  5      PRIMARY KEY (id));

Table created.

SQL>
SQL>
SQL> CREATE OR REPLACE FUNCTION emp_Course(s_id emp.id%TYPE)
  2     RETURN VARCHAR2 IS
  3     v_course    VARCHAR(10);
  4  BEGIN
  5     SELECT course INTO v_course
  6     FROM emp
  7     WHERE id = s_id;
  8     RETURN v_course;
  9  END emp_Course;
 10  /

Function created.

SQL>
SQL> drop table emp;

Table dropped.

   
    
    
  








Related examples in the same category

1.Query returning all rows and all columns from the table
2.Indicate the column names in query command
3.Returning a Single Column.sql
4.Reference one column more than once
5.Reference renamed column in order by
6.Renaming a column with a longer name