Use of DECODE and NULL value in a WHERE clause

hi all,
I came into an issue trying to use the DECODE function in a simple where clause.
this is my test case
CREATE TABLE tab_test (lev NUMBER, code VARCHAR2(10), val VARCHAR2(10));
INSERT INTO tab_test VALUES (1, NULL, 'val11');
INSERT INTO tab_test VALUES (1, NULL, 'val12');
INSERT INTO tab_test VALUES (1, '13', 'val13');
INSERT INTO tab_test VALUES (2, '21', 'val21');
INSERT INTO tab_test VALUES (1, '22', 'val22');
INSERT INTO tab_test VALUES (1, '23', 'val23');
and this is the query
SELECT * FROM tab_test WHERE code = DECODE(:lev,1,NULL,:cod)
as you can see running this query, setting :lev to 1 will return an empty record set, instead of the expected first two rows (as it will be, running "select * from tab_test where code is null").
is there a way to overcome this issue? thanks for help

hi Frank,
I can confirm that the queries do work when run on TOAD, but do not when they are put in the WHERE clause of my data block. I guess the problem relies on some data block setting; I should investigate on Forms forum.
Anyway, here is my test case, including data and some examples. You can realize that it works good
CREATE TABLE TAB_TEST
LEV NUMBER,
CODE VARCHAR2(10 BYTE),
VAL VARCHAR2(10 BYTE)
Insert into tab_test
(LEV, CODE, VAL)
Values
(3, 'val21', 'val3_211');
Insert into tab_test
(LEV, CODE, VAL)
Values
(2, 'val21', 'val3_212');
Insert into tab_test
(LEV, VAL)
Values
(1, 'val11');
Insert into tab_test
(LEV, VAL)
Values
(1, 'val12');
Insert into tab_test
(LEV, VAL)
Values
(1, 'val13');
Insert into tab_test
(LEV, CODE, VAL)
Values
(2, 'val11', 'val21');
Insert into tab_test
(LEV, CODE, VAL)
Values
(2, 'val12', 'val22');
Insert into tab_test
(LEV, CODE, VAL)
Values
(2, 'val13', 'val23');
COMMIT;
SELECT * FROM TAB_TEST
CONNECT
BY PRIOR val = code
START WITH (CASE
WHEN :LIV = 1 AND code IS NULL THEN 'OK'
WHEN :LIV != 1 AND code = :COD THEN 'OK'
END = 'OK')
               AND VAL = :V
:LIV = 1
:COD = [any]
:V = 'val11'
LEV     CODE     VAL
1          val11
2     val11     val21
3     val21     val3_211
3     val21     val3_212
:LIV = 1
:COD = [any]
:V = 'val12'
LEV     CODE     VAL
1          val12
2     val12     val22
:LIV = 2
:COD = 'val11'
:V = 'val21'
LEV     CODE     VAL
2     val11     val21
3     val21     val3_211
2     val21     val3_212

Similar Messages

  • Issue with using N'...' values in a where clause against a function index

    We have a table that is defined with non Unicode columns with a UPPER(..) function index on the index column (to allow searching in any alphabetic case)
    e.g.
    create table my_table
    index_column varchar2(20),
    desc_column varchar2(40)
    create index my_table_idx as on my_table(UPPER(index_column));
    there is approx. > 10 million rows in this table
    The issue we have is that when we do the following select
    select index_column, desc_column from my_table
    where upper(index_column) = 'SOME VALUE'; this statement runs in approx 0.03 seconds which is great
    But we also have some statements that run as
    select index_column, desc_column from my_table
    where upper(index_column) = N'SOME VALUE'; notice the N'...' string (unicode) value used. This ends up doing a full table scan (> 5 seconds)
    So... the question is how can i make this select statement passing in a Unicode string value hit this function based UPPER index? Is there anyway?
    I have tried these extra indexes - to no avail
    create index my_table_idx as on my_table(UPPER(CAST(index_column as nvarchar2(20)));
    and
    create index my_table_idx as on my_table(UPPER(COMPOSE(index_column)));
    I assumed Oracle should have done and implicit conversion back to a non unicode string value and then passed that value into the UPPER(...) function index, but it appears as though Oracle isn't recognizing that the column is a different type (varchar2 vs nvarchar2)
    Any help greatly appreciated?

    Horrible amount of irrelevant tags, and the only thing relevant , the four digit version, is of course not mentioned.
    Also the characterset of the database is relevant.
    As far as I know in 11g and higher one no longer needs the N'<string construct>'
    As to implicit conversion
    assume <number_column> = '9'
    Oracle always converts this into
    to_char(<number_column>='9'
    Same applies to your case.
    Try leaving out the N, check whether it works and whether your function based index is used.
    Sybrand Bakker
    Senior Oracle DBA

  • How to use dynamically column_name and column_name value in plsql procedure

    hi,
    how to use dynamically column_name and column_name value in plsql procedure.
    for example, i have one table with column col1.i want write plsql code with dynamically execute the insert one schema to another schema.
    by
    siva

    DECLARE
    CURSOR C
    IS
    SELECT cc_cd
    FROM TEMP1 WHERE s_flg ='A' AND b_num IN('826114');--,'709537','715484');
    CURSOR D
    IS
    SELECT * FROM cONSTRAINTS_test ORDER BY SRL_NUM;
    STMT VARCHAR2(4000);
    p_target_schema VARCHAR2(30):='schema1';
    p_source_schema VARCHAR2(30):='schema2';
    BEGIN
    FOR REC IN C
    LOOP
    FOR REC1 IN D
    LOOP
    STMT := 'INSERT INTO '||p_target_schema||''||'.'||''||REC1.CHILD_TABLE||' SELECT * FROM '||p_source_schema||''||'.'||''||REC1.CHILD_TABLE||' where '||REC1.COLUMN_NAME||'='||REC.cntrct_cd||'';
    Dbms_Output.Put_Line('THE VALUE STMT:'||STMT);
    END LOOP;
    END LOOP;
    END;
    cc_cd='434se22442ss3433';
    cc_t_ms is parent table-----------------------pk_cc_cd is primary key
    cc_cd is column name
    CONSTRAINTS_test table
    CHILD_TABLE NOT NULL VARCHAR2(30)
    CONSTRAINT_NAME NOT NULL VARCHAR2(30)
    COLUMN_NAME NOT NULL VARCHAR2(400)
    R_CONSTRAINT_NAME VARCHAR2(30)
    CONSTRAINT_TYPE VARCHAR2(1)
    PARENT_TABLE NOT NULL VARCHAR2(30)
    SRL_NUM NUMBER(4)
    CHILD_TABLE     CONSTRAINT_NAME     COLUMN_NAME     R_CONSTRAINT_NAME     CONSTRAINT_TYPE     PARENT_TABLE     SRL_NUM
    a aaa cc_CD     pk_cc_CD     R     cc_t_MS     1
    bb     bbb      Cc_CD     PK_CC_CD     R     cc_t_MS     2
    bb_v     bb_vsr     S_NUM     PK_S_NUM      R     bb_v      3
    cC_HS_MS     cc_hs_CD     cc_CD     PK_CC_CD     R     cc_t_MS     4
    cC_HS_LNK cc_HIS_LNK_CD     H_CD     PK_HS_HCD     R     cC_hs_ms 5
    cC_D_EMP     cc_d_EMP     Cc_CD     PK_CC_CD      R     cc_t_MS     6
    i want insert schema1 to schema2 with run time of column_name and column value.the column_name and values should dynamically generated
    with refential integrity.is it possible?
    can any please quick solution.its urgent
    by
    siva

  • 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

  • Using multiple values in a where clause, for values only known at runtime

    Dear all
    I am creating a PL/SQL program which returns multiple rows of data but only where it meets a set id values that a user has previously chosen. The id values are stored in an associative array and are chosen by a user in the preceding procedure at run time.
    I know all the table and column names in advance. The only things I don't know are the exact number of ids selected from the id column and what their values will be. This will only be known at runtime. When the procedure is run by the user it prints multiple rows of data to a web browser.
    I have been reading the following posting, which I understand to a large extent, Query for multiple value search But I cannot seem to figure out how I would apply it to my work as I am dealing with multiple rows and a cursor.
    The code as I have currently written it is wrong because I get an error not found message in my web browser. I think the var_user_chosen_map_list_ids in the for cursor loop could be the problem. I am using the variable_user_chosen_map_list_ids to store all the id values from my associatative array as a string. Which I modified from the code that vidyadhars posted in the other thread.
    Should I be creating a OPEN FOR ref cursor and if so where would I put my associative array into it? At the moment I take the value, turning it into a string and IN part in the WHERE clause holds the string, allowing the WHERE clause to read all the values from it. I would expect the where clause to read everything in the string as 1 complete string of VARCHAR2 data but this would not be the case if this part of the code at least was correct. The code is as follows:
    --Global variable section contains:
    var_user_chosen_map_list_ids VARCHAR2(32767);
    PROCEDURE PROCMAPSEARCH (par_user_chosen_map_list_ids PKG_ARR_MAPS.ARR_MAP_LIST)
    IS
    CURSOR cur_map_search (par_user_chosen_map_list_ids IN NUMBER)
    IS
    SELECT MI.map_date
           MT.map_title,
    FROM map_info MI,
         map_title MT,
    WHERE MI.map_title_id = MT.map_title_id
    AND MI.map_publication_id IN
    (var_user_chosen_map_list_ids);
    var_map_list_to_compare VARCHAR2(32767) := '';
    var_exe_imm_map VARCHAR2(32767);
    BEGIN
    FOR rec_user_chosen_map_list_ids IN 1 .. par_user_chosen_map_list_ids.count
    LOOP
       var_user_chosen_map_list_ids := var_user_chosen_map_list_ids ||
       '''' ||
       par_user_chosen_map_list_ids(rec_user_chosen_map_list_ids) ||
    END LOOP;
    var_user_chosen_map_list_ids := substr(var_user_chosen_map_list_ids,
                                            1,
                                            length(var_user_chosen_map_list_ids)-1);
    var_exe_imm_map := 'FOR rec_search_entered_details IN cur_map_search
    LOOP
    htp.print('Map date: ' || cur_map_search.map_date || ' Map title: ' || cur_map_search.map_title)
    END LOOP;';
    END PROCMAPSEARCH;EXECUTE IMMEDIATE var_exe_imm_map;
    I would be grateful of any comments or advice.
    Kind regards
    Tim

    I would like to thank everyone for their kind help.
    I have now successfully converted my code for use with dynamic SQL. Part of my problem was getting the concept confused a little, especially as I could get everything work in a static cursor, including variables, as long as they did not contain multiple values. I have learnt that dynamic sql runs the complete select statement at runtime. However even with this I was getting concepts confused. For example I was including variables and the terminator; inside my select string, where as these should be outside it. For example the following is wrong:
         TABLE (sys.dbms_debug_vc2coll(par_user_chosen_map_list_ids))....
    AND MI.map_publication_id = column_value;';Where as the following is correct:
         TABLE (sys.dbms_debug_vc2coll('||par_user_chosen_map_list_ids||'))....
    AND MI.map_publication_id = column_value';PL/SQL is inserting the values and then running the select statement, as opposed to running the select statement with the variables and then accessing the values stored in those variables. Once I resolved that it worked. My revised code is as follows:
    --Global variable section contains:
    var_user_chosen_map_list_ids VARCHAR2(32767);
    var_details VARCHAR(32767);
    PROCEDURE PROCMAPSEARCH (par_user_chosen_map_list_ids PKG_ARR_MAPS.ARR_MAP_LIST)
    IS
    BEGIN
    FOR rec_user_chosen_map_list_ids IN 1 .. par_user_chosen_map_list_ids.count
    LOOP
       var_user_chosen_map_list_ids := var_user_chosen_map_list_ids ||
       '''' ||
       par_user_chosen_map_list_ids(rec_user_chosen_map_list_ids) ||
    END LOOP;
    var_user_chosen_map_list_ids := substr(var_user_chosen_map_list_ids,
                                            1,
                                            length(var_user_chosen_map_list_ids)-1);
    var_details := FUNCMAPDATAFIND (var_user_chosen_map_list_ids);
    htp.print(var_details);
    END PROCMAPSEARCH;
    FUNCTION FUNCMAPDETAILS (par_user_chosen_map_list_ids IN VARCHAR2(32767)
    RETURN VARCHAR2
    AS
    TYPE cur_type_map_search IS REF CURSOR;
    cur_map_search cur_type_map_search;
    var_map_date NUMBER(4);
    var_map_title VARCHAR2(32767);
    begin:
    OPEN cur_map_search FOR
    'SELECT MI.map_date,
           MT.map_title
    FROM map_info MI,
         map_title MT,
         TABLE (sys.dbms_debug_vc2coll(' || par_user_chosen_map_list_ids || '))
    WHERE MI.map_title_id = MT.map_title_id
    AND MI.map_publication_id = column_value';
    LOOP
    FETCH cur_map_compare INTO
    var_map_date,
    var_map_title;
    var_details := var_details || 'Map date: '||
                        var_map_date ||
                        'Map title: ' ||
                        var_map_title;
    EXIT WHEN cur_map_compare%NOTFOUND;
    END LOOP;
    RETURN var_details;
    END FUNCMAPDETAILS;Kind regards
    Tim

  • 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.

  • About xml and null values in 10g

    Hi, I have an UCM GetFile webservice component wich receives 4 arguments, two of them are null values (rendition and extraPops), and the xml request generated by obpm is:
    <GetFileByName xmlns="http://www.stellent.com/GetFile/">
      <dDocName>V_123410</dDocName>
      <revisionSelectionMethod>latestReleased</revisionSelectionMethod>
      <rendition/>
      <extraProps/>
    </GetFileByName>The problem is: On UCM web service, an empty tag like <rendition/> is treated like a "empty string" value, instead of a null value, and then the response i get isn't the expected.
    What I want do to is change this behavior, and when I put null values in requests, the obpm should not write those tags. Is that possible?
    Should be like that:
    <GetFileByName xmlns="http://www.stellent.com/GetFile/">
      <dDocName>V_123410</dDocName>
      <revisionSelectionMethod>latestReleased</revisionSelectionMethod>
    </GetFileByName>Thanks!

    Hi,
    I have question regarding aggregates. It's possible to read data from BW aggregates? We have webi reports on a SAP BW multi cube and we would like to optimize retriving query.
    >> Because you are using the BW Query as the source all the items that you have done so far in terms of aggregation, indexing, ... is all valid and there are no specific steps required to leverage it with Web Intelligence. Make sure the aggregates are "correct" meansing that they do reflect what you are asking for in the Web Intelligence query panel
    How can we filter in webi query null (#) values. If we create condition that some variabe is diffrent from # we still get null (#) values in report.
    >> You should be able to create a variable. in case you tried that already could you be more specific ?
    thanks
    Ingo

  • MS Access and Null values

    Hi,
    I'm attempting to create a report in Crystal Reports Designer 2008 using a Microsoft Access 2003 table as a source. I'm having difficulty with my report design when the first record of the table contains a NULL value. I wish to find the Maximum() value of this field using the formula Maximum({table.field1}, {table.field2}) where field1 contains the value i'm trying to find the maximum of and field2 contains the grouping data. I find that if field1 contains valid values then the formula works as expected whereas if the first field1 value is NULL then the formula simply refuses to output anything (not even an error).
    I attempted to amend my formula to read:
    If IsNull({table.field1})
    Or {table.field1} = ""
    Or {table.field1} = " " Then
        "1"
    Else
       Maximum({table.field1}, {table.field2})
    But this also refuses to work.
    I also tried the following from the menu File > Report Options ... > Convert Database NULL Values to Default, and the other setting of Convert Other NULL Values to Default, but neither seemed to work for me.
    Any ideas on how I can test the table to see if the value is a null and hence deal with it?
    Thanks,
    Mike

    Ian,
    I had previously tried that with no luck.
    I've investigated further and I think the problem actually lies elsewhere. In my report design I join a couple of SQL Server views to the MS Access table. I think the join conditions are such that there is no data to bring back and so although the {table.field1} contains a vaule it is being ignored since the other tables can't join to it.
    I've managed to alter my other views and the problem still seems to have gone for the moment.
    I guess to answer my own question, the use of ISNULL(), = "" or = " " are the correct tests for a MS Access table and probably for most other data sources as well.
    Thanks,
    Mike

  • Problem with QofQ and Null Values

    Just converted from CF5 to CF7. Finally figured out what was
    causing the error message :
    "The value "" cannot be converted to a number" when running a
    QofQ. It happens whenever there is a NULL (and I think a ZERO)
    value in the QofQ. I'm using the QofQ in a seperate chart program.
    The main query merges data from a store and a region table.
    I'm doing a LEFT OUTER JOIN to combine the REGION with the STORE,
    AND so that stores with NO SALES for a given day will show up as
    ZERO. On the main report, when I don't use a QofQWhen grouping by
    DAY or MONTH, I can test the value in the CFOUTPUT for NULL or ZERO
    and display "0" or "N/A" on the report.
    But when I try to chart it, using a QofQ to read in the
    values from the main query, and format the numbers, I get this
    error message. I've tried using the CAST function, using FLOAT,
    DOUBLE, BIGINT, etc., but still get same error message.
    The only way I could fix this is to add a WHERE statement to
    the QofQ, that only includes sales values greater than ZERO. But
    then, I have gaps in my chart because stores with NO SALES for a
    given day or MONTH don't appear. Because they are removed from the
    query. The whole point of LEFT JOINS is to include items with no
    values (or NULL) values.
    Does anyone know if it's possible to keep these values in a
    QofQ? So that items (e.g., store locations in my case) with NULL or
    ZERO values for some or all days or months can be charted? Even
    with a ZERO value? I've read everything I can get my hands on
    regarding QofQ, the CAST function, etc., but nothing seems to work.
    Thanks for any help. (FYI, didn't have this problem with CF5. It's
    QofQ could handle NULL or ZERO values without providing an error).
    Gary

    Well, I tried the IsNull function on the 3 SUM() values I was
    calculating in my SELECT statement (on a LEFT OUTER JOIN QUERY),
    and I STILL got another "cannot convert "" to a number" but this
    time the error message was more direct, and pointed me to a DATE
    field in my query, where I was SORTING AND GROUPING either by DAY
    or MONTH (depending on what user selected on form).
    In my QofQ, I'm not just reformating the integer SUM()
    values, but also the date values. So, I applied the IsNull()
    function to the DATE values in my main query. I still kept getting
    errors. But after experimenting ((SQL Server BOL docs doesn't give
    ISNULL() examples for DATE FIELDS, only NUMBER fields), I tried
    putting the dates in SINGLE QUOTES in my IsNull() function, the
    QUERY RAN. Then I wasn't sure WHAT date to enter, e.g., 1/1/1889 or
    1/1/2001, etc.
    Then, I discovered, after experimenting, that you cannot just
    blindly enter ANY date when using IsNull in a date field,
    especially if you are using CFGRAPH to chart the results by day.
    You have to select a date within the date range the user selected,
    so this means using the FORM.DATE (or URL.DATE) value from the
    form. Here's the working example from my SELECT main query:
    SELECT SUM(ISNULL(d.ttldb,0)) AS SumOfDB,
    SUM(ISNULL(d.ttldbv,0)) AS SumOfDBV,
    SUM(ISNULL(d.ttldbi,0)) AS SumOfDBI,
    <CFIF '#url.reptype#' IS "DAILY">
    ISNULL(d.depday, '#url.date1#') AS depday
    <CFELSE>
    month(ISNULL(d.depday, '#url.date2#')) AS TranMonth,
    year(ISNULL(d.depday, '#url.date2#')) AS TranYear
    </CFIF>
    Then I discovered that whatever date was used in the URL.DATE
    field (in my case it would be one of the two date field from the
    form, and depended on whether you coded DATE1 or DATE2, the chart
    would always show ZERO values for that date. So I tried putting the
    IsNull() date values in the GROUP BY and ORDER BY statements, e.g.,
    <CFIF '#url.reptype#' IS "DAILY">
    GROUP BY ISNULL(d.depday, '#url.date1#')
    ORDER BY ISNULL(d.depday, '#url.date1#') DESC
    <CFELSE>
    GROUP BY year(ISNULL(d.depday, '#url.date2#')),
    month(ISNULL(d.depday, '#url.date2#'))
    ORDER BY year(ISNULL(d.depday, '#url.date2#')),
    month(ISNULL(d.depday, '#url.date2#'))
    </CFIF>
    And this worked. The report ran just fine, and the chart
    charted every value correctly.
    I guess you have to learn all the little "quirks" about CF7
    and how it's QofQ and chart programs work. But so far, so good.
    Thank you all for your help. Now I've got to update other old
    CF5 programs that are returning errors when there are null values
    from my LEFT OUTER JOIN queries. Will take some time, but at least
    I know how to do it. Thanks to your help.
    I really appreciate your time and efforts to help with this
    issue.
    Gary

  • Automated row fetches, checkboxes and null values

    Hi
    In Apex3 I have a page with automated fetch row process that is working fine. Now I need to add a new not null varchar2 column "flag" which can be a Y or a N.
    To do so, I created a new checkbox item p1_flag, set the source properties and the LOV definition to: STATIC2:Flag set;Y
    However when I try to save the data with the checkbox unticked I get a null value error. To solve it, I created a computation on that field like this:
    nvl(:p1_flag, 'N')
    Is this the best way to do it? (other than using database triggers)
    Thanks
    Luis

    Hi Patrick
    Thanks for the reply. I thought that, just wondered if there were a better way...
    Another option that I was thinking about was to modify the column definition to be nullable, with valid values being Y and null. So I wouldn't have to care about it. The only thing being that I don't like very much the idea of modifying the database design because of the development tool (though I saw things much worse than this, as using VARCHAR2 instead of DATE because the front end tool didn't handle date datatypes very well!)
    Or just stick to a trigger to do it.
    Cheers
    Luis

  • Using Convert to handle NULL values for empty Strings ""

    After having had the problem with null values not being returned as nulls and reading some suggestion solution I added a converter to my application.
      <converter>
        <converter-id>NullStringConverter</converter-id>
        <converter-for-class>java.lang.String</converter-for-class>
        <converter-class>com.j2anywhere.addressbookserver.web.NullStringConverter</converter-class>
      </converter>
    ...I then implemented it as follows:
      public String getAsString(FacesContext context, UIComponent component, Object object)
        System.out.println("Converting to String : "+object);
        if (object == null)
          System.out.println("READING null");
          return "NULL";
        else
          if (((String)object).equals(""))
            System.out.println("READING null (Second Check)");
            return null;       
          else
            return object.toString();
      public Object getAsObject(FacesContext context, UIComponent component, String value)
        System.out.println("Converting to Object: "+value+"-"+value.trim().length());
        if (value.trim().length()==0 || value.equals("NULL"))
          System.out.println("WRITING null");
          return null;
        else
          return value.toUpperCase();
    ...I can see that it is converting my values, however the object to which the inputText fields are bound are still set to empty strings ""
    <h:inputText size="50" value="#{addressBookController.contactDetails.information}" converter="NullStringConverter"/>Also when reading the object values any nulls are already converted to empty strings before ariving at the converter. It seems that there is a default converter handling string values.
    How can I resolve this problem as set nulls when the input value is an empty string other then checking every string in my class individually. I would really hate to pollute my object model with empty string tests.
    Thanks in advance
    Edited by: j2anywhere.com on Oct 19, 2008 9:06 AM

    I changed my converter as suggested :
      public Object getAsObject(FacesContext context, UIComponent component, String value)
        if (value == null || value.trim().length() == 0)
          if (component instanceof EditableValueHolder)
            System.out.println("SUBMITTED VALUE SET TO NULL");
            ((EditableValueHolder) component).setSubmittedValue(null);
          else
            System.out.println("COMPONENT :"+component.getClass().getName());
          System.out.println("Converting to Object: " + value + "< to " + null);
          return null;
        System.out.println("Converting to Object: " + value + "< to " + value);
        return value;
      }which produces the following output :
    SUBMITTED VALUE SET TO NULL
    Converting to Object: < to null
    Info : The INFO line however comes from my controller object where I print out the set value :
    package com.simple;
    import java.util.ArrayList;
    import java.util.List;
    public class Controller
      private String information;
      /** Creates a new instance of Controller */
      public Controller()
        System.out.println("Createing Controller");
        information = "Constructed";
      public String process()
        System.out.println("Info : "+getInformation());
        return "processed";
      public String reset()
        setInformation("Re-Constructed");
        System.out.println("Info : "+getInformation());
        return "processed";
      public String setNull()
        setInformation(null);
        System.out.println("Info : "+getInformation());
        return "processed";
      public String getInformation()
        return information;
      public void setInformation(String information)
        this.information = information;
    }I also changes my JSP / JSF page a little. Here is the updated version
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
    <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <%--
        This file is an entry point for JavaServer Faces application.
    --%>
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
      </head>
      <body>
        <f:view>
          <h:form>
            <h:inputText id="value" value="#{Controller.information}"/>
            <hr/>
            <h:commandLink action="#{Controller.process}">
              <h:outputText id="clicker" value="Process"/>
            </h:commandLink>             
            <hr/>
            <h:commandLink action="#{Controller.reset}">
              <h:outputText id="reset" value="Reset"/>
            </h:commandLink>             
            <hr/>
            <h:commandLink action="#{Controller.setNull}">
              <h:outputText id="setNull" value="Set Null"/>
            </h:commandLink>             
          </h:form>
        </f:view>
      </body>
    </html>The converter is declared for the String class in the faces configuration file. From the log message is appears to be invoked, however the object is not set to null.
    I tested this with JSF 1.2_04-b20-p03 as well as 1.2_09-b02-FCS.
    any other suggestions what could be causing this.

  • Null value of fax and Null value of email is not reflecting in SRM

    Hi
    If you change the Vendor fax and email to null value in SAP(transaction XK02 in communication for address) and replicate the vendor in SRM 5.0 with transaction BBPUPDVD, still in manage business partners BBPMAININT as vendor I am able to see old fax number and email id  instead of null value in Contact for Business Partner area.
    Where as if we change vendor fax and email to new fax and email , after replication we wre able to see new fax and email id in manage business partners transaction as vendor.
    Regards
    Dayal

    solved!

  • BAPI Structure populating using field name and field value frm internal tbl

    Hi Experts,
                     Need your help, my requirement is to populate BAPI import structure using its field name and filed value  stored in a internal table.  Please advise the best approach.
    Regards
    Ram.

    Hi, in an ABAP program you can make use of FIELD-SYMBOLS and the ASSIGN statement for filling the BAPI fields based on the fieldname found in the internal table. Hopes it answer your question. Succes

  • Date Range and Null Values

    Post Author: mrae
    CA Forum: Formula
    I want to pull up data that have been completed for the month, but also want to include null values.  I did the following but didn't work.
    (isnull({wrhwr.date_completed}) or {wrhwr.date_completed} => 4/1/2008 12:00:00AM or =<4/30/2008 11:59:59PM
    Help, please?

    Post Author: SKodidine
    CA Forum: Formula
    Try:
    isnull({wrhwr.date_completed}) or {wrhwr.date_completed} IN datetime(2008,04,01,00,00,00) to datetime(2008,04,30,23,59,59)

  • Should I use And or OR in the Where Clause?

    2 Databases have been merged, and in the purge some data was omitted, so I am running clean-up.  Now I need a query to show me if item1 is null, then check olditem1 if both fields are null then ignore the record completely.  But If either field
    has a value I need it returned.  So 1st check item1 if that field is not null, then return the record, if item1 is null, check olditem1 if that field is not null then return the record.  If both fileds are null, ignore the record and let's check
    the next one.
    Sample Data;
    Select
    Test.StaffIDID,
    Test.purchasedfrom,
    Test.date,
    case when Test.item1 is null then Test.olditem1 else null end as [1st Item],
    case when Test.item2 is null then Test.olditem2 else null end as [2nd Item],
    From internetsales Test
    CREATE TABLE Test
    StaffID INT NOT NULL PRIMARY KEY,
    purchasedfrom NVARCHAR(30) NOT NULL,
    date DateTime NOT NULL,
    item1 NVARCHAR(50),
    item2 NVARCHAR(50),
    olditem1 NVARCHAR(50),
    olditem2 NVARCHAR(50)
    INSERT Test VALUES
    (2, 'web1', '2010-01-02', 'stereo', 'NULL', 'NULL', 'NULL'),
    (3, 'web3', '2011-02-15', 'NULL', 'microphone', 'NULL', 'NULL'),
    (4, 'web14', '2014-02-21', 'NULL', 'NULL', 'NULL', 'headset'),
    (5, 'web81', '2015-01-01', 'NULL', 'NULL', 'MP3 Player', 'NULL');
    (6, 'web18', '2011-01-01', 'Dryer', 'NULL', 'MP3 Player', 'NULL');
    (7, 'web8', '2009-01-01', 'NULL', 'NULL', 'Stove', ''NULL);
    (8, 'web828', '2002-01-01', 'NULL', 'NULL', 'NULL', 'USB HUB');
    (9, 'web88', '2007-01-01', 'Refrigerator', 'NULL', 'NULL', 'NULL');
    (10, 'web89', '2009-01-01', 'NULL', 'NULL', 'NULL', 'NULL');
    Desired returned result sets would be StaffIDs: 2,5,6,7,9 -- as they have a value for item1 or olditem1

    Looks like you totally ignored my answer :-(
    well... you have your reason probably...
    You do realize that I gave you the answer from the start?!?
    Hi,
    your sample data do not include any NULL value. Blank string is not NULL.
    Please clarify your question and give us the result that you want to get, according to your sample data.
    * if your data is NULL and not empty string that you can use COALESCE(item1, olditem1,'') in order to get the first value that is not NULL. if both
    NULL then it will return blank string as this is the first value that is not null
      Ronen Ariely
     [Personal Site]    [Blog]    [Facebook]
    Using nested IIF can be done directly with the
    COALESCE function.
    The execution plan is the same, but the code is much cleaner and easier to write or read.
    There is a reason for this function.
    * In your current needs there are only 2 nested IIF, but you should know about COALESCE function! Once you get more complex situation you will be able to get a solution much faster and probably without any mistake on the first try.
    try to use 5 nested IIF... using COALESCE  this is simple as 2 or 10... all you need is to write all the values and the function will return the first that is not NULL
    Any way, I hope this is useful for people that will come to this thread in future :-)
    -- SOLUTION 1: using nested IIF
    SELECT StaffID, purchasedfrom, date,
    IIF(ITEM1 IS NOT NULL, ITEM1, IIF(OLDITEM1 IS NOT NULL, OLDITEM1,NULL)) AS [1ST ITEM],
    IIF(ITEM2 IS NOT NULL, ITEM2,IIF(OLDITEM2 IS NOT NULL, OLDITEM2,NULL)) AS [2ND ITEM]
    FROM Test
    -- solution 2: using COALESCE
    SELECT
    StaffID, purchasedfrom, date,
    COALESCE(ITEM1, OLDITEM1) AS [1ST ITEM],
    COALESCE(ITEM2, OLDITEM2) AS [2ND ITEM]
    FROM Test
    -- Whish solution look simpler to read, write or use?
    -- The execution plan is the same, but it is always good idea to make sure if you are not sure :-)
    I hope this is useful :-)
      Ronen Ariely
     [Personal Site]    [Blog]    [Facebook]

Maybe you are looking for

  • Centering Pictures in Ken Burns Effect.

    I've been putting together a slide show of various pictures using the Ken Burns effect. I've moved some of the pictures off-center for the pan and zoom effects and now all of my other pictures begin off-center. Is there an easy way to center the pics

  • Only getting context menus- can't select an item?

    I spilled some tea on my Macbook Pro key board- cleaned it up and dried it out. Now whenever I try to select an item (mac mail, numbers, finder) only get a context menu.  Can't select an item or type.  Mac mail can only look at one of my mail boxes c

  • Java.io.FileNotFoundException - ws-addressing.xsd

    I'm getting the following exception when I deploy and view my BPEL Process in the BPEL Console. What could be causing this exception: The following exception occured while loading this Process: Exception Name: java.io.FileNotFoundException Exception

  • Mac will not recognize my iPhone. a restart will resolve but...?

    every so often my Mac will not recognize my iPhone. a restart will resolve, is there a trick to recognize the iPhone without a restart? I'm on an eMac w OS 10.4.11 3GS

  • Generate documentat​ion of several VI's

    Hi everybody, I'm attempting to generate automatically the documentation of my own VI's (connector, front panel and description) I know that now Labview can execute a lot of things but that one particularly ??? Thanks Solved! Go to Solution.