Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Commands to get oracle server info.

jjkSep 11 2008 — edited Sep 11 2008
Hello everybody,
Could anybody tell me the commands that can get us various server details
(like server version etc etc ...) or how can we get the server environment details ?

Comments

Prazy
Till now Oracle treats Null and empty string as equal. ie. empty string is also considered as null in Oracle.
select nvl(null,'Yes, Null it is!') A,nvl('','Oops!, I am null too') B from dual;

A                B
---------------- --------------------
Yes, Null it is! Oops!, I am null too

Elapsed: 00:00:00.00
Regards,
Prazy
Centinul
Do you mean blank (as in space ASCII character # 32) or an empty string? In Oracle NULL and empty strings are treated the same.

Check out this link for a worked out example:

Oracle/PLSQL: Difference between an empty string and a null value
Twinkle
Hi,

Below link may help you
http://www.techonthenet.com/oracle/questions/empty_null.php


Twinkle
NeilCSE
Yes I was talking about '' and not ' '

Thanks all
aak
Sven W.
user605246 wrote:
Hi All,

Is the below right?

NULL is not stored as a value in a field. Its an internal bit that is set to indicate that the value is unknown.
Blank is stored as a value in the field. Because of that we can perform all kinds of comparisons with blank value, while we cant do the same with NULLs

Regards,
aak
In general this is not right.

The value of a field can be NULL. If the field is a varchar2 field then '' and NULL are equal, both represent an empty field.
A blank ' ' is stored as a blank and is not empty (ascii char 32).

There is a slight difference between '' and NULL. For '' the datatype is known, but for NULL it is not. This makes a difference in certain expressions where a type conversion is needed. However NULL with datatype can be written like this: CAST(NULL as varchar2(10))
Twinkle
Hi,
SQL> create table chk
  2  (id number,
  3  t varchar2(10));

Table created.

SQL> insert into chk values(1,'');

1 row created.

SQL>  insert into chk values(2,'');

1 row created.

SQL> insert into chk values(3,null);

1 row created.

SQL> commit;
SQL> select * from chk
  2  where t is null;

        ID T
---------- ----------
         1
         2
         3

SQL> select * from chk
  2  where t = '';

no rows selected

SQL> insert into chk values('','T');

1 row created.

SQL> select * from chk;

        ID T
---------- ----------
         1
         2
         3
           T
Twinkle
MichaelS
difference between NULL and ''
there are some rare occasions where NULL and '' are not treated the same though:
SQL> declare
 var char(1) := null;
 ret integer;
begin
 ret := anydata.convertchar(var).getchar(var);
 dbms_output.put_line('Length: ' || length(var));
end;
/
Length: 
PL/SQL procedure successfully completed.
but
SQL> declare
 var char(1) := '';
 ret integer;
begin
 ret := anydata.convertchar(var).getchar(var);
 dbms_output.put_line('Length: ' || length(var));
end;
/
Length: 1
PL/SQL procedure successfully completed.
John Spencer
user605246 wrote:
Hi All,

Is the below right?

NULL is not stored as a value in a field. Its an internal bit that is set to indicate that the value is unknown.
Blank is stored as a value in the field. Because of that we can perform all kinds of comparisons with blank value, while we cant do the same with NULLs

Regards,
aak
You are corerct in that NULL is not stored as a value in a field, but sorta/kinda wrong that it is an internal bit set to indicate that the value is unknown.

If the NULL column(s) is/are the last column(s) in the table, then null values are not stored at all. The basic structure of a row stored on disk is (highly simplified)
col1length|col1data|col2length|col2data|col3length|col3data
So, given a row with col1 = 'ABC', col2 = 'Hello' and col3 null what is stored is:
3|ABC|5|Hello
However, if col2 is null and col 3 = 'Hello' then what is stored is:
3|ABC|0|5|Hello
So the length byte is set to 0 to indicate that the column is null. Although the actual storage mechanisims for other data types differ from varchar2 example above, the 0 valeu i nthe length byte always indocates a null, and trailing null columns take 0 bytes of storage.

John
Nicosa-Oracle
there are some rare occasions where NULL and '' are not treated the same though:
Your example is biased, consider this :
SQL> ed
Wrote file afiedt.buf

  1  declare
  2   var char(1) := '';
  3   ret integer;
  4  begin
  5   dbms_output.put_line('var: -' || var ||'-');
  6   ret := anydata.convertchar(var).getchar(var);
  7   dbms_output.put_line('Length: ' || length(var));
  8* end;
SQL> /
var: - -
Length: 1

PL/SQL procedure successfully completed.
notice the space between the 2 minus signs ?
a char is not a varchar2...
Sven W.
Nicosa wrote:
there are some rare occasions where NULL and '' are not treated the same though:
Your example is biased, consider this :
...
notice the space between the 2 minus signs ?
a char is not a varchar2...
So you proved what?

Michaels clearly showed an example where the use of '' and NULL will give different results.
He also mentioned that this is a rare case. I can give other examples with varchar2. Those are rare too.
And biased only so far as they are ment to show the exception from the rule.
MichaelS
Your example is biased
Makes it even more pronounced and simpler to proof:
SQL> declare
   var            char (1) := '';
   var2           char (1) := null;
begin
   dbms_output.put_line ('Length var: ' || length (var));
   dbms_output.put_line ('Length var2: ' || length (var2));
end;
/
Length var: 1
Length var2: 
PL/SQL procedure successfully completed.
Notice there's no space in the definition of var!
Nicosa-Oracle
So you proved what?
Makes it even more pronounced and simpler to proof:
(...)
Notice there's no space in the definition of var!
;)
Yes, I misunderstood at first what you were showing.
All my apologizes.

I did react on the use of char more than on the behavior of null.
(To me char is a dead/deprecated type... what you showed wouldn't happen with a varchar2)

Edited by: Nicosa on Mar 30, 2010 7:01 AM
445476
Notice there's no space in the definition of var!
Doesn't need to be; the CHAR is a fixed width field - it is automatically padded to 1 char wide when receiving a value. The point being made is that an empty varchar2 when assigned to a char, will be padded out to a string of length 1, whereas a null when assigned to a char, is not padded (because it is the concept of nothing within the context of char)
1 - 13
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Oct 9 2008
Added on Sep 11 2008
3 comments
454 views