Using NVL and to_char

Hi guys,
Some help needed here; I'm using the following code to create a report in Oracle APEX 3.0:
select     "EBA_BT_PROBLEM"."ID" as " BUG ID",
"EBA_BT_PROBLEM"."SUBJECT" as "SUBJECT",
     "EBA_BT_URGENCY"."URGENCY_NAME" as "PRIORITY",
     "EBA_BT_USER"."LOGIN_NAME" as "ASSIGNED TO",
"EBA_BT_PROBLEM"."SUBMITTED_BY_ID" as "SUBMITTED BY"
from     "EBA_BT_PROBLEM" INNER JOIN "EBA_BT_USER" ON "EBA_BT_PROBLEM"."ASSIGNED_TO_ID" = "EBA_BT_USER"."ID"
JOIN "EBA_BT_URGENCY" ON "EBA_BT_PROBLEM"."URGENCY_ID" = "EBA_BT_URGENCY"."ID"
JOIN "EBA_BT_STATUS" ON "EBA_BT_PROBLEM"."STATUS_ID"
= "EBA_BT_STATUS"."ID"
JOIN "EBA_BT_PRODUCT" ON "EBA_BT_PROBLEM"."PRODUCT_ID"
= "EBA_BT_PRODUCT"."ID"
JOIN "EBA_BT_CATEGORY" ON "EBA_BT_PROBLEM"."CATEGORY_ID"
= "EBA_BT_CATEGORY"."ID"
where
to_char("EBA_BT_PROBLEM"."STATUS_ID") = NVL(:P64_STATUS,to_char("EBA_BT_PROBLEM"."STATUS_ID"))
It is returning all of the fields and data that I am after, the only issue I am having is with my "where". I have a drop down select box called P64_STATUS, which allowes me to chose from several options, which will in turn give me different outputs of the report. It does this ok, but when it is set to the defualt or "null" value, I want to to just give me all of the possible rows from the Select; instead it gives me nothing back.
So in essence I need to correct the code in my where clause, I think mainly here:
NVL(:P64_STATUS,to_char(*"EBA_BT_PROBLEM"."STATUS_ID"*))
in order to give me what I am after
I've tried to explain what I am after as best I can, any help would be much appreciated; thanks!

Hi,
Sean Ed wrote:
It is returning all of the fields and data that I am after, the only issue I am having is with my "where". I have a drop down select box called P64_STATUS, which allowes me to chose from several options, which will in turn give me different outputs of the report. It does this ok, but when it is set to the defualt or "null" value, I want to to just give me all of the possible rows from the Select; instead it gives me nothing back.I suspect that :p64_status is getting set to a space, or something else that you can't see, rather than to NULL. Run this to check:
SELECT  DUMP (:p64_status)
FROM    dual;and post the output.
If that's the problem, use TRIM to equate a string that consists of nothing but spaces with NULL:
WHERE     (         :p64_status  = TO_CHAR (eba_bt_problem.status_id)
     OR  TRIM (:p64_status)      IS NULL
     )The way you were using NVL seems to assume that STATUS_ID can't be NULL. Is that the case?
This has nothing to do with your current question, but why are you using TO_CHAR? Is status_id a NUMBER, but you can only supply VARCHAR2 parameters?
If so, it would be more efficient to convert :p64_status to a NUMBER (which only means one call to TO_NUMBER for the entire query), rather than convert status_id to a VARCHAR2 (which requires calling TO_CHAR on every row). So you might consider this:
WHERE     ( TO_NUMBER (:p64_status)  = eba_bt_problem.status_id
     OR     TRIM (:p64_status)  IS NULL
I've tried to explain what I am after as best I can, any help would be much appreciated; thanks!The explanation was good, but there's a limit to how much explanations can do. It would really help if you included a test case that people can run to re-create the problem and test their solutions. That includes CREATE TABLE and INSERT statements for some sample data, VARIABLE and assignment statements for parameters (such as :p64_status), and the results you want from that data with the given parameter(s).
It's good that you mentioned you're using Apex 3.0; always say what version of the database (e.g., 10.2.0.4.0) you're using, too.

Similar Messages

  • ORA-06502 use TO_NUMBER and TO_CHAR

    Hi,
    Oracle Database 10g 10.2.0.5.0.
    I have mistake in this code:
    nSuper_ NUMBER(6,2);
    dbms_output.put_line('Super: ' ||  TO_NUMBER(nSuper_,'FM9G990D90'));
    ...I should use "TO_CHAR"...but my test is not failure, why?:
    --a)
    SET SERVEROUTPUT ON
    DECLARE
      nSuper_ NUMBER(6,2);
    BEGIN
      nSuper_ := 666.12;
      dbms_output.put_line('Super: ' ||  TO_NUMBER(nSuper_,'FM9G990D90'));
    END;
    Super: 666,12
    --b)
    SET SERVEROUTPUT ON
    DECLARE
      nSuper_ NUMBER(6,2);
    BEGIN
      nSuper_ := 6666.12;
      dbms_output.put_line('Super: ' ||  TO_NUMBER(nSuper_,'FM9G990D90'));
    END;
    DECLARE
    ERROR en línea 1:
    ORA-06502: PL/SQL: error  numérico o de valor
    ORA-06512: en línea 5
    --c)
    SET SERVEROUTPUT ON
    DECLARE
      nSuper_ NUMBER(6,2);
    BEGIN
      nSuper_ := 6666.12;
      dbms_output.put_line('Super: ' ||  TO_CHAR(nSuper_,'FM9G990D90'));
    END;
    Super: 6.666,12Why "a" not fail and "b" if it fails?

    Hi,
    jortri wrote:
    Why "a" not fail and "b" if it fails?Because Oracle RDBMS is (too) kind to you for "simple" conversion like that (but that doesn't mean you won't get errors...).
    The to_number function takes as input <b>string</b>.
    You're sending to it a <b>number</b>, so Oracle does this : +"Ok this guy is sending a number into a TO_NUMBER function when it should be a string, let's do an implicit conversion for him transparently"+.
    Your to_number(my_number_variable,'FM9G990D90') actually becomes this :to_number( to_char(my_number_variable) ,'FM9G990D90')But, as you can notice, the to_char function is not given any format, so it uses your session default which could be way different from the mask you're providing to the to_number function.
    Please execute this to understand what your failing to_number function is receiving as input :select 6666.12 number_implicitly_converted from dual;By default, on my machine it displays this :Scott@my11g SQL>select 6666.12 number_implicitly_converted from dual;
    NUMBER_IMPLICITLY_CONVERTED
                        6666.12Now if I use it as input of your to_number function with your format mask :Scott@my11g SQL>select TO_NUMBER('6666.12','FM9G990D90') back_to_number from dual;
    select TO_NUMBER('6666.12','FM9G990D90') back_to_number from dual
    ERROR at line 1:
    ORA-01722: invalid numberTadammm !
    Conclusion : Don't mess up the use of to_number/to_char/to_date functions.
    :-)

  • Difference between join conditions using NVL and not using NVL

    Hi,
    I have a join condition in one of the applications as follows.
    NVL(RQ.out_mesg_id,0) = NVL(RS.out_mesg_id,0)How is it different without using NVL function. What is the internal execution difference.
    RQ.out_mesg_id = RS.out_mesg_idWill there be any difference in Performance and also in the query output.
    Regards,
    Pabolu

    Pabolu wrote:
    Hi,
    I have a join condition in one of the applications as follows.
    NVL(RQ.out_mesg_id,0) = NVL(RS.out_mesg_id,0)How is it different without using NVL function. What is the internal execution difference.
    RQ.out_mesg_id = RS.out_mesg_idWill there be any difference in Performance and also in the query output.
    Regards,
    PaboluI suppose that's a bit of a trick question (or could be).
    If the column is allowed to be NULL, then your 2 queries are NOT equivalent, so comparing isn't useful since presumably you can only have one correct result :)
    However, if RQ and RS (no idea what the table names are) are both defined as having a NOT NULL constraint on the column out_mesg_id (ignoring the possibility of column level masking possible with the use of VPD here) then the optimizer could do better if you rewrote the query without the use of NVL (this would of course depend on your tables, indexes, etc ... i am merely showing you that it COULD make a difference).
    SQL> select * from v$version;
    BANNER                                                                         
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product               
    PL/SQL Release 10.2.0.1.0 - Production                                         
    CORE     10.2.0.1.0     Production                                                     
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production                        
    NLSRTL Version 10.2.0.1.0 - Production                                         
    SQL>
    SQL> create table t1 as
      2  select level as col1, case when mod(level, 10) = 0 then null else mod(level, 10) end as col2
      3  from dual connect by level <= 1000;
    Table created.
    SQL>
    SQL> alter table t1 add constraint t1_pk primary key (col1);
    Table altered.
    SQL>
    SQL> create index t1_i_001 on t1 (col2);
    Index created.
    SQL>
    SQL> exec dbms_stats.gather_table_stats(user, 'T1', cascade => true);
    PL/SQL procedure successfully completed.
    SQL>
    SQL> create table t2 as
      2  select level as col1, case when mod(level, 100) = 0 then null else mod(level, 100) end as col2
      3  from dual connect by level <= 1000;
    Table created.
    SQL>
    SQL> alter table t2 add constraint t2_pk primary key (col1);
    Table altered.
    SQL>
    SQL> create index t2_i_001 on t2 (col2);
    Index created.
    SQL>
    SQL> exec dbms_stats.gather_table_stats(user, 'T2', cascade => true);
    PL/SQL procedure successfully completed.
    SQL>
    SQL> --query using NVL
    SQL> explain plan for
      2  select count(*)
      3  from t1, t2
      4  where nvl(t1.col1, 0) = nvl(t2.col1, 0)
      5  /
    Explained.
    SQL>
    SQL> SELECT * FROM table(DBMS_XPLAN.DISPLAY);
    PLAN_TABLE_OUTPUT                                                              
    Plan hash value: 663667122                                                     
    | Id  | Operation              | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT       |       |     1 |     8 |     5  (20)| 00:00:01 |
    |   1 |  SORT AGGREGATE        |       |     1 |     8 |            |          |
    |*  2 |   HASH JOIN            |       |  1000 |  8000 |     5  (20)| 00:00:01 |
    |   3 |    INDEX FAST FULL SCAN| T1_PK |  1000 |  4000 |     2   (0)| 00:00:01 |
    |   4 |    INDEX FAST FULL SCAN| T2_PK |  1000 |  4000 |     2   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT                                                              
    Predicate Information (identified by operation id):                            
       2 - access(NVL("T1"."COL1",0)=NVL("T2"."COL1",0))                           
    16 rows selected.
    SQL>
    SQL> --verbose version of NVL
    SQL> explain plan for
      2  select count(*)
      3  from t1, t2
      4  where t1.col1 = t2.col1
      5  or ( (t1.col1 is null and t2.col1 = 0) or (t2.col1 is null and t1.col1 = 0) or (t1.col1 is null and t2.col1 is null) )
      6  /
    Explained.
    SQL>
    SQL> SELECT * FROM table(DBMS_XPLAN.DISPLAY);
    PLAN_TABLE_OUTPUT                                                              
    Plan hash value: 1043818223                                                    
    | Id  | Operation              | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT       |       |     1 |     8 |     2   (0)| 00:00:01 |
    |   1 |  SORT AGGREGATE        |       |     1 |     8 |            |          |
    |   2 |   NESTED LOOPS         |       |  1000 |  8000 |     2   (0)| 00:00:01 |
    |   3 |    INDEX FAST FULL SCAN| T1_PK |  1000 |  4000 |     2   (0)| 00:00:01 |
    |*  4 |    INDEX UNIQUE SCAN   | T2_PK |     1 |     4 |     0   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT                                                              
    Predicate Information (identified by operation id):                            
       4 - access("T1"."COL1"="T2"."COL1")                                         
    16 rows selected.So if we compare the 'verbose' version of the query, in the "predicate information" section of the explain you can see that the optimizer was able to completely ignore the
    or ( (t1.col1 is null and t2.col1 = 0) or (t2.col1 is null and t1.col1 = 0) or (t1.col1 is null and t2.col1 is null) ) condition since it knows that neither t1.col1 NOR t2.col1 columns can be null (by definition), and because of this we get a slightly different index access choice.

  • How to use nvl with to_char on varchar data type

    Hi,
    I have the datatype as varchar in which i enter date format with timestamp.
    I am using the quey
    select nvl(:p_date,pei_attribute8) from per_people_extra_info .
    Now i need to trucate in date format as Mar,12,2011.
    I tried using
    select tochar(nvl(:p_date,pei_attribute8),'yyyymmmdd') from per_people_extra_info and getting invalid character.
    How to get the output in 'Month ddTH, YYYY' format ????
    Edited by: user12952202 on Oct 27, 2011 12:11 AM

    This will not apply for HR tables..
    I used fnd_date.canonical_to_date function and solved the issue.
    Thanks Again :)
    Edited by: user12952202 on Oct 27, 2011 2:28 AM
    Edited by: user12952202 on Oct 27, 2011 2:28 AM

  • Help with nvl and to_char in query

    Hi, I was wondering if anyone could help me with finding the reason that the following query gives me an invalid number error:
    SELECT     to_char('dd/mm/yyyy',nvl(co_modified_date,co_added_date)) as d1
    FROM     co_allergies_record_upd
    WHERE          co_allergies_record_upd_id IN (
    SELECT co_allergies_record_upd_id
    FROM     co_allergies_link_upd
    WHERE     co_allergies_rec_id = 42
    ORDER BY     nvl(co_modified_date,co_added_date) DESC
    Specifically, it is the nvl(co_modified_date,co_added_date) which is causing the error. The co_added_date has a NOT NULL constraint, and both are date fields. What could be causing the error?

    You have missed format and data argument places in to_char():
    SELECT to_char('dd/mm/yyyy',nvl(co_modified_date,co_added_date)) as d1
    FROM co_allergies_record_upd
    WHERE co_allergies_record_upd_id IN (
    SELECT co_allergies_record_upd_id...
    SQL> select to_char('dd/mm/yyyy',sysdate) from dual;
    select to_char('dd/mm/yyyy',sysdate) from dual
    ERROR at line 1:
    ORA-01722: invalid number
    SQL> select to_char(sysdate,'dd/mm/yyyy') from dual;
    TO_CHAR(SY
    20/12/2006Rgds.

  • Using disticnt and nvl together

    Hi,
    Is it possible to use nvl with distinct?
    When no data is returned, the value should should be 0.
    How do I get use nvl in the code to get a value 0 when no data is returned?
    I tried using distinct(nvl(lbt.bsl_det_koers,0)), but tis still show 'no data found'.
    select  distinct(LBT.BSL_DET_KOERS)
    FROM    lgl_beslagleggingen_det lbt
    ,       lgl_referentie lre
    where   LBT.BSL_DET_VALUTA = LRE.REF_ID
    and     LBT.BSL_ID = 6
    and     LRE.REF_AFKORTING = 'USD';Thanks,
    Diana

    You can do like this,
    WITH T
         AS (SELECT DISTINCT (LBT.BSL_DET_KOERS)
               FROM lgl_beslagleggingen_det lbt, lgl_referentie lre
              WHERE LBT.BSL_DET_VALUTA = LRE.REF_ID
                AND LBT.BSL_ID = 6
                AND LRE.REF_AFKORTING = 'USD')
    SELECT * FROM T
    UNION ALL
    SELECT 0
      FROM DUAL
    WHERE NOT EXISTS (SELECT 1 FROM t)G.

  • Why use cursor and for loop?

    Hi All
    So in general why would we use a cursor and a for loop to do update in a stored procedure?
    Why wouldnt we just use a single update statement ?
    is there compelling reason for using a cursor and a for loop: I am reading some code from a co-worker that the business logic for the select (set need to be updated) is complex but the update logic is simple (just set a flag to (0 or 1 or 2 or 3 or 4).
    But eventually the select come down to a key (row_id) so I re-write it using just a single sql statement.
    The size of the main table is about 2.6 to 3million rows
    Any thoughts on that??
    The code below I just do a google for cursor for update example in case for something to play with
    -Thanks for all your input
    create table f (a number, b varchar2(10));
    insert into f values (5,'five');
    insert into f values (6,'six');
    insert into f values (7,'seven');
    insert into f values (8,'eight');
    insert into f values (9,'nine');
    commit;
    create or replace procedure wco as
      cursor c_f is
        select a,b from f where length(b) = 5 for update;
        v_a f.a%type;
        v_b f.b%type;
    begin
      open c_f;
      loop
        fetch c_f into v_a, v_b;
        exit when c_f%notfound;
        update f set a=v_a*v_a where current of c_f;
      end loop;
      close c_f;
    end;
    exec wco;
    select * from f;
    drop table f;
    drop procedure wco;
    Joining multiple tables
    create table numbers_en (
      id_num  number        primary key,
      txt_num varchar2(10)
    insert into numbers_en values (1, 'one'  );
    insert into numbers_en values (2, 'two'  );
    insert into numbers_en values (3, 'three');
    insert into numbers_en values (4, 'four' );
    insert into numbers_en values (5, 'five' );
    insert into numbers_en values (6, 'six'  );
    create table lang (
       id_lang   char(2) primary key,
       txt_lang  varchar2(10)
    insert into lang values ('de', 'german');
    insert into lang values ('fr', 'french');
    insert into lang values ('it', 'italian');
    create table translations (
      id_num    references numbers_en,
      id_lang   references lang,
      txt_trans varchar2(10) not null
    insert into translations values (1, 'de', 'eins'   );
    insert into translations values (1, 'fr', 'un'     );
    insert into translations values (2, 'it', 'duo'    );
    insert into translations values (3, 'de', 'drei'   );
    insert into translations values (3, 'it', 'tre'    );
    insert into translations values (4, 'it', 'quattro');
    insert into translations values (6, 'de', 'sechs'  );
    insert into translations values (6, 'fr', 'six'    );
    declare
      cursor cur is
          select id_num,
                 txt_num,
                 id_lang,
                 txt_lang,
                 txt_trans
            from numbers_en join translations using(id_num)
                       left join lang         using(id_lang)
        for update of translations.txt_trans;
      rec cur%rowtype;
    begin
      for rec in cur loop
        dbms_output.put (
          to_char (rec.id_num         , '999') || ' - ' ||
          rpad    (rec.txt_num        ,   10 ) || ' - ' ||
          rpad(nvl(rec.txt_trans, ' '),   10 ) || ' - ' ||
                   rec.id_lang                 || ' - ' ||
          rpad    (rec.txt_lang       ,   10 )
        if mod(rec.id_num,2) = 0 then
          update translations set txt_trans = upper(txt_trans)
           where current of cur;
           dbms_output.put_line(' updated');
        else
          dbms_output.new_line;
        end if;
      end loop;
    end;
    /Edited by: xwo0owx on Apr 25, 2011 11:23 AM

    Adding my sixpence...
    PL/SQL is not that different from a SQL perspective than any other SQL client language like Java or C# or C/C++. PL/SQL simply integrates the 2 languages a heck of a lot better and far more transparent than the others. But make no mistake in that PL/SQL is also a "client" language from a SQL perspective. The (internal) calls PL/SQL make to the SQL engine, are the same (driver) calls made to the SQL engine when using Java and C and the others.
    So why a cursor and loops in PL/SQL? For the same reason you have cursors and loops in all these other SQL client languages. There are the occasion that you need to pull data from the SQL engine into the local language to perform some very funky and complex processing that is not possible using the SQL language.
    The danger is using client cursor loop processing as the norm - always pulling rows into the client language and crunching it there. This is not very performant. And pretty much impossible to scale. Developers in this case views the SQL language as a mere I/O interface for reading and writing rows. As they would use the standard file I/O read() and write() interface calls.
    Nothing could be further from the truth. SQL is a very advance and sophisticated data processing language. And it will always be faster than having to pull rows to a client language and process them there. However, SQL is not Turing complete. It is not the procedural type language that most other languages we use, are. For that reason there are things that we cannot do in SQL. And that should be the only reason for using the client language, like PL/SQL or the others, to perform row crunching using a client cursor loop.

  • Using NVL for date

    I am creating a view and one of the columns is this:
    (b.startdate || ' To ' || b.enddate) salesDateRange
    however when I was trying to handle the null value of date, I found the following problems,
    case 1
    (nvl(b.startdate, 'NA') || ' To ' || b.enddate) salesDateRange
    when i use nvl, I am able to create the view, but when I retrieve the data, I get this error msg.
    ORA-01858: a non-numeric character was found where a numeric was expected
    01858. 00000 - "a non-numeric character was found where a numeric was expected"
    *Cause:    The input data to be converted using a date format model was
    incorrect. The input data did not contain a number where a number was
    required by the format model.
    *Action:   Fix the input data or the date format model to make sure the
    elements match in number and type. Then retry the operation.
    is nvl only available for numerical value?

    user8944947 wrote:
    I am creating a view and one of the columns is this:
    (b.startdate || ' To ' || b.enddate) salesDateRange
    however when I was trying to handle the null value of date, I found the following problems,
    case 1
    (nvl(b.startdate, 'NA') || ' To ' || b.enddate) salesDateRange
    when i use nvl, I am able to create the view, but when I retrieve the data, I get this error msg.
    ORA-01858: a non-numeric character was found where a numeric was expected
    01858. 00000 - "a non-numeric character was found where a numeric was expected"
    *Cause:    The input data to be converted using a date format model was
    incorrect. The input data did not contain a number where a number was
    required by the format model.
    *Action:   Fix the input data or the date format model to make sure the
    elements match in number and type. Then retry the operation.
    is nvl only available for numerical value?In addition to the answers already given, you have to consider that NVL is an overloaded function, designed to deal with different datatypes. It accepts 2 arguments and the version of NVL that is used depends on the arguments given (that's the nature of overloading - look it up on the internet if you're not sure).
    So, there is defined e.g.
    NVL({noformat}<number arg>, <number arg>{noformat})
    NVL({noformat}<varchar2 arg>, <varchar2 arg>{noformat})
    NVL({noformat}<date arg>, <date arg>{noformat})
    etc.In your example, as the first argument you are passing in is a date, Oracle is opting to use:
    NVL({noformat}<date arg>, <date arg>{noformat})But your second argument is not a date, it's a varchar2.
    However, Oracle is clever and can perform "implicit" conversions between datatypes i.e. it will try and convert datatypes without you actually telling it to. (It's generally good coding practice to do it yourself though).
    So, in you case Oracle is taking your varchar2 string "NA" and trying to implicitly convert this to a date, using the only way it knows how, which is to apply a date format mask as defined by the NLS_DATE_FORMAT parameter for the session. For example, internally it will be trying to do the equivalent of:
    TO_DATE('NA','DD-MON-YYYY')(assuming your NLS_DATE_FORMAT parameter is set to DD-MON-YYYY)
    If we try that ourselves, we get...
    SQL> select to_date('NA','DD-MON-YYYY') from dual;
    select to_date('NA','DD-MON-YYYY') from dual
    ERROR at line 1:
    ORA-01858: a non-numeric character was found where a numeric was expected... which is the same error you were getting.
    So, in order for your NVL to work you would either need to supply a DATE as the second argument (some default date to use if the first argument is null), or some varchar2 string that represents a date in the correct format as per your NLS_DATE_FORMAT setting (dangerous because if the NLS_ setting changes then your code can suddently error), or you provide the first argument as a VARCHAR2 string instead of a date (using TO_CHAR), so the the function overloading causes Oracle to choose the varchar2 argument version of NVL, for which 'NA' is a perfectly valid second argument.

  • Can not use NVL with group by clause?

    Hi All, I am using following sql query to fetch some records. select       nvl('RP5_dsc_dlk_MED_DEL_SBH_20130919_5799.out.bc','RP5_dsc_dlk_MED_DEL_SBH_20130919_5799.out.bc')||'|'||       nvl(tm_cdr_file_name,'NA')||'|'||       nvl(min(obj_id0),'0')||'|'||       nvl(max(obj_id0),'0')||'|'||       nvl(count(obj_id0),'0')||'|'||       nvl(trim(to_char(sum(VOLUME_RECEIVED)/100,'9999999999999990.99')),'0') from       EVENT_DLAY_SESS_TLCS_T where       obj_id0 between 1433833603724199101 and 1433833603724199109 group by       nvl(tm_cdr_file_name,'NA') The above query is perfect and returns data. In this case the returned data is as below:   RP5_dsc_dlk_MED_DEL_SBH_20130919_5799.out.bc|ICP_dsc_dlk_MED_DEL_SBH_20130919_5799.edr|1433833603724199101|1433833603724199109|9|2.00 However, when there is no matching obj_id0. My expected result will be as below:   RP5_dsc_dlk_MED_DEL_SBH_20130919_5799.out.bc|NA|0|0|0|0 I tried NVL and decode but it did not work. Any help on this is highly appreciated. Thanks Angsuman

    Hi, Angsuman,
    Angshuman wrote:
    Hi All, I am using following sql query to fetch some records. select       nvl('RP5_dsc_dlk_MED_DEL_SBH_20130919_5799.out.bc','RP5_dsc_dlk_MED_DEL_SBH_20130919_5799.out.bc')||'|'||       nvl(tm_cdr_file_name,'NA')||'|'||       nvl(min(obj_id0),'0')||'|'||       nvl(max(obj_id0),'0')||'|'||       nvl(count(obj_id0),'0')||'|'||       nvl(trim(to_char(sum(VOLUME_RECEIVED)/100,'9999999999999990.99')),'0') from       EVENT_DLAY_SESS_TLCS_T where       obj_id0 between 1433833603724199101 and 1433833603724199109 group by       nvl(tm_cdr_file_name,'NA') The above query is perfect ...
    Is the query really perfect, or does it have some problem?
    Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and the results you want from that data, so that the people who want to help you can re-create the problem and test their ideas.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002
    Do you think the message you posted is easy to read?  Do you think people would be able to understand what you're doing, and be more likely to help you, if it were formatted differently?
    I know this this site can take something that looks nice when you post it, and turn it into something hard to read.  Look at your message after you post it.  If it has become hard to read, fix it, even if the site, not you, caused the problem.

  • To know what procedure  is in exectution using  SID  and SERIAL#

    Hi
    Is there some way to know what procedure(package or function) is running using SID and SERIAL#, I tried to use v$sqltext , but show only query
    Tia
    using oracle 9.2.02

    Hello
    Joining v$session (sql_id) with v$sql (sql_id) you have the program_id.
    Joining v$sql (program_id) with dba_objects (object_id) and you have the proc/pkg
    Something like this:
    select rpad(s.sid || ',' || s.serial#, 10) sid
    , p.spid
    , to_char(sysdate - (s.last_call_et / 86400),'HH24:MI:SS') "LASTCALL"
    , to_char(s.LOGON_TIME,'dd/mm HH24:MI:SS') logon
    , rpad(substr(lower(s.username), 1, 10), 10) usr
    , rpad(substr(nvl(lower(s.osuser), 'n/a'), 1, 10), 10) osu
    , rpad(lower(decode(lower(trim(s.terminal)), 'unknown', substr(s.machine, 1, instr(s.machine, '.')-1), null
    , s.machine, s.terminal)),15) mcn
    , s.sql_id
    , o.object_name
    from v$session s, v$process p, v$sql q, dba_objects o
    where s.status = 'ACTIVE'
    and s.username is not null
    and p.addr = s.paddr
    and q.sql_id = s.sql_id
    and q.program_id = o.object_id
    order by 5;
    Regards
    Edited by: ERadaell on 16/06/2011 11:31
    Edited by: ERadaell on 16/06/2011 11:33
    Edited by: ERadaell on 16/06/2011 11:37

  • Using index and NULL

    Hi,
    I have the following issue (10.2.0.4)
    I have index on NO0_SESSION_ID and TBNAME
    how can I force using index ?
    Thanks for your help
    UPDATE BXAT.no5                                    
       SET TBNAME = :p0,                               
           REPLICATION_METHOD = :p1,                   
           STATUS = :p2,                               
           STARTING_TIME = :p3,                        
           ENDING_TIME = :p4,                          
           REC_INSERTED = :p5,                         
           REC_UPDATED = :p6,                          
           REC_UNCHANGED = :p7,                        
           REC_IN_ERROR = :p8,                         
           REC_CONFLICTS = :p9,                        
           TOTAL_REC = :p10,                           
           REC_CONF_UPDATED = :p11,                    
           REC_CONF_UNCHANGED = :p12,                  
           MASTER_TABLE = :p13,                        
           MASTER_SQ0_NRID = :p14,                     
           NO0_SESSION_ID = :p15,                      
           REC_PURGED = :p16,                          
           SQ0_NRID = :p17                             
    WHERE     (NO0_SESSION_ID = :wp18 OR :wp18 IS NULL)
           AND (TBNAME = :wp19 OR :wp19 IS NULL)              
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | UPDATE STATEMENT   |      |  1723 | 96488 |  1361   (1)| 00:00:17 |
    |   1 |  UPDATE            | NO5  |       |       |            |          |
    |*  2 |   TABLE ACCESS FULL| NO5  |  1723 | 96488 |  1361   (1)| 00:00:17 |
    Predicate Information (identified by operation id):                       
       2 - filter((:WP19 IS NULL OR "TBNAME"=:WP19) AND (:WP18 IS NULL OR     
                  "NO0_SESSION_ID"=TO_NUMBER(:WP18)))                         

    user12045475 wrote:
    Hi,
    I have the following issue (10.2.0.4)
    I have index on NO0_SESSION_ID and TBNAME
    how can I force using index ?
    Thanks for your help
    UPDATE BXAT.no5                                    
    SET TBNAME = :p0,                               
    REPLICATION_METHOD = :p1,                   
    STATUS = :p2,                               
    STARTING_TIME = :p3,                        
    ENDING_TIME = :p4,                          
    REC_INSERTED = :p5,                         
    REC_UPDATED = :p6,                          
    REC_UNCHANGED = :p7,                        
    REC_IN_ERROR = :p8,                         
    REC_CONFLICTS = :p9,                        
    TOTAL_REC = :p10,                           
    REC_CONF_UPDATED = :p11,                    
    REC_CONF_UNCHANGED = :p12,                  
    MASTER_TABLE = :p13,                        
    MASTER_SQ0_NRID = :p14,                     
    NO0_SESSION_ID = :p15,                      
    REC_PURGED = :p16,                          
    SQ0_NRID = :p17                             
    WHERE     (NO0_SESSION_ID = :wp18 OR :wp18 IS NULL)
    AND (TBNAME = :wp19 OR :wp19 IS NULL)              
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | UPDATE STATEMENT   |      |  1723 | 96488 |  1361   (1)| 00:00:17 |
    |   1 |  UPDATE            | NO5  |       |       |            |          |
    |*  2 |   TABLE ACCESS FULL| NO5  |  1723 | 96488 |  1361   (1)| 00:00:17 |
    Predicate Information (identified by operation id):                       
    2 - filter((:WP19 IS NULL OR "TBNAME"=:WP19) AND (:WP18 IS NULL OR     
    "NO0_SESSION_ID"=TO_NUMBER(:WP18)))                         
    It has already been pointed out that the FTS is probably due to the OR whatever IS NULL predicates.
    A hack that might/might not work - assuming indexes on the columns exist - is to use the syntax
    --'' is an empty string, interpreted by Oracle as null
    +column+ > ''A better way is to create a function-based index using NVL() or COALECSE on the affected column.

  • Using NVL in Query of Query resulting in error

    I'm still using CF8 and Oracle 11G back-end.
    When I use NVL in the query of query I got error....Can't I use NVL to check on null value? Please help
    Here is my codes:
    <cfquery name="GetC2" datasource="#Trim(application.OracDSN)#">
         SELECT CamID2, rel2_2,p_ln2,p_fn2,ins,l_year
         FROM prt_temp
         WHERE Ins = 'CC'
         AND l_year =  '1481'
    AND NVL(Child_LN2,' ') <> ' '
    AND NVL(Child_FN2,' ') <> ' '
        </cfquery>
    <cfif GetC2.Recordcount NEQ 0>   
    <cfquery name="CheckRel2C2" dbtype="QUERY">
      SELECT CamID2, rel2_2
      FROM GetC2
      WHERE NVL(Rel2_2,' ') <> ' '
    AND NVL(p_ln2,' ') = ' '
    AND NVL(p_fn2,' ') = ' '
    AND Ins = 'CC'
    AND l_year =  '1481'
    </cfquery>
    </cfif>
    The error:
    Error Executing Database Query.
    Query Of Queries syntax error.
    Encountered "NVL ( Rel2_2 ,. Incorrect conditional expression, Expected one of [like|null|between|in|comparison] condition,

    NVL is an Oracle function, and is not available in ColdFusion Query of Query.  If you are trying to check for null values, then use IS NULL or IS NOT NULL.  So
    WHERE NVL(Rel2_2,' ') <> ' '
        AND NVL(p_ln2,' ') = ' '
        AND NVL(p_fn2,' ') = ' '
    becomes
    WHERE Rel2_2 IS NOT NULL
        AND p_ln2 IS NULL
        AND p_fn2 IS NULL
    -Carl V.

  • Using NVL function in Dynamic SQL

    Hi ,
    I have created a procedure using the Dynamic SqL and while using the NVL() getting the following error . ORA-00936: missing expression.
    The query I have written as
    SQL_Txt:=' INSERT INTO VF.tblCData (A, B, C, D, E, F,G,H,I,J)
         SELECT '||l_A||',
         '||l_B||',
         '||l_C||',
              '||l_D||',
              NULL ,
              '||L_F||',
              NVL('||Param1||',''''),
              NVL('||Param2||',''''),
              NVL('||Param3||',''''),
              NULL
              FROM '||ParamTbl1||' WHERE ' ;
    and so on.
    For Param1 I have data for one execution and Param2 and Param3 is null for that execution.
    While executing the same I am getting below
    INSERT INTO VF.tblCData (A, B, C, D, E, F,G,H,I,J)
    SELECT 25,
         1,
         7,
              6,
              NULL ,
              5,
              NVL(PurchaseDate,''),
              NVL(,''),
              NVL(,''),
              NULL
              FROM xyz.PBuyer@pocdb WHERE
    and error ORA-00936: missing expression is popping up for Param2 and Param3 NVL(,'')
    Any suggestion to resolve this issue is highly appreciable.
    Thanks
    Sudipta

    NVL(,''),Where's the first argument to NVL? That's the obvious problem. Empty strings are NULL in Oracle anyway, so just lose the NVL and insert the values...
    C:\>                                                                        
    C:\>sqlplus hr/hr                                                           
    SQL*Plus: Release 11.2.0.3.0 Production on Wed May 8 10:08:53 2013          
    Copyright (c) 1982, 2011, Oracle.  All rights reserved.                     
    Connected to:                                                               
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> set NULL I_AM_NULL                                                     
    SQL> create table x(y varchar2(20));                                        
    Table created.                                                              
    SQL> insert into x values ('');                                             
    1 row created.                                                              
    SQL> select * from x;                                                       
    Y                                                                           
    I_AM_NULL                                                                   
    SQL>                                                                        

  • Any other way to write this using nvl(x,v) locator.

    please solve my confusion.
    select * from emp
    where nvl(to_char(temperature),'a')
    in (select nvl(to_char(temperature),'a') from emp
    where ename = 'SCOTT');
    temperature column in numeric value. Is there anyother way to execute the same answer without using type casting(to_char).
    can we use above queries ans without to_char..
    Edited by: user8710598 on Aug 19, 2009 10:18 AM

    Hi Solomon,
    I think you are forgot one case ( if sal is null).
    Sincerly it's good solution Solomon, I learned a good method to avoid scan table two times.
    Tanks Solomon.
    Good job.
    SELECT *
      FROM (SELECT e.*,
                   MAX (CASE
                           WHEN ename = 'SCOTT' OR temperature IS NULL
                              THEN 1
                        END
                       ) OVER (PARTITION BY temperature) scotts_temperature_club
              FROM emp e)
    WHERE scotts_temperature_club = 1
    SELECT *
      FROM emp_test;
         EMPNO ENAME      JOB              MGR HIREDATE          SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 1980-12-17        800                    20
          7499 ALLEN      SALESMAN        7698 1981-02-20       1600        300         30
          7521 WARD       SALESMAN        7698 1981-02-22       3000        500         30
          7566 JONES      MANAGER         7839 1981-04-02                               20
          7654 MARTIN     SALESMAN        7698 1981-09-28       1250       1400         30
          7698 BLAKE      MANAGER         7839 1981-05-01                               30
          7782 CLARK      MANAGER         7839 1981-06-09       2450                    10
          7788 SCOTT      ANALYST         7566 1987-04-19       3000                    20
          7839 KING       PRESIDENT            1981-11-17       5000          0         10
          7844 TURNER     SALESMAN        7698 1981-09-08       1500                    30
          7876 ADAMS      CLERK           7788 1987-05-23                               20
          7900 JAMES      CLERK           7698 1981-12-03        950                    30
          7902 FORD       ANALYST         7566 1981-12-03       3000                    20
          7934 MILLER     CLERK           7782 1982-01-23       1300                    10
    SELECT *
      FROM (SELECT e.*,
                   MAX (CASE
                           WHEN ename = 'SCOTT' OR sal IS NULL
                              THEN 1
                        END
                       ) OVER (PARTITION BY sal) scotts_salary_club
              FROM emp_test e)
    WHERE scotts_salary_club = 1
         EMPNO ENAME      JOB              MGR HIREDATE          SAL       COMM     DEPTNO SCOTTS_SALARY_CLUB
          7788 SCOTT      ANALYST         7566 1987-04-19       3000                    20                  1
          7521 WARD       SALESMAN        7698 1981-02-22       3000        500         30                  1
          7902 FORD       ANALYST         7566 1981-12-03       3000                    20                  1
          7566 JONES      MANAGER         7839 1981-04-02                               20                  1
          7876 ADAMS      CLERK           7788 1987-05-23                               20                  1
          7698 BLAKE      MANAGER         7839 1981-05-01                               30                  1
    6 rows selected.

  • How to use nvl() function in SQL Loader

    I am trying to use nvl() funtion in my SQL Loader control file and I keep geting errors. Would someone please tell me where I can find the syntax reference to this?
    Thanks a lot!

    I just answered a similar question like this last Thursday.
    SQL*LOADER how to load blanks when data is null

Maybe you are looking for

  • HT201250 can I use the same drive to backup more than one computer

    Can I use the same external hard drive to backup (using Time Machine) my Macbook pro and iMac computers? Can they be the same partition?

  • Intel core 2 duo 2 Ghz...

    I'm gonna buy an iMac 20"...I'd just like to know how will the overall performance be using Logic studio... Will I be able to use multiple plugins and software monitoring with low latency? Any experience is appreciated, thank you.

  • Problems publishing in Edge.

    When I want to publish and I go to file>publish the word publish stays grayed out. How can I activate this? Thanks.

  • Javascript error message loading dreamweaver mx

    this may be two different questions but here goes: -- i downloaded the interakt kollection a while back and just got time to use it. by now i noticed that a newer version was available so i downloaded it. but it crashed my machine trying to update. a

  • Does Xvfb server starting shuts down the other servers linked to it.

    We deploy our application using Weblogic server.We use Xvfb Server for rendering Digital Image. We could find that the Weblogic server is shutting down within an hour if we restart the Xvfb server. Can anyone clarify if there is any relation between