Comparing Null values in PL/SQL with varchar2

Comparing Null values in PL/SQL with varchar2

Post by Thomas Kyt » Sun, 05 Sep 1999 04:00:00




(if that email address didn't require changing)


>I'm searching for an elegant way to compare two varchar2 vars, what i want
>is this

>var1    var2    result
>''           ''            true
>null        null       true
>'aa'        'aa'        true
>'a'            'b'        false

>when using nvl() like this:

>a varchar2(10);
>b varchar2(10);

>if nvl(a,'blabla') = nvl(b,'blabla')
>then
>  et etc.

>i always have to be sure that b or a cannot be 'blabla', can anybody tell me
>what a better solution is, WITHOUT writing all the code out ( if a is null )
>?????

write a function:


varchar2 ) return
  2  boolean
  3  as
  4     return_val boolean default FALSE;
  5  begin
  6     if ( p_str1 = p_str2 ) then
  7         return_val := true;
  8     elsif ( p_str1 is null and p_str2 is null ) then
  9         return_val := true;
 10     end if;
 11     return return_val;
 12  end;
 13  /

Function created.



  2      v1    varchar2(5) default 'aa';
  3      v2    varchar2(5) default 'aa';
  4  
  4      procedure testit
  5      is
  6      begin
  7          if ( compvc( v1, v2 ) ) then
  8              dbms_output.put_line( '"'||v1||'" = "'||v2||'"' );
  9          else
 10              dbms_output.put_line( '"'||v1||'" <> "'||v2||'"' );
 11          end if;
 12      end;
 13  begin
 14      testit;
 15      v1 := ''; v2 := '';
 16      testit;
 17      v1 := null; v2 := null;
 18      testit;
 19      v1 := 'a'; v2 := 'b';
 20      testit;
 21  end;
 22  /
"aa" = "aa"
"" = ""
"" = ""
"a" <> "b"

PL/SQL procedure successfully completed.


>greetings and thanks in advance Jeroen

--
See http://govt.us.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'...
Current article is "Part I of V, Autonomous Transactions" updated June 21'st


Oracle Service Industries     Reston, VA   USA

Opinions are mine and do not necessarily reflect those of Oracle Corporation

 
 
 

Comparing Null values in PL/SQL with varchar2

Post by fumi » Mon, 06 Sep 1999 04:00:00



> I'm searching for an elegant way to compare two varchar2 vars, what i want
> is this

> var1    var2    result
> ''           ''            true
> null        null       true
> 'aa'        'aa'        true
> 'a'            'b'        false

> when using nvl() like this:

> a varchar2(10);
> b varchar2(10);

> if nvl(a,'blabla') = nvl(b,'blabla')
> then
>   et etc.

> i always have to be sure that b or a cannot be 'blabla', can anybody tell me
> what a better solution is, WITHOUT writing all the code out ( if a is null )
> ?????


> greetings and thanks in advance Jeroen

Hi, Jerone,
You can use:

    if a||'blabla'=b||'blabla' then

 
 
 

1. Oracle PL/SQL giving null values a numeric value in a stored proceedure

I am hoping I can get someone to give me some insite on a stored
proceedure I am writing.
I have a table that was created by the all knowing contractors within
an Oracle database in an Arbor Billing System.
The table was created and a primary key was set for a numbering scheme
from aproximatly 32,000 to -32,000 except that the numbers are only
created when a row is created in the table.
The problem I have is that there are different number ranges being
used randomly for row entries and null values in between.

I am tring to create a stored proceedure to assighn numeric values to
the random Null values in the sequence of the table.

I have had a couple of Ideas one of which was to create another table
with all of the numbering sequence in tact and have and inner join
pull the values from that table where the value IS NULL for the table
in question.

2. IQ Software

3. Null values and Varchar2 fields

4. Opening an access database from vb

5. Fastest query in PL/SQL function when values can be NULL

6. On key label help

7. How to compare null value

8. 16722-DE-Wilmington-Visual Basic-Visual C++-SQL-Document Management-Developer

9. comparing data with NULL values

10. Compare NULL value in WHERE clause

11. compare null values

12. handling NULL values when comparing 2 columns

13. PL/SQL - IN OUT PARAMETER problem: ORA-06502: PL/SQL: Numeric or value error