Question of NVL

NVL (to_date (NVL(:2,fnd_profile.) ((Value ('ICX_DATE_FORMAT_MASK'))),'* ') AND nvl (to_date (nvl (: 3, fnd_profile.value ('ICX_DATE_FORMAT_MASK'))),'* ')


is the syntax above to correct otherwise correct me

Published by: user12053530 on October 24, 2009 01:13

Hello

If you want to test explicitly for NULL values, I think it's more clear:

WHERE     (     date_column     >= TO_DATE (:2, fnd_profile.value ('ICX_DATE_FORMAT_MASK')
     OR     :2          IS NULL
     )
AND     (     date_column     <= TO_DATE (:3, fnd_profile.value ('ICX_DATE_FORMAT_MASK')
     OR     :3          IS NULL
     )

Tags: Database

Similar Questions

  • Simple question about NVL

    Hello

    It's simple question on NVL, here are the details:

    create table tb_test (number (3) id, varchar2 (12)) nm;

    insert into tb_test values (111, 'AAA');

    Select NVL (nm, n / 'a') in tb_test where id = 222;

    I don't have "N/a", which is what I expected. Any comment?  Thank you!

    Hello

    If you want a row of output, even if the query produces no line; right?

    This looks like a job for outer join:

    SELECT NVL (t, nm, n / 'a') OUTPUT

    OF the double

    LEFT OUTER JOIN tb_test t ON t.id = 222

    ;

    LEFT OUTER JOIN ensures that each row in the table to the left (i.e. immediately before "LEFT OUTER JOIN") will join, even if the condtion join fails.  It is 1 row duplicate, therefore, if there is no line in tb_test that fills the 'id = 222' condition, that the double row will be in the game anyway.  If there is tb_test lines that meet the condition, they all appear in the result set.

  • question query NVL

    Hello
    I have a request for a request to write that check null values in the CHANGE_CODE, makes it so 'none' if they are null, then the "none" takes the value and makes "open well". Should it be written in 2 separate calls to the database or can it be written as one? I wrote the following query, the "no" value is picked up, but its not to change the none for ' open wells. "I

    StringBuilder sbSQL = new StringBuilder();
    sbSQL.Append ("SELECT distinct RO. OBJECT_ID, RE. Stuff, RR.NAME, replace (nvl (A.CHANGE_CODE, '(none)'), '(none)', 'open_well') REV_CODE, "Autobalance"NOTE");
    sbSQL.Append ("FROM PLX_SCRIPTED_LOAD_OBJECT_SET OBJ");
    sbSQL.Append ("INNER JOIN PLX_CASE_ATTRIBUTE A ON OBJ. OBJECT_ID = A.OBJECT_ID");
    sbSQL.Append ("INNER JOIN PLX_RECON_RESERVOIR RR ON A.UNIQUE_ID is RR. RESERVOIR_NAME");
    sbSQL.Append ("INNER JOIN PLX_RECON_OBJECT RO ON RR. RESERVOIR_ID = RO. RESERVOIR_ID");
    sbSQL.Append ("INNER JOIN PLX_RECON_RESERVOIR_ENTRY RE ON RO. RESERVOIR_DATA_OBJECT_ID = RE. RESERVOIR_DATA_OBJECT_ID");
    sbSQL.Append ("INNER JOIN PLX_RECON_RESERVE_CATEGORY RRC ON RE. RESERVE_CATEGORY_ID = CRR. STUFF AND A.RESERVE_CATEGORY = CRR. CATEGORY_NAME');

    If I run the following query in sql developer, I get the results I want:
    SELECT replace (nvl (a.CHANGE_CODE, '(none)'), '(none),' open_well'), reservoir_entity, object_id, rr. Xxx_plx_case_attribute RESERVOIR_NAME A, PLX_RECON_RESERVOIR RR
    where A.UNIQUE_ID = RR. RESERVOIR_NAME


    any suggestions?
    Thank you

    UPDATE XXX_PLX_CASE_ATTRIBUE SET CHANGE_CODE = "OPEN_WELL".
    WHERE CHANGE_CODE IS NULL OR CHANGE_CODE = 'NONE ';

  • NVL question (sort off)

    Hi guys,.

    I was wondering if you could help me please.

    I have a table with a start_date and end_date, in addition to a temp_start_date and temp_end_date column.

    What I want to do, is show the start_date and end_date BUT, if the arguments start_date is null I want to show the temp_start_date and the temp_end_date in this column.

    I thought I could use nvl or eventually decode this?

    The first bit I think is simple, I nvl start_date to the temp_start_date, but I'm not sure how to proceed from there? I only want to show the temp_end_date if arguments start_date is null. Any help on this would be greatly appreciated.

    Select nvl (start_date, temp_start_date), end_date
    From my_table

    Thank you

    Hello

    Use2 NVL for this function

    SELECT     NVL ( start_date
             , temp_start_date
             )          AS s_date
    ,     NVL2 ( start_date
              , end_date
              , temp_end_date
              )             AS e_date
    FROM    table_x
    ;
    

    You could use DECODE or CASE to test If start_date is NULL and, depending on the response, return end_date or temp_end_date, but NVL2 has been designed for this. In other words, the expression of NVL2 above is equivalent to

    ,     CASE
             WHEN  start_date  IS NOT NULL
             THEN  end_date
             ELSE  temp_end_date
         END             AS e_date
    

    and also

    ,     DECODE ( start_date
                , NULL     , temp_end_date
                           , end_date
                )        AS e_date
    

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).
    See the FAQ forum {message identifier: = 9360002}

  • Need help for the Partition of PL/SQL query for a question

    Hi all


    I'm running on a question that I'm not able to get the desired result. I would appreciate if one of you experts can help resolve this.

    SQL * more: Production of release 11.2.0.1.0 game 4 Feb 09:31:26 2016
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.

    Connected to:
    Oracle Database 11 g Enterprise Edition Release 11.2.0.4.0 - 64 bit Production
    With partitioning, OLAP, Data Mining and Real Application Testing options


    with t as)
    Select 1 numero_enregistrement, Student_ID 123, nvl (trim (01), 'NULL') like Item_id, 'ITEM_ID_01' FIELD_NAME Union double all the
    Select 1 numero_enregistrement, Student_ID 123, nvl (trim(' '), 'NULL') like Item_id, 'ITEM_ID_02' FIELD_NAME Union double all the
    Select 1 numero_enregistrement, Student_ID 123, nvl (trim(' '), 'NULL') like Item_id, 'ITEM_ID_03' FIELD_NAME Union double all the
    Select 1 numero_enregistrement, Student_ID 123, nvl (trim(' '), 'NULL') like Item_id, 'ITEM_ID_04' FIELD_NAME Union double all the
    Select 1 numero_enregistrement, Student_ID 123, nvl (trim(' '), 'NULL') like Item_id, 'ITEM_ID_05' FIELD_NAME Union double all the
    Select 1 numero_enregistrement, Student_ID 123, nvl (trim(' '), 'NULL') like Item_id, 'ITEM_ID_06' FIELD_NAME Union double all the
    Select 2 numero_enregistrement, Student_ID 123, nvl (trim('01'), 'NULL') like Item_id, 'ITEM_ID_01' FIELD_NAME Union double all the
    Select 2 numero_enregistrement, Student_ID 123, nvl (trim('02'), 'NULL') like Item_id, 'ITEM_ID_02' FIELD_NAME Union double all the
    Select 2 numero_enregistrement, Student_ID 123, nvl (trim('03'), 'NULL') like Item_id, 'ITEM_ID_03' FIELD_NAME Union double all the
    Select 2 numero_enregistrement, Student_ID 123, nvl (trim('01'), 'NULL') like Item_id, 'ITEM_ID_04' FIELD_NAME Union double all the
    Select 2 numero_enregistrement, Student_ID 123, nvl (trim('01'), 'NULL') like Item_id, 'ITEM_ID_05' FIELD_NAME Union double all the
    Select 2 numero_enregistrement, Student_ID 123, nvl (trim('02'), 'NULL') like Item_id, 'ITEM_ID_06' double FIELD_NAME)
    SELECT distinct COUNT (*) OVER (PARTITION BY numero_enregistrement ORDER BY numero_enregistrement) REC_COUNT, numero_enregistrement, STUDENT_ID, ITEM_ID, Field_Name FROM t
    where ITEM_ID = 'NULL '.

    I get the following result.


    NUMERO_ENREGISTREMENT ITEM_ID FIELD_NAME STUDENT_ID REC_COUNT
    5                                   1                                             123                              NULL               ITEM_ID_02
    5                                   1                                             123                              NULL               ITEM_ID_03
    5                                   1                                             123                              NULL               ITEM_ID_04
    5                                   1                                             123                              NULL               ITEM_ID_05
    5                                   1                                             123                              NULL               ITEM_ID_06


    My desired output is

    Rec_COUNT Student_ID ITEM_ID FIELD_NAME numero_enregistrement
    5 1 123 NULL ITEM_ID_02, ITEM_ID_03, ITEM_ID_04, ITEM_ID_04, ITEM_ID_05

    Thanks in advance

    Rajesh

    Hi, Renon,

    Thanks for posting the sample data and results; It is very useful.

    Be sure to explain exactly how you get these results from these data.  There are many different reasons you may have, that all happen to produce the same results with the sample data you posted, but will get different results with other data sets.

    This looks like a job for aggregate (including the LISTAGG) functions and GROUP BY, not for functions, analytical and PARTITION BY

  • More on my table of full scan question...

    Ok. Apology. start one new thread, like other a receipt very complicated... If anyone can help Id be very grateful, because this results in a significant performance problem...

    XE 11.2

    Re this query:

    Select ENTITY_BUDGET_CAT,

    Sum (actual) real by

    de)

    Select Br ENTITY_BUDGET_CAT_ID as ENTITY_BUDGET_CAT,

    sum (br. BRI_CREDIT) under the real name

    from: br bri_recon

    Group of BR. ENTITY_BUDGET_CAT_ID

    )

    where ENTITY_BUDGET_CAT = (SELECT "EBC". (' ' ID ' FROM 'ENTITY_BUDGET_CAT' "EBC" WHERE 'ENTITY_ID' = 55)

    ENTITY_BUDGET_CAT group

    The query results in a table full of BRI_RECON scan, even if there is an index on BR. ENTITY_BUDGET_CAT_ID... If I put the where conditition on the inner circle question it works fine.

    The void, select retrieve entity_budget_cat on where clause returns a single value.

    If I replace the subselect statement to get the entity_budget_cat with a literal value, it uses the index on ENTITY_BUDGET_CAT and is much faster with a much lower cost.

    If I remove the sum (actual) external and just retrieve the value and no group, it also uses a sweep of indexes on the inner query on BRI_RECON.

    I need instruction in this format because its share actually well expand with unions comprising the sum of 4 tables, then later adds the value of the outer query to retrieve a single value by group of... The docs say that the filter must be passed to any SQL internally, but everything Ive tried to change the query, but leave the internal SQL without a where clause clause and apply it on the outer query. (as I would a view) translates into a full table scan.

    Here is a simple example of the view I have as an example of how the larger view needs to look for tables of the amount and return a single sum by group...

    Create union_sum_view like)

    Select sum (a) as a 'b' b

    de)

    Select nvl (sum (2), 0) as a 'b' of the double

    Union of all the

    Select nvl (sum (2), 0) as a 'b' of the double

    )

    Group by 'b '.

    )

    Select * from union_sum_view where b = (select "b" double)

    Ive tried to put a hint about it, and it doesn't seem to make a difference...

    Ive looked full statistics on the diagram too...

    So my question is: what is causing the full table scan (which is clearly much less effective). And given that I need to build a view in this way, how can I change to use an index in this format, or what I do to make it work...   All variants and the traces are below...

    Select ENTITY_BUDGET_CAT,

    Sum (actual) real by

    de)

    Select Br ENTITY_BUDGET_CAT_ID as ENTITY_BUDGET_CAT,

    sum (br. BRI_CREDIT) under the real name

    from: br bri_recon

    Group of BR. ENTITY_BUDGET_CAT_ID

    )

    where ENTITY_BUDGET_CAT = (SELECT "EBC". (' ' ID ' FROM 'ENTITY_BUDGET_CAT' "EBC" WHERE 'ENTITY_ID' = 55)

    ENTITY_BUDGET_CAT group

    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
    ---------------------------------------------------------------------------------------------------------------
    | 0 | SELECT STATEMENT | 230. 3910 | 3335 (3) | 00:00:41 |
    | 1. HASH GROUP BY. 230. 3910 | 3335 (3) | 00:00:41 |
    |* 2 | VIEW | 230. 3910 | 3333 (3) | 00:00:40 |
    | 3. HASH GROUP BY. 230. 1610. 3333 (3) | 00:00:40 |
    | 4. TABLE ACCESS FULL | BRI_RECON | 589K | 4031K | 3287 (2) | 00:00:40 |
    | 5. TABLE ACCESS BY INDEX ROWID | ENTITY_BUDGET_CAT | 1. 8. 2 (0) | 00:00:01 |
    |* 6 | INDEX RANGE SCAN | ENTITY_BUDGET_CAT_ENTITY_IDX1 | 1 | | 1 (0) | 00:00:01 |
    ---------------------------------------------------------------------------------------------------------------
    Information of predicates (identified by the operation identity card):
    ---------------------------------------------------
    2 - filter("ENTITY_BUDGET_CAT"= (SELECT "EBC".")) ID""ENTITY_BUDGET_CAT""EBC"WHERE
    'ENTITY_ID' = 55))
    6 - access ("ENTITY_ID" = 55)

    Select ENTITY_BUDGET_CAT,

    Sum (actual) real by

    de)

    Select Br ENTITY_BUDGET_CAT_ID as ENTITY_BUDGET_CAT,

    sum (br. BRI_CREDIT) under the real name

    from: br bri_recon

    Group of BR. ENTITY_BUDGET_CAT_ID

    )

    where ENTITY_BUDGET_CAT = (382)

    ENTITY_BUDGET_CAT group

    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
    ----------------------------------------------------------------------------------------------------
    | 0 | SELECT STATEMENT | 1. 17. 54 (0) | 00:00:01 |
    | 1. GROUP SORT BY NOSORT | 1. 17. 54 (0) | 00:00:01 |
    | 2. VIEW | 1. 17. 54 (0) | 00:00:01 |
    | 3. GROUP SORT BY NOSORT | 1. 7. 54 (0) | 00:00:01 |
    | 4. TABLE ACCESS BY INDEX ROWID | BRI_RECON | 808 | 5656. 54 (0) | 00:00:01 |
    |* 5 | INDEX RANGE SCAN | BRI_RECON_IDX_EBC | 808 | 4 (0) | 00:00:01 |
    ----------------------------------------------------------------------------------------------------
    Information of predicates (identified by the operation identity card):
    ---------------------------------------------------
    5 - access("BR".") ENTITY_BUDGET_CAT_ID "= 382)

    Richard Legge wrote:

    The void, select retrieve entity_budget_cat on where clause returns a single value.

    If I replace the subselect statement to get the entity_budget_cat with a literal value, it uses the index on ENTITY_BUDGET_CAT and is much faster with a much lower cost.

    Because the query runs faster when you use literal is because Oracle merges internal queries and views, so that it looks to below.

    Select Br ENTITY_BUDGET_CAT_ID as ENTITY_BUDGET_CAT

    sum (br. BRI_CREDIT) under the real name

    from: br bri_recon

    where br. ENTITY_BUDGET_CAT_ID =

    Group of BR. ENTITY_BUDGET_CAT_ID

    However when a subquery is used, as in the column ENTITY_BUDGET_CAT - the subquery must be run before the outer query can send more data, so that the outer query to only return results that match records based on the subquery.

    Richard Legge wrote:

    I need instruction in this format because its share actually well expand with unions comprising the sum of 4 tables, then later adds the value of the outer query to retrieve a single value by group of...

    Maybe you should re - write the query as follows so that the optimizer would get the opportunity to merge the view and give you better performance...

    Select entity_budget_cat

    , sum (actual) real by

    from (select br.entity_budget_cat_id as entity_budget_cat

    , sum (br.bri_credit) real by

    from: br bri_recon

    Br.entity_budget_cat_id group

    ) a1

    , (select ebc.id from entity_budget_cat where entity_id = 55 ebc) b1

    where a1.entity_budget_cat = b1.id

    A1.entity_budget_cat group;

    or just... would...

    Select entity_budget_cat_id entity_budget_cat

    , sum (actual) real by

    bri_recon a1

    , (select ebc.id from entity_budget_cat where entity_id = 55 ebc) b1

    where a1.entity_budget_cat_id = b1.id

    A1.entity_budget_cat_id group

  • Practical SQL training/exam question

    Hello

    I am a student at the bases SQL 1z0-051 exam, and examples of questions about the Oracle University site review is the following:

    3. review the structure of the EMP table:

    EMP                                      

    Name                                  Null?                        Type

    ------------------------------------------------------------------------------------------

    EMPNO NOT NULL NUMBER (3)

    ENAME                                                               VARCHAR2(25)

    SALARY                                                              NUMBER(10,2)

    COMM_PCT                                                        NUMBER(4,2)

    You want to generate a report which meets the following requirements:

    1 shows the names of employees and the commission amounts

    2 excludes employees who do not have a commission

    3 displays a zero for the employees whose SALARY has no value

    You run the following SQL statement:

    SQL > SELECT ename, NVL (salary * comm_pct, 0)

    WCP

    WHERE comm_pct <>NULL;


    What is the result?

    It generates an error

    B it runs successfully but displays no results

    C it runs successfully but displays results that meet only the requirements 1 and 3

    D it is running successfully and displays results which fulfil all the requirements

    The answer provided on the Web site is: B it runs successfully but displays no results

    and I don't understand why...


    The WHERE clause excludes rows with comm_pct is NULL. So for the function NVL in the SELECT clause, the value of comm_pct will never be NULL, but salary * can * be NULL (there is no NULL constraint on this topic), so for lines where the salary is NULL, salary * comm_pct evaluate to NULL and the function NVL would transform these nulls to 0.


    Am I missing something?  I realize that for some people on this forum, the answer may be obvious, but I'm learning just for the first level of certification SQL, so for now I still have a lot to discover.


    Thanks in advance,

    JM

    x <> NULL

    x = NULL

    Neither is never true. NULL is never equal to what whatsoever (including NULL). NULL is also never not equal to what

    X IS NOT NULL

    X IS NULL

    are the right way

    http://docs.Oracle.com/CD/B19306_01/server.102/b14200/sql_elements005.htm

  • Question calling a function

    Hi all

    I have a function that takes a lot of time when its appeal of a direction select in a view. The display of lines 156K and other joins table query, the query result is about 66K.

    The query without the function takes 0.5 seconds, but with the function takes an eternity, here is my example:help with statistical plan.

    I replaced this part I have several ii.index with the function as:

    Sum ((ci.ilo_cost/1000) * pl.degradation * fs.) Ask * pc.total_count * fn_get_inflation (ci.req_id, pc.FY, 2)) AS PR_TR_Cost,

    Here is my function:

    create or replace function fn_GET_INFLATION(v_req_id in number, v_fy in number, v_rate_type in number) return number is
      Result number;
    begin
      select cr into Result
      from (
        select lkp_inflation_rate_type_name, lkp_inflation_rate_type_id, fy, calculated_rate cr
        from lkp_inflation_rates join lkp_inflation_rate_base using(lkp_inflation_rate_base_id)
        join lkp_inflation_rate_type using (lkp_inflation_rate_type_id)
        join requirement using (req_id)
        where req_id = v_req_id
        and fy between fydp_startyear and (fydp_endyear + 2)
        model
        partition by (lkp_inflation_rate_base_id)
        dimension by (row_number() over(partition by lkp_inflation_rate_base_id order by fy) rn)
        measures(fy, rate, lkp_inflation_rate_type_name, lkp_inflation_rate_type_id, 0 calculated_rate)
        rules(calculated_rate[any] = nvl(calculated_rate[cv()-1], 1) * (rate[cv()] * 0.01 + 1))
      )
      where fy = v_fy
      and lkp_inflation_rate_type_id = v_rate_type;
      return(Result);
    
      exception when no_data_found then
        Result := 1;
        return(Result);
    n_GET_INFLATION;
    

    Is there something wrong with my function?

    Can I use the function in a different way in the opinion? I have to create a procedure and use the slider?

    Any ideas?

    Thank you!

    Hello

    Whenever you have a question, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the expected results of these data, so that people who want to help you can recreate the problem and test their ideas.

    Explain, using specific examples, how you get these results from these data.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: Re: 2. How can I ask a question on the forums?

    Calling even the simplest of SQL user-defined function slows the SQL statement.

    It seems that this function is not the simplest user-defined function.  You can do much of the work even appealed to the other.

    These two are the reasons why you may get better performance if you could do what you need to do in pure SQL.  I bet as you can, because the function is essentially just do more SQL.  If nothing else, you could do exactly the thing as a scalar subquery.

  • NVL function in Oracle 11 G

    Hi all

    During my interview, I had two questions that made me perplexed in the interview.

    (1) in Oracle 11 G, there is a similar to the nvl function. What is it? I knew that we can use decode function nvl but in 11G, any function has been introduced?

    (2) other that function, what are the other ways to pass the entries of a procedure?

    Someone knew the answers to these or questions asked by the interviewer are wrong? Please give your suggestions...

    Hello

    user2639048 wrote:

    Hi all

    During my interview, I had two questions that made me perplexed in the interview.

    (1) in Oracle 11 G, there is a similar to the nvl function. What is it? I knew that we can use decode function nvl but in 11G, any function has been introduced?

    COALESCE may think of you (or the one who asked you this), but she is older than version 11.

    See COALESCE

    If you had no idea what was the service, a good answer would be: "I don't know what is the function, but I know that there is a"what's new"manual Oralce 11 (and all recent versions) and, better yet, a"What's new"chapter at the beginning of the manual of the SQL language that describes all the new features."  "Know exactly what are the new features in Oracle 11 aren't really important if we are now both Oracle 11 and older versions, anyway."

    (2) other that function, what are the other ways to pass the entries of a procedure?

    Someone knew the answers to these or questions asked by the interviewer are wrong? Please give your suggestions...

    Sorry, I can't understand what you're asking.

    Isn't a function.

    IN arguments are usually the best way to move the entries of a procedure.  If, in an interview, someone asked on other ways, make it clear that you know before you give any other answer.

    I suggest that you describe what you want a little more in detail.

    In addition, create a separate thread for each separate issue.  (I do not know what 2) above is, but it doesn't seem to have anything to do with 1).  (Asked in the same interview is not significant.)

  • Use a control for a column nvl non-zero trigger

    Hi gurus,

    Appreciate your help here,

    I was told to use a control nvl for a column not null, am looking at here can we use NVL fucntion for a (ES_NUMBER) column not null or something wrong...

    Please notify.


    Sea of ESCR

    ES_NUMBER not null VARCHAR2 (16).

    ID NUMBER (8).

    FULL_FALG VARCHAR2 (1)

    sample data:

    ES_NUMBERfull_flagID
    67156044950THERE1
    484002064992N6
    22220000N3
    601101704712148N4
    670162973THERE5
    670163740THERE6
    670163740THERE6
    670170399THERE6


    CREATE OR REPLACE TRIGGER prod.merpiggytrig

    BEFORE INSERT OR UPDATE ON PROD. SEA
    FOR EACH LINE

    DECLARE
    bParam BOOLEAN: = FALSE;

    BEGIN

    IF THE INSERTION
    THEN
    bParam: = TRUE;
    ELSIF UPDATE
    THEN
    IF NVL(:NEW.ES_NUMBER,' ') <>nvl (: OLD.ES_NUMBER,' ')

    THEN
    bParam: = TRUE;
    ON THE OTHER
    IF NVL (: OLD.ES_NUMBER,' ') <>: NEW.ES_NUMBER,' ')
    THEN
    IF (: NEW.ID = 6 AND)
    NVL(:OLD.) FULL_FLAG, 'n') <>nvl(:NEW.) FULL_FLAG, 'N') AND NVL(:NEW.) (FULL_FLAG, 'n') <>'n') THEN
    bParam: = FALSE;
    ON THE OTHER
    bParam: = TRUE;
    END IF;
    END IF;

    END IF;
    END IF;

    IF bParam

    THEN
    UPDATE prod.ter SET piggy_flag = 'Y '.
    WHERE mer_id =: new.mer_id
    and NVL(piggy_flag,'N') = 'n';
    END IF;

    < < TRIGGER_EXIT > >
    NULL;

    END;
    /

    Hello

    978485 wrote:

    Yes es_number non-null VARCHAR2 (16).

    In fact, a question that we can use nvl for not null column.

    Yes. Was there no problem when you tried?

    The only restriction on NVL is that both arguments must be the same data type (or close).  There is no restriction on arguments is NULL or not.  Neither the argument must be NULL.

  • Application of self-join interview question?

    Hi guys!

    I asked this question in an interview for the job as a developer of database.

    I received a select based on symbol table and asked to drow the printout and then explain works step by step this statement.

    Here are the instructions create & insert

    /**********************************************/

    create table tbl (number x, y varchar2 (50));

    INSERT INTO tbl (x, y) VALUES ('A', 0);

    INSERT INTO tbl (x, y) VALUES (1, 'B');

    COMMIT;

    /***********************************************/

    Below the query (select statement)

    SELECT tbl1.x

    OF tbl tbl1 tbl2 tbl

    WHERE tbl1.x = 0 OR tbl2.x = 1;

    Please explain me the output and work step by step this statement...

    Thank you...

    Hello usman_noshahi,

    If you omit the where the query clause will result as below

    SELECT tbl1.x, tbl2.x

    OF tbl tbl1 tbl2 tbl

    /

    X          X

    ----- ----------

    0          0

    0          1

    1          0

    1          1

    Request granted will result as below based on where condition on each line on top 4 rows...  Or Condition will be returs real if one condition is met with the data set.

    SQL > SELECT tbl1.x, tbl2.x

    2 tbl tbl1 tbl2 tbl

    3. WHERE tbl1.x = 0 tbl2.x = 1 GOLD

    4.

    X          X

    ---------- ----------

    0          0

    0          1

    1          1

    SQL >

    You can get the information in a different way as below...

    SQL > explain plan set statement_id = "ORACLEFORUMS" for

    2. SELECT tbl1.x

    3 tbl tbl1 tbl2 tbl

    4 WHERE tbl1.x = 0 OR tbl2.x = 1;

    He explained.

    SQL > select LPad (' ', 2 *(Level-1)). Level | '.' || NVL (position 0). ' ' ||

    Operation 2. ' ' || Options of | ' ' || Object_name | ' ' || Object_type

    3   || ' ' || Decode (id, 0, Statement_Id |) "Cost = ' | Position) | cost

    4   || ' ' || Object_Node "Query Plan.

    plan_table 5

    6 start with id = 0 and statement_id = 'ORACLEFORUMS. '

    7. connect by prior id = parent_id

    8 and statement_id = 'ORAFAQ.

    9   /

    Query plan

    --------------------------------------------------

    1.7 STATEMENT SELECT ORACLEFORUMS cost = 77

    2.1 NESTED LOOPS 7

    3.1 ACCESS FULL TBL TABLE 3 TABLE

    3.2 TABLE ACCESS FULL TBL TABLE 2

    SQL > SELECT *.

    TABLE 2 (DBMS_XPLAN. DISPLAY ('PLAN_TABLE', 'ORACLEFORUMS', 'BASIC'));

    PLAN_TABLE_OUTPUT

    ------------------

    Hash value of plan: 1718268327

    -----------------------------------

    | ID | Operation | Name |

    -----------------------------------

    |   0 | SELECT STATEMENT |      |

    |   1.  NESTED LOOPS |      |

    |   2.   TABLE ACCESS FULL | TBL |

    |   5:   TABLE ACCESS FULL | TBL |

    -----------------------------------

    10 selected lines.

    SQL >

    SQL > select LPAD (' ', 2 *(LEVEL-1)). operation 'OPERATION', 'options ',.

    2 DECODE (TO_CHAR (id), '0',' COST = ' |) NVL (to_char (position), n / 'a').

    3 object_name) 'OBJECTNAME', id | » -'|| NVL (parent_id, 0) | » -'||

    4 NVL (position 0), 'ORDER', SUBSTR (optimizer, 1, 6) 'OPT '.

    plan_table 5

    6. start with id = 0

    7 and statement_id = 'ORACLEFORUMS. '

    8 connect by prior id = parent_id

    9 and statement_id = 'ORACLEFORUMS. '

    10.

    OPTIO OBJECTNAME OPT OPERATION ORDER

    ------------------------- ----- ----------------------------------------------- ---------- ---------------

    COST OF THE SELECT = 7 0-0-7 ALL_RO

    NESTED LOOPS                                                                  1-0-1

    TABLE ACCESS FULL TBL 2-1-1

    TABLE 3-1-2 TBL FULL ACCESS

    SQL >

    ID ID-PARENT as follows...

    00

    10

    21

    31

    Here level 1 has 2 childs (2,3)

    Thus the sequential order of enforcement will be 2,3,1.

    For more reference I recommend you read below, of course it's Oracle V8 but it gives more information.

    Good reading!

    Optimization of joins

  • "The Archivelog file size" and the question of 'db_recovery_file_dest_size.

    Hello

    According to the literature, DB_RECOVERY_FILE_DEST specifies the default location for the flash recovery area. The flash recovery area contains copies of files of control current multiplexes and remake online of newspapers, but also archived redo logs

    And DB_RECOVERY_FILE_DEST_SIZE specifies (in bytes) of the strict limit on the total space to be used by the target database recovery files created in the flash recovery area.

    Here's the info from my database (10 gr 2, RHEL 64-bit database is in archivelog mode):

    Log_archive_dest_1 = ' LOCATION = + recovery /'

    db_recovery_file_dest = '+ RECOVERY. "

    db_recovery_file_dest_size = 550 GB

    -Size of archivelog files:

    Select

    SUM(BLOCKS * BLOCK_SIZE)/1024/1024/1024 SIZE_GB

    Of

    V$ ARCHIVED_LOG

    -> 672,39 GB

    If I have question used flash recovery area space, it is to be:

    SELECT name

    , ceil (space_limit / 1024 / 1024) SIZE_M

    , ceil (space_used / 1024 / 1024) USED_M

    , decode (nvl (space_used, 0),)

    0, 0

    ceil ((space_used / space_limit) * 100)) PCT_USED

    V $ recovery_file_dest

    ORDER BY name

    NAME SIZE_M USED_M PCT_USED

    + 563200 8 1 RECOVERY

    I'm confused where are the archivelogs saved if not + recovery?

    Total current total size of ARCHIVELOG files if "672.39" but especially the request saying that only 8% of the db_recovery_file_dest was used. So obviously they are either not in + RECOVERY or they are not accounted for.

    I chedk on ASM using asmcmd:

    ASMCMD > cd ARCHIVELOG

    ASMCMD > ls

    2013_09_05 /.

    2013_09_06 /.

    2013_09_09 /.

    2013_09_10 /.

    2013_09_11 /.

    2013_09_12 /.

    ASMCMD >

    Whereas the query on the view V$ ARCHIVED_LOG shows me the file names for the month of August as well.

    I don't know that I am misunderstanding/missing something. I'm lost :-(

    Please advise!

    Thanks in advance!

    You wrong understand archiving at the area of fast recovery works. You have done the fast recovery area to a certain destination and also set up check-in to the same physical location: but Oracle doesn't know that they are in the same place. You must explicitly set:

    ALTER system set log_archive_dest_1 is 'location = USE_DB_RECOVERY_FILE_DEST';.

    and then Oracle will understand and follow the space in the paper archive used against the db_recovery_file_dest_size.

    --

    John Watson

    Oracle Certified Master s/n

  • JOIN the question... Join two tables without omitting lines

    I came across a problem that should be an easy fix (I hope), but I'm having a hard time to come up with a solution.

    Basically I have two tables, one with the actual amounts with the budget. I have to write a sql statement select that joins these tables together and includes all of their lines. I was able to join the tables by using JOIN, LEFT JOIN and RIGHT JOIN, but it always fails the lines I need.

    Below, I have examples of my tables (AMOUNT_TABLE and BUDGET_TABLE). For simplicity, I built the examples to show the same values in the first four columns, with the 5th and 6th columns (SUB_ACCOUNT, AMOUNT, BUDGET) as the only values that are different. My actual tables are not quite that simple, but I don't think it was relavent to this issue.

    AMOUNT_TABLE

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT

    2013

    111111555555000010020131111115555551000100201311111155555520001002013111111555555300010020131111115555554000100

    BUDGET_TABLE

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT BUDGET

    2013

    1111115555553000200201311111155555540002002013111111555555500020020131111115555556000200

    Here's what I hope. Note that SUB_ACCOUNTs 0000, 1000, and 2000 show without budget amounts since there is not a corresponding line in the BUDGET_TABLE. And same for SUB_ACCOUNTs 5000 and 6000, they show budgets with no amount because there is not a corresponding line in the AMOUNT_TABLE.

    (exit)

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT BUDGET
    201311111155555500001000
    201311111155555510001000
    201311111155555520001000
    20131111115555553000100200
    20131111115555554000100200
    201311111155555550000200
    201311111155555560000200

    If all goes well, my question is clear. Any help on this would be greatly appreciated. Thanks in advance.

    Use the join ANSI - FULL OUTER JOIN syntax:

    with amount_table like)

    Select fiscal_year 2013, 1 period, 11111 acct_unit, 555555, 0000 sub_account, amount 100 of all the double union

    Select 2013,1,11111,555555,1000,100 from all the double union

    Select 2013,1,11111,555555,2000,100 from all the double union

    Select 2013,1,11111,555555,3000,100 from all the double union

    Select double 2013,1,11111,555555,4000,100

    ),

    budget_table like)

    Select 1 time, 11111 acct_unit, account 555555, sub_account 3000, 2013 fiscal_year, budget of 200 Union double all the

    Select 2013,1,11111,555555,4000,200 from all the double union

    Select 2013,1,11111,555555,5000,200 from all the double union

    Select double 2013,1,11111,555555,6000,200

    )

    Select nvl (a.fiscal_year, b.fiscal_year) fiscal_year,

    period of NVL (a.period, b.period),

    NVL (a.acct_unit, b.acct_unit) acct_unit.

    account of NVL (a.Account, b.Account),

    NVL (a.sub_account, b.sub_account) sub_account.

    Amount NVL(a.amount,0),

    NVL(b.budget,0) budget

    of amount_table one

    full join

    budget_table b

    on)

    a.Fiscal_Year = b.fiscal_year

    and

    a.period = b.period

    and

    a.acct_unit = b.acct_unit

    and

    a.Account = b.account

    and

    a.sub_account = b.sub_account

    )

    /

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT BUDGET
    ----------- ---------- ---------- ---------- ----------- ---------- ----------
    2013 1 11111 555555 0 100 0
    2013 1 11111 555555 1000 100 0
    2013 1 11111 555555 2000 100 0
    2013 1 11111 555555 3000 100 200
    2013 1 11111 555555 4000 100 200
    2013 1 11111 555555 6000 0 200
    2013 1 11111 555555 5000 0 200

    7 selected lines.

    SQL >

    SY.

  • Character with the ascii value '0' does not not in NVL...

    Hello

    I have a question, work with "Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi" as our Source and target. For a record in the nvl (COLUMN, 'AA') target is back 'AA' but the same matching record in the source: nvl (COLUMN, 'AA') returns nothing (a data field where nothing is there), why what is happening? Every point of view...

    Basically you have a CHR (0) in the column. And CHR (0) is not a NULL value. So its obvious NVL will not return AA.

    It could be interesting to ask Tom "Strange Chr (0) '

    See also this

    SQL > create table t
    2 as
    3 select cast (chr (0) as varchar2 (30)) c
    4 double;

    Table created.

    SQL > t desc;
    Name Null?    Type
    ---------------------- -------- ------------------------
    C VARCHAR2 (30)

    SQL > select c from t;

    C
    ------------------------------

    SQL > select nvl (c, 'a') t;

    NVL (C, 'A')
    ------------------------------

    SQL > select dump t (c);

    DUMP (C)
    ------------------------------
    Typ = 1 Len = 1:0

    SQL > select nvl (replace (c, chr (0)), 'a') t;

    NVL (REPLACE (C, CHR (0)), 'A')
    ------------------------------
    one

    SQL >

  • Query NVL

    Dear experts,

    I have a code like this.
    DECLARE
    a VARCHAR2 (1);
    b VARCHAR2 (1);
    c VARCHAR2 (1);
    BEGIN
    b: = NULL;
    c : = a ' ;
    a = NVL (b, c);
    If a = a ' CAN
    a: = 'E '.
    END IF;
    END;

    My question is how can I write the article

    a = NVL (b, c);
    If a = a ' CAN
    a: = 'E '.
    END IF;

    In a single expression.

    Concerning
    Rajat

    use DECODING... not tested

    select
         DECODE(
              NVL(b,c), 'D', 'E'
         ) into a
    from dual;
    

    Something like that?

    SQL> DECLARE
      2     a   VARCHAR2 (1);
      3     b   VARCHAR2 (1);
      4     c   VARCHAR2 (1);
      5  BEGIN
      6     b := NULL;
      7     c := 'D';
      8     a := NVL (b, c);
      9
     10     /*IF a = 'D'
     11     THEN
     12        a := 'E';
     13     END IF;*/
     14     select DECODE(NVL(b,c), 'D', 'E') into a from dual;
     15
     16     DBMS_OUTPUT.put_line ('a= ' || a || ', b= ' || b || ', c= ' || c);
     17  END;
     18  /
    a= E, b= , c= D
    
    PL/SQL procedure successfully completed.
    

Maybe you are looking for

  • Cookies and issue of profile

    How Firefox stores cookies? In other words, I understand that they are stored in a file in C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\d3z0e911.default. In one or several files called Cookies.sqlite. I have PC Tools Performance Toolkit

  • increase the resolution of 200 Hz to 1000 Hz

    I need speed my kinematic data must match the kinetic data that I use for my analysis by a factor of 5. I tried a linear interpolation, but as the ntimes value grows flattens my signal and I end up losing the shape of the data. This happens for inter

  • Computer brand new finds itself down and slow that I can't use it!

    I just bought a HP all-in-one computer and it is so bogged down and slow, I can hardly even typing this message.  I have not downloaded anything, but I hear it constantly running in the background.  It is almost impossible to hit, because the cursor

  • ASUS Eee Slate as a POS Station?

    How well this device would work as one point of sale in a restaurant or a small retail environment?  Can servers carry this autour and enter orders food & drink?  Saw also a blog comment on the need for a docking station, but in the meantime, this de

  • Updates windows 7

    I have windows 7, from 6-10 that my computer stop saying that it updates of 7 elements, they are all faloures, I tried to do this manual too but nothing happens, have ideas? Galina cordially