printing variables in pl/sql
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));
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));
PL/SQL does not have a literal to represent boolean values. You will have to either convert the v_six_years boolean value to a string, or not use a boolean if you wish to print the value. PL/SQL booleans are great for logic but useless if you wish to display the value.
DECLARE
v_hire_date DATE:='30-Oct-2000';
v_six_years VARCHAR2(1);
BEGIN
IF MONTHS_BETWEEN(SYSDATE,v_fecha_contrato)/12 > 6 THEN
v_six_years:='1';
ELSE
v_six_years:='0';
END IF;
DBMS_OUTPUT.PUT_LINE('flag '||v_six_years);
END;
Or
DECLARE
v_hire_date DATE:='30-Oct-2000';
v_six_years BOOLEAN;
v_six_years_display VARCHAR2(5);
BEGIN
IF MONTHS_BETWEEN(SYSDATE,v_fecha_contrato)/12 > 6 THEN
v_six_years:=TRUE;
v_six_years_display := 'true';
ELSE
v_six_years:=FALSE;
v_six_years_display := 'false';
END IF;
DBMS_OUTPUT.PUT_LINE('flag '||v_six_years_display);
END;
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 );