Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2003
    Location
    india,hyderabad
    Posts
    43

    Talking Unanswered: re: decode logic

    hi! ,

    if x = 1 and y = 2 then
    z = 3;
    elsif x= 5 then
    z := 6;
    else
    z := 7;
    end if;

    how do i encorporate this logic into
    a single select decode statement ...
    harry

  2. #2
    Join Date
    Mar 2002
    Location
    Reading, UK
    Posts
    1,137
    try using nested decodes or use case instead.

    Alan

  3. #3
    Join Date
    Dec 2003
    Location
    Noida, India.
    Posts
    171

    Re: re: decode logic

    Using decode:
    select x,y,decode(x,1,decode(y,2,3,7), 5,6,7) z from t;


    Using case:
    select x,y,case x when '1'
    then case y when '2'
    then 3
    else 7
    end
    when '5' then 6
    else 7
    end z
    from t;

    Output from above two is:

    X Y Z
    - - ----------
    1 2 3
    1 3 7
    5 6
    6 7


    Originally posted by hreddy007
    hi! ,

    if x = 1 and y = 2 then
    z = 3;
    elsif x= 5 then
    z := 6;
    else
    z := 7;
    end if;

    how do i encorporate this logic into
    a single select decode statement ...
    Oracle can do wonders !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •