Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

printing variables in pl/sql

I have the following code:

DECLARE
   v_hire_date DATE:='30-Oct-2000';
   v_six_years BOOLEAN;  
BEGIN
IF MONTHS_BETWEEN(SYSDATE,v_fecha_contrato)/12 > 6 THEN
      v_six_years:=TRUE;
ELSE
      v_six_years:=FALSE;
END IF;
DBMS_OUTPUT.PUT_LINE('flag '||v_six_years);
END;

I want to print the value of the variable v_six_years, but I am getting the error:

ORA-06550: line 10, column 24:
PLS-00306: wrong number or types of arguments in call to '||'
ORA-06550: line 10, column 3

How to print the value of the variable v_six_years?

like image 893
Layla Avatar asked Oct 22 '12 04:10

Layla


3 Answers

It seems you cannot concat varchar and boolean.

Define this function:

FUNCTION BOOLEAN_TO_CHAR(FLAG IN BOOLEAN)
RETURN VARCHAR2 IS
BEGIN
  RETURN
   CASE FLAG
     WHEN TRUE THEN 'TRUE'
     WHEN FALSE THEN 'FALSE'
     ELSE 'NULL'
   END;
END;

and use it like this:

DBMS_OUTPUT.PUT_LINE('flag '|| BOOLEAN_TO_CHAR(v_six_years));
like image 130
mzzzzb Avatar answered Oct 18 '22 12:10

mzzzzb


You can use below to print Boolean Value in PLSQL

dbms_output.put_line('v_six_years '||  sys.diutil.bool_to_int(v_six_years));
like image 32
Rocker Avatar answered Oct 18 '22 13:10

Rocker


dbms_output.put_line is not overloaded to accept a boolean argument.Simple one line answer would be

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

like image 27
Aniket Thakur Avatar answered Oct 18 '22 11:10

Aniket Thakur