'Check if a column is all NULL in PL/SQL

I want to write a programm that first checks if a column is only populated with NULLs before updating the column.
I have written what I thought should work, however, DBMS_OUTPUT.PUT_LINE is only returning the name of the column.

DECLARE
  v_null VARCHAR(255) NULL;

BEGIN
DBMS_OUTPUT.ENABLE;

SELECT MAX('col_name') INTO v_null
FROM user_tab_cols
WHERE UPPER(table_name) = 'table';

DBMS_OUTPUT.PUT_LINE(v_null);  
     
    if v_null IS NULL THEN
    DBMS_OUTPUT.PUT_LINE('COLUMN is empty');
    end if;
end;  

Also when I change my IF clause to NOT NULL then the 'COLUMN is empty' string gets returned.
The column is only populated with NULLs, I have checked multiple times. The column is of NUMBER type. Running Oracle 12c Enterprise on Windows 10.



Solution 1:[1]

Found it...

DECLARE
  v_null VARCHAR(255) NULL;

BEGIN
DBMS_OUTPUT.ENABLE;

SELECT MAX(col_name) INTO v_null
FROM table;

DBMS_OUTPUT.PUT_LINE(v_null);  

    if v_null IS NULL THEN
    DBMS_OUTPUT.PUT_LINE('COLUMN is empty');
    end if;
end; 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 blabbath