How to check empty string and null? Assign same value to multiple variables

Hi,
1.
How do I check for empty string and null?
in_value IN VARCHAR2
2. Also how do I assign same value to multiple variables?
var_one NUMBER := 0;
var_two NUMBER := 0;
var_one := var_two := 0; --- Gives an error
Thanks

MichaelS wrote:
Not always: Beware of CHAR's:
Bug 727361: ZERO-LENGTH STRING DOES NOT RETURN NULL WHEN USED WITH CHAR DATA TYPE IN PL/SQL:
SQL> declare
  2    l_str1   char (10) := '';
  3    l_str2   char (10) := null;
  4  begin
  5  
  6    if l_str1 is null
  7    then
  8      dbms_output.put_line ('oh STR1 is null');
  9    elsif l_str1 is not null
10    then
11      dbms_output.put_line ('oh STR1 is NOT null');
12    end if;
13  
14    if l_str2 is null
15    then
16      dbms_output.put_line ('oh STR2 is null');
17    elsif l_str2 is not null
18    then
19      dbms_output.put_line ('oh STR2 is NOT null');
20    end if;
21  end;
22  /
oh STR1 is NOT null
oh STR2 is null
PL/SQL procedure successfully completed.
SQL> alter session set events '10932 trace name context forever, level 16384';
Session altered.
SQL> declare
  2    l_str1   char (10) := '';
  3    l_str2   char (10) := null;
  4  begin
  5  
  6    if l_str1 is null
  7    then
  8      dbms_output.put_line ('oh STR1 is null');
  9    elsif l_str1 is not null
10    then
11      dbms_output.put_line ('oh STR1 is NOT null');
12    end if;
13  
14    if l_str2 is null
15    then
16      dbms_output.put_line ('oh STR2 is null');
17    elsif l_str2 is not null
18    then
19      dbms_output.put_line ('oh STR2 is NOT null');
20    end if;
21  end;
22  /
oh STR1 is null
oh STR2 is null
PL/SQL procedure successfully completed.
SQL> SY.

Similar Messages

  • Varchar2, empty strings and NULL

    Hi all,
    When inserting an empty string into a column of type varchar2 - is a NULL value stored in the column by the database? I've seen conflicting reports, and I know that the SQL 1992 spec specifies that empty strings not be treated as a NULL value, but that Oracle has traditionally treated zero length strings stored in a varchar2 column as NULL.
    So, is there a way to store an empty string in a varchar2 column as an empty string and not a NULL value?
    TIA,
    Seth

    It can be even more complicated or annoying than NULL not equal to ASCII NULL.
    example:
    create table test_null
    (fld1 varchar2(10),
    fld2 varchar2(10),
    fld3 varchar2(20));
    insert into test_null values (chr(0),null, 'chr(0) and null');
    insert into test_null values (null, null, 'null and null');
    insert into test_null values ('', chr(0), ''''' and chr(0)');
    insert into test_null values ('', null, ''''' and null');
    select * from test_null;
    FLD1       FLD2       FLD3
                          chr(0) and null
                          null and null
                          '' and chr(0)
                          '' and null
      1  DECLARE
      2  BEGIN
      3   for c1 in (select fld1, fld2, fld3 from test_null) loop
      4      if c1.fld1 = c1.fld2 then
      5         dbms_output.put_line(c1.fld3||' Are equal'||
      6                '  Length fld1 = '||to_char(length(c1.fld1))||
      7                ' Length fld2 = '||to_char(length(c1.fld2)));
      8      else
      9         dbms_output.put_line(c1.fld3||' Are NOT equal'||
    10                '  Length fld1 = '||to_char(length(c1.fld1))||
    11                ' Length fld2 = '||to_char(length(c1.fld2)));
    12      end if;
    13      dbms_output.put_line(' ');
    14   end loop;
    15*  END;
    SQL> /
    chr(0) and null Are NOT equal  Length fld1 = 1 Length fld2 =
    null and null Are NOT equal  Length fld1 =  Length fld2 =
    '' and chr(0) Are NOT equal  Length fld1 =  Length fld2 = 1
    '' and null Are NOT equal  Length fld1 =  Length fld2 =
    PL/SQL procedure successfully completed.

  • Empty string and NULL value

    Hi,
    Does oracle treat empty string as NULL.
    If it is so,Can we force db to treat both as different things.
    Thanx

    11g.DBA wrote:
    Hi,
    Does oracle treat empty string as NULL.Yes.
    If it is so,Can we force db to treat both as different things.No.
    Please read in SQL Reference:
    http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements005.htm#SQLRF3003

  • How to read a string from file & assign the val to a variable in batch file

    Hi,
    How to read a string from a file and assign the value to a variable then return the value to the screen in windows batch file?
    Any suggestions?
    thanks.

    Unless this is a homework question then I don't see the purpose of doing this, but....
    You should be looking a the supplied package utl_file to get the string out of the file, dbms_output to display the string and then google windows batch/command files calling sqlplus to execute your program.
    Andre

  • Distinguishing between empty string and null values

    hi all,
    I am using an ODBC connection to connect my java app to database using JDBCODBC driver. I have 2 columns 'aColumn' and 'bColumn' in my table, both allow null values. I have one row in it, which has null value in aColumn and empty string in bColumn. I retrieve this row's data and assign it to 2 columns : 'aColumnVar' and 'bColumnVar' respectively. I find out that both 'aColumnVar' and 'bColumnVar' variables has null values (although bColumnVar should has an empty string as its value). Now my ODBC connection Data Source has the option "Use ANSI nulls, paddings, and warnings" ON. I turn it off and try again. This time both 'aColumnVar' and 'bColumnVar' variables has empty string as values (although aColumnVar should has null as its value).
    How can I make sure that i can get the data exactly as it is in the database in my variables?
    Thanks

    there is a wasNull() method on ResultSet. After you
    have obtained the value of a column e.g. by calling a
    method like getString you can call wasNull and if it
    returns true then the value on the database is null.
    Check the java docs, it might explain it better
    http://java.sun.com/j2se/1.4.1/docs/api/java/sql/Result
    et.html#wasNull()I am using MS SQL Server 7.0 under Windows NT 4.0 with JDK 1.2. My ODBC connection Data Source has to have the option "Use ANSI nulls, paddings, and warnings" ON.
    I try the wasNull() method but it is doing the same thing i.e. telling me that a column is null when in database it is null (right); and a column is null when in database it is an empty string (wrong). I suspect it is something to do with the JDBC-ODBC driver I am using.

  • Is empty string and Null same?

    create table x
    (empid number);
    Table created.
    insert into x values ('');
    1 row created.
    insert into x values (null);
    1 row created.
    SQL> set null <<>>
    SQL> select * from x;
         EMPID
    <<>>
    <<>>So i can safely change an Insert statement like
    insert into x values ('');to
    insert into x values (null);Right?

    michaels2 wrote:
    char pads with spaces to the length of the data itemdon't think so - at least not on my 11.2.0.1.0Good. Oracle finally fixed it. Before 11.2 it was pretty much as ajallen noted:
    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
    PL/SQL Release 11.1.0.6.0 - Production
    CORE    11.1.0.6.0      Production
    TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
    NLSRTL Version 11.1.0.6.0 - Production
    SET SERVEROUTPUT ON
    DECLARE
        flag CHAR(2);
        PROCEDURE check_null (p_flag IN CHAR)
        IS
        BEGIN
          IF p_flag = '  '
            THEN
              dbms_output.put_line ('flag is equal to ''  ''');
            ELSIF p_flag IS NULL
              THEN
                dbms_output.put_line ('flag is null');
            ELSE
              dbms_output.put_line ('other');
          END IF;
        END;
    BEGIN
        flag := '';
        check_null (flag);
        flag := NULL;
        check_null (flag);
    END;
    flag is equal to '  '
    flag is null
    PL/SQL procedure successfully completed.
    alter session set events '10932 trace name context forever, level 16384';
    DECLARE
        flag CHAR(2);
        PROCEDURE check_null (p_flag IN CHAR)
        IS
        BEGIN
          IF p_flag = '  '
            THEN
              dbms_output.put_line ('flag is equal to ''  ''');
            ELSIF p_flag IS NULL
              THEN
                dbms_output.put_line ('flag is null');
            ELSE
              dbms_output.put_line ('other');
          END IF;
        END;
    BEGIN
        flag := '';
        check_null (flag);
        flag := NULL;
        check_null (flag);
    END;
    flag is null
    flag is null
    PL/SQL procedure successfully completed.
    SQL>
    Bug 727361: ZERO-LENGTH STRING DOES NOT RETURN NULL WHEN USED WITH CHAR DATA TYPE IN PL/SQL
    SY.

  • Null and empty string not being the same in object?

    Hello,
    I know that null and empty string are interpreted the same in oracle.
    However I discovered the strange behaviour concerning user defined objects:
    create or replace
    TYPE object AS OBJECT (
    value VARCHAR2(2000)
    declare
    xml xmltype;
    obj object;
    begin
    obj := object('abcd');
    xml := xmltype(obj);
    dbms_output.put_line(xml.getStringVal());
    obj.value := '';
    xml := xmltype(obj);
    dbms_output.put_line(xml.getStringVal());
    obj.value := null;
    xml := xmltype(obj);
    dbms_output.put_line(xml.getStringVal());
    end;
    When creating xml from object, all not-null fields are transformed into xml tag.
    I supposed that obj.value being either '' or null will lead to the same result.
    However this is output from Oracle 9i:
    <OBJECT_ID><VALUE>abcd</VALUE></OBJECT_ID>
    <OBJECT_ID><VALUE></VALUE></OBJECT_ID>
    <OBJECT_ID/>
    Oracle 10g behaves as expected:
    <OBJECT><VALUE>abcd</VALUE></OBJECT>
    <OBJECT/>
    <OBJECT/>
    However Oracle 9i behaviour leads me to the conclusion that oracle
    must somehow distinguish between empty string and null in user defined objects...
    Can someone clarify this behaviour?
    Thus is it possible to test if object's field is empty or null?

    However Oracle 9i behaviour leads me to the conclusion that oracle
    must somehow distinguish between empty string and null in user defined objects...
    Can someone clarify this behaviour?
    Thus is it possible to test if object's field is empty or null?A lot of "fixes" were done, relating to XML in 10g and the XML functionality of 9i was known to be buggy.
    I think you can safely assume that null and empty strings are treated the same by Oracle regardless. If you're using anything less than 10g, it's not supported any more anyway, so upgrade. Don't rely on any assumptions that may appear due to bugs.

  • How to differentiate the EMPTY Records and Null Values in DSO

    Hello....how is everyone here?? Ehehehe!
    I try to load some data from the flat file which contains some EMPTY data and Null Values for the records. The data type for the InfoObjects of the fields "Quantity" is "number". The sample data from the flat file (CSV) are as below:
    Food              Quantity
    Hamburger  -       12
    Cheese        -       0
    Vegetable      -               (Empty)
    When I try to load the above sample data to the DSO, I get the results of the data as follow:
    Food              Quantity
    Hamburger     - 12.000
    Cheese           -  0.000
    Vegetable         - 0.000
    In this case, how can the user differentiate whether the records is contain empty value of null values in DSO? This is kinda of hard to differentiate the both scenarios above. Is there any way to differentiate the scenarios described here?
    Thanks alot =)

    Hi Fluffy,
    It depends on the initial values of the data type
    The inital values For quantity/Currency/ Numbers it takes spaces as 0
    for char it is SPACE
    We cannot differeniate between space and null values.
    IF you have to force this then define quantity as char and load the data. we will not have units and aggregation in this case.
    Hope this helps.
    PV

  • How to force simple tags and null attributes to appear when using SQL/XML?

    Hello everybody:
    I'm developing a non-schema based XMLType view.
    When the XML document is generated, i noticed two things I need to manage in order to achieve the desired result:
    1. Oracle generates a <tag></tag> pair for each XMLELEMENT defined; in my case, some tags need to appear as <tag/>... how do I do? Is it possible when using schema based XMLType views? Is it possible while using a non-schema approach?
    2. When using XMLATTRIBUTE('' AS "attribute") or XMLATTRIBUTE(NULL AS "attribute"), no one attribute with label "attribute" and null value appears at the output; how do I force to Oracle DB to render those attributes which are with no values (needed to render those attributes as another parsing code will await for all the items)?
    3. Some tip about how to route the output to an XML text disk file will be appreciated.
    Thanks in advance.
    Edited by: Enyix on 26/02/2012 11:21 PM
    Edited by: Enyix on 26/02/2012 11:22 PM

    Hello odie_63, thanks for your reply:
    Reasons why needed single tags are these two next: Needed to generate a single XML file from 50,000,000 rows, where the XML ouput matches not only row data but another default values for another elements and attributes (not from database but using strings and types with default values); by using start and end tag, the generated file is as much twice bigger than using single tags; second, needed a very precise presentation for all the document.
    For generating that document, currently focus is based on using a batch process relying on Spring Batch with using a single JDBC query where a join happens between two tables. From my point of view, that approach uses: database resources, network resources, disk resources, and processing resources, including the price of making the join, sending to network, creating objects, validating, and making the file (Expending too much time generating that XML file). That processs currently is in development.
    I think possibly another approach is delegating the complete generation of that file to the database using its XML capabilities. My current approach following your recomendations is to generate a clob where I will put all the XML and putting it into a table. It leads me to another issues: Considering limitations on memory, processing and disk space, needed to append a single row-as-xml into the clob as soon as possible, and putting the clob inside the field as soon as possible, or putting the clob inside the field, and appending into it as the data is generated; so How do I manage the process in order to achieve that goals?. Seen these issues aren't related to my original question, so I'll open a new post. Any help will be apreciated.
    Thanks again in advance.

  • ORACLE treats empty Strings as NULL, Any workaround?

    Hi,
    ORACLE treats empty Strings as NULL.
    I am writing, rather modifying Java code to make it work with both SQLServer and Oracle. Since our code is already working for SQLServer, now I have the problem in porting to Oracle wherever I have empty strings. I used to insert empty strings into coulumns in SQLServers, the same SQLs give errors in SQL Server.
    Any workaround on the DB end or in JDBC for this?
    Thanks in advance,
    Suresh
    [email protected]

    jschell wrote:
    nichele wrote:
    jwenting wrote:
    If NULL really is different in your context from an empty string you're going to have to define some sequence of characters as indicating an empty string.yes, this is what i need to implement.Sounds like a flawed design then.
    I'm wondering what's the best approach in order to avoid to change all my application isolating this behavior somewhere (wrapping the jdbc driver for instance).That doesn't make much sense to me. You should already have a database layer. You change the database layer. If you don't have a database layer then that means you have another design flaw. And in that case I would really not be the one that needs to maintain that code base.I thought a bit about the value of your answer...but i didn't find it ....sorry but i don't like who replies on forum just to say bad design/bad choice etc...if you have any kind of suggestion you are welcome, otherwise you can spend your time in doing something else instead of reply to this thread.

  • How to check the BW and BIA systems are up and working fine.

    Hi friends,
    how to check the BW and BIA systems are up and working fine. And also what is ICM, how to check whether it is working properly or not.
    ANd what is name resolution and IP , how to check whether this is running fine.
    regards, balu.

    Hi,
    you can use process monitoring or the alert function in the standalone TREXAdmin tool.
    ICM:
    http://help.sap.com/saphelp_nw04/helpdata/EN/0a/a7903febb15a7be10000000a11405a/content.htm
    name resolution
    http://en.wikipedia.org/wiki/Domain_Name_System
    IP:
    http://en.wikipedia.org/wiki/IP
    Please also have a look at the transactions TREXADMIN and RSDDBIAMON2.
    I think it´s better if you use the forum search and google/wikipedia before you ask such questions.
    Best Regards,
    Jens

  • How to Break this String and put into a Table

    Hi all,
    Currently i working on the Reading of Csv file.THe Csv file wil be stored as BLOB in one table.
    The Format of the Csv file is
    EMPCODE :DATEOFBIRTH
    312089 ,12/01/1984
    321456 ,03/05/1980
    120212 ,04/08/1987
    312456 ,23/12/1977
    311110 ,12/04/1998
    323232 ,20/06/1990
    UPLOAD_BLOB
    column     Datatype
    UploadId Number
    File_details BLOB
    And i reading the BLOB in one procedure and i m getting the String as like this ---->
    "312089 ,12/01/1984
    321456 ,03/05/1980
    120212 ,04/08/1987
    312456 ,23/12/1977
    311110 ,12/04/1998
    323232 ,20/06/1990"
    I am Dont know how to Parse this String and put in table
    While 1<STRING.LENGTH
    LOOP
    EMPCODE=SUBSTRING();
    DATEOFBIRTH=SUBSTRING();
    INSERT INTO TABLE VALID_EMPCODE(EMPCODE,DATEOFBIRTH)VALUES(......);END LOOP
    VALID_EMPCODE
    EMPCODE VARCHAR2(30)
    DATEOFBIRTH VARCHAR2(15)
    Can any one tell me how to parse this whole string and break them

    Duplicate post
    How to Break this String and put into a Table

  • How could i parse string and link its model with my files in eclipse project?

    How could i parse string and link its model with my files in eclipse project?, as i read that we dont have to use standalone mode while working with eclipse projects.
    Example of what i want to do:
    I have file1.dsl in my project which contains some statements but the declaration of these statements are not in another file, i need to put them only in my code

    Hi Stefan,
    I have eclipse project contains 2 files, file1.dsl and file2.dsl, you can see the contents of the files below.
    file1.dsl contains some statements as shown below and file2.dsl contains the declarations of the variables. (like in C++ or Java we have declarations and usage)
    At this step file1.dsl and file2.dsl will be parsed successfully without any errors.
    Lets imagine that we will delete this project and will create another one and the new project will contain only file1.dsl (which contains the usage)
    At this step this file (file1.dsl) will contains some errors after parsing it, because we are using variables without declarations.
    So what i need is to parse the content of file2.dsl directly without adding this file to the project.
    I need to add the content of file2.dsl directly as a string in the code and parse it. just like that ( "int a;int b;" )
    And link file1.dsl with the model generated after parsing my string
    file1.dsl
    a++;
    b++;
    file2.dsl
    int a;
    int b;
    Thanks

  • How to check the memory and CPU usage on NPU

    Hi expert ,
    Could you tell me how to check the memory and cpu usage on NPU?
    I think ASR1000 has this command (show platform hardware qfp active...) , but I coudn't find the same command on ASR9001.
    I checked " show controllers np counters all"  command, but I did not find it.
    Platform: ASR9001
    version: 4.3.2
    NP: Tyhoon
    Thanks,

    Hi Kanako,
    understand your question, but something like that doesnt exist for the trident/typhoon NPU's for the asr9k.
    in fact cpu usage is not really applicable for parallel/serialized hardware forwarders, but mainly the KPI is here
    the PPS it handles.
    The max pps it can handle is dependent on feature set.
    What you could do is measure the rates on the PARSE_FABRIC_RECEIVE count (packets received from fabric, so egress direction), PARSE_ENET_RECEIVE count (packets received from the interface to the fabric, so ingress) and the LOOPBACK count, that is packets that are recirculated for extra processing. The sum of these 3 gives an idea of the PPS rate the NPU is working on.
    Memory consumption is something tricky also, there are many memories attached to the NPU, notably:
    TCAM used for vlan matching, ACL and QOS matching
    Search memory for L2 and L3 (shared on Trident, separated on Typhoon)
    Frame memory for packet bufferin in QOS
    Stats memory, for all kinds of counters of QOS maps, interface stats etc
    their usage is rather dynamic also.
    The few things you want to verify on these are:
    - ACL usage (in terms of Tcam entries)
    - MAC table size (2M max on typhoon)
    - FIB size (4M max on typhoon)
    frame memory is dependent on the buffering, which is a sum of all the packets instant queue length and size of all pmaps attached to interfaces served by the same NPU. there is no good overview as to how much you have available of that, but it has a rather significant size 1G or 2G depending on the TR or SE cards (typhoon specific).
    regards
    xander
    Xander Thuijs CCIE #6775
    Principal Engineer 
    ASR9000, CRS, NCS6000 & IOS-XR

  • How to check relation between two tables in same database

    How to check relation between two tables in same database using Oracle SQL developer. Version 2.1.1.64

    Hi,
    Try this,
    SELECT   cons.owner AS child_owner, cons.table_name AS child_table,
             cons.constraint_name constaint_name,
             cons.constraint_type constraint_type, col.owner parent_owner,
             col.table_name parent_table, col.column_name column_name
        FROM dba_cons_columns col, dba_constraints cons
       WHERE cons.r_owner = col.owner
         AND cons.r_constraint_name = col.constraint_name
         AND col.owner = 'MY_USER'
    ORDER BY child_table;Thanks,
    Shankar

Maybe you are looking for