Interesting - null field

Dúvidas, dicas e truques de SQL, Select, Update, Delete, cláusulas, operações com joins, Funções em SQLs, etc
Post Reply
User avatar
dr_gori
Moderador
Moderador
Posts: 5024
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

See this .. I created a view with a null field.
The field is recorded with varchar2 (0). This proves that null = varchar2 (0) ... :-)

Select all

SQL> CREATE OR REPLACE VIEW VIEW_NULL AS 
  2  SELECT 
  3    NULL CAMPO_NULL 
  4  FROM DUAL; 
 
View created. 
 
SQL> DESC VIEW_NULL; 
 Name                            Null?    Type 
 ------------------------------- -------- ---- 
 CAMPO_NULL                               VARCHAR2(0) 
 
SQL>  
charlesmafra
Rank: Estagiário Sênior
Rank: Estagiário Sênior
Posts: 8
Joined: Thu, 19 Aug 2004 9:45 am
Location: Angola
Contact:
Charles Mafra
Oracle Developer

Disagree, null is null, null is not equal to a varchar2 (0);
See this

Select all

SQL> declare 
  2  a varchar2(0) default null; 
  3  begin 
  4  null; 
  5  end; 
  6  / 
a varchar2(0) default null; 
           * 
ERRO na linha 2: 
ORA-06550: linha 2, coluna 12: 
PLS-00215: Restrições do comprimento das cadeias de car. devem estar dentro do 
intervalo (1 .. 32767)

Complementing ... Why is NULL a number then?

Select all

  1  CREATE OR REPLACE VIEW VIEW_NULL AS 
  2      SELECT 
  3        NULL CAMPO_NULL 
  4        ,TO_NUMBER(NULL) CAMPO_NULL_NUMERICO 
  5* FROM DUAL 
SQL> / 
 
Vista criada. 
 
SQL> DESC VIEW_NULL; 
 Nome                                      Nulo?    Tipo 
 ----------------------------------------- -------- ---------------------------- 
 CAMPO_NULL                                         VARCHAR2 
 CAMPO_NULL_NUMERICO                                NUMBER
User avatar
tfg
Rank: Analista Júnior
Rank: Analista Júnior
Posts: 83
Joined: Mon, 03 May 2004 3:38 pm
Location: Novo Hamburgo - RS

Interesting this topic ... (looks like those philosophy classes where it debates "what is nothing")
but not wanting to put more wood in the fire, see the pl below:

Select all

THO> DECLARE 
  2    A VARCHAR2(10); 
  3  BEGIN 
  4    A:=''; 
  5    IF A IS NULL 
  6    THEN DBMS_OUTPUT.PUT_LINE('Esse é null!'); 
  7    END IF; 
  8  END; 
  9  / 
 
PL/SQL procedure successfully completed. 
 
THO> SET SERVEROUTPUT ON 
THO> / 
Esse é null! 
 
PL/SQL procedure successfully completed. 
 
THO> 
But I agree with Charlesmafra. I also think null is null. (This example I quoted above does not change my opinion)

.
charlesmafra
Rank: Estagiário Sênior
Rank: Estagiário Sênior
Posts: 8
Joined: Thu, 19 Aug 2004 9:45 am
Location: Angola
Contact:
Charles Mafra
Oracle Developer

As you can see in your example, if we take the assignment you did, it continues to say that "the" is null.

Poruqe The variable is initialized with NULL automatically ...

Write
to VARCHAR2 (10); It is equal to
to varchar2 (10): = null; and equal to
to VARCHAR2 (10) default NULL;

Select all

 
  1  DECLARE 
  2        A VARCHAR2(10); 
  3      BEGIN 
  4        --A:=''; 
  5        IF A IS NULL 
  6        THEN DBMS_OUTPUT.PUT_LINE('Esse é null!'); 
  7        END IF; 
  8*     END; 
SQL> / 
Esse é null! 
 
Procedimento de PL/SQL concluído com êxito. 
 
SQL> 
When you did "A: = ''" You do not attach a blank, you just opened and closed quotation marks, you will agree with me that This is not "nothing" or null.
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 16 guests