Use of boolean in PL/SQL

Alternatively you can use the Oracle function diutil.bool_to_int to convert a boolean value to an integer: True -> 1, False -> 0.

dbms_output.put_line(diutil.bool_to_int(p_your_boolean));

dbms_output.put_line is not overloaded to accept a boolean argument. You can do something like

dbms_output.put_line( case when exist = true 
                           then 'true'
                           else 'false'
                        end );

to convert the boolean into a string that you can then pass to dbms_output.

The ORA-01422 error is a completely separate issue. The function checkEmpNo includes the SELECT INTO statement

SELECT emp_id 
  INTO emp_number
  FROM emp;

A SELECT INTO will generate an error if the query returns anything other than 1 row. In this case, if there are multiple rows in the emp table, you'll get an error. My guess is that you would want your function to do something like

CREATE OR REPLACE FUNCTION checkEmpNo(p_eno number)
  RETURN boolean 
IS
  l_count number;
BEGIN
  SELECT count(*)
    INTO l_count
    FROM emp
   WHERE emp_id = p_eno;

  IF( l_count = 0 )
  THEN
    RETURN false;
  ELSE
    RETURN true;
  END IF;
END checkEmpNo;

Tags:

Oracle

Plsql