I need help with Analytic Function

Hi,
I have this little problem that I need help with.
My datafile has thousands of records that look like...
Client_Id Region Countries
[1] [1] [USA, Canada]
[1] [2] [Australia, France, Germany]
[1] [3] [China, India, Korea]
[1] [4] [Brazil, Mexico]
[8] [1] [USA, Canada]
[9] [1] [USA, Canada]
[9] [4] [Argentina, Brazil]
[13] [1] [USA, Canada]
[15] [1] [USA]
[15] [4] [Argentina, Brazil]
etc
My task is is to create a report with 2 columns - Client_Id and Countries, to look something like...
Client_Id Countries
[1] [USA, Canada, Australia, France, Germany, China, India, Korea, Brazil, Mexico]
[8] [USA, Canada]
[9] [USA, Canada, Argentina, Brazil]
[13] [USA, Canada]
[15] [USA, Argentina, Brazil]
etc.
How can I achieve this using Analytic Function(s)?
Thanks.
BDF

Hi,
That's called String Aggregation , and the following site shows many ways to do it:
http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
Which one should you use? That depends on which version of Oracle you're using, and your exact requirements.
For example, is order importatn? You said the results shoudl include:
CLIENT_ID  COUNTRIES
1        USA, Canada, Australia, France, Germany, China, India, Korea, Brazil, Mexicobut would you be equally happy with
CLIENT_ID  COUNTRIES
1        Australia, France, Germany, China, India, Korea, Brazil, Mexico, USA, Canadaor
CLIENT_ID  COUNTRIES
1        Australia, France, Germany, USA, Canada, Brazil, Mexico, China, India, Korea?
Mwalimu wrote:
... How can I achieve this using Analytic Function(s)?The best solution may not involve analytic functions at all. Is that okay?
If you'd like help, post your best attempt, a little sample data (CREATE TABLE and INSERT statements), the results you want from that data, and an explanation of how you get those results from that data.
Always say which version of Oracle you're using.
Edited by: Frank Kulash on Aug 29, 2011 3:05 PM

Similar Messages

  • Help with analytical function

    I successfully use the following analytical function to sum all net_movement of a position (key for a position: bp_id, prtfl_num, instrmnt_id, cost_prc_crncy) from first occurrence until current row:
    SELECT SUM (net_movement) OVER (PARTITION BY bp_id, prtfl_num, instrmnt_id, cost_prc_crncy ORDER BY TRUNC (val_dt) RANGE BETWEEN UNBOUNDED PRECEDING AND 0 FOLLOWING) holding,
    what i need is another column to sum net_movement of a position but only for the current date, but all my approaches fail..
    - add the date (val_dt) to the 'partition by' clause and therefore sum only values with same position and date
    SELECT SUM (net_movement) OVER (PARTITION BY val_dt, bp_id, prtfl_num, instrmnt_id, cost_prc_crncy ORDER BY TRUNC (val_dt) RANGE BETWEEN UNBOUNDED PRECEDING AND 0 FOLLOWING) today_net_movement
    - take the holding for the last date and subtract it from the current holding afterwards
    SELECT SUM (net_movement) OVER (PARTITION BY bp_id, prtfl_num, instrmnt_id, cost_prc_crncy ORDER BY TRUNC (val_dt) RANGE BETWEEN UNBOUNDED PRECEDING AND -1 FOLLOWING) last_holding,
    - using lag on the analytical function which calculates holding fails too
    I also want to avoid creating a table which stores the last holding..
    Does anyone sees where I make a mistake or knows an alternative to get this value?
    It would help me much!
    Thanks in advance!

    Thank you,
    but I already tried that but it returns strange values which are not the correct ones for sure.
    It is always the same value for each row, if its not 0, and a very high one (500500 for example), even if the sum of all net_movement of that date is 0 (and the statement for holding returns 0 too)
    I also tried witch trunc(val_dt,'DDD') with the same result (without trunc it is the same issue)
    please help if you can, thanks in advance!

  • Help with analytical function   (ora 9...)

    Hi everyone, is there a way to fill some missing numbers based on what have come before and after that missing number by starttime and based on how many missing data are between? ... by "simple" select? I know how to do that just theoreticly with simple math commands, but is there a way to apply them in sql (analytical functions)?
    Thanks in advance for any ideas !
    The missing number on line 17 could be calculated as 339+(1/2)*(356-339) = 347,5
    The missing number on line 23 could be calculated as 355+(1/3)*(292-355) = 334
    The missing number on line 24 could be calculated as 355+(2/3)*(292-355) = 313
    rownumber + temp_table (starttime,data_column)
    15     23.5.2007 16:15     ,     258
    16     23.5.2007 16:30     ,     339
    17     23.5.2007 16:45     ,     
    18     23.5.2007 17:00     ,     356
    19     23.5.2007 17:15     ,     373
    20     23.5.2007 17:30     ,     355
    21     23.5.2007 17:45     ,     363
    22     23.5.2007 18:00     ,     355
    23     23.5.2007 18:15     ,     
    24     23.5.2007 18:30     ,     
    25     23.5.2007 19:00     ,     292
    26     23.5.2007 19:15     ,     295
    THANKS
    Message was edited by:
    dusoo

    Way too late, but I wouldn't let my effort go unpublished ;-)
    SQL> create table temp_table
      2  as
      3  select 15 rownumber, to_date('23.5.2007 16:15','dd.mm.yyyy hh24:mi') starttime, 258 data_column from dual union all
      4  select 16, to_date(' 23.5.2007 16:30','dd.mm.yyyy hh24:mi'), 339 from dual union all
      5  select 17, to_date(' 23.5.2007 16:45','dd.mm.yyyy hh24:mi'), null from dual union all
      6  select 18, to_date(' 23.5.2007 17:00','dd.mm.yyyy hh24:mi'), 356 from dual union all
      7  select 19, to_date(' 23.5.2007 17:15','dd.mm.yyyy hh24:mi'), 373 from dual union all
      8  select 20, to_date(' 23.5.2007 17:30','dd.mm.yyyy hh24:mi'), 355 from dual union all
      9  select 21, to_date(' 23.5.2007 17:45','dd.mm.yyyy hh24:mi'), 363 from dual union all
    10  select 22, to_date(' 23.5.2007 18:00','dd.mm.yyyy hh24:mi'), 355 from dual union all
    11  select 23, to_date(' 23.5.2007 18:15','dd.mm.yyyy hh24:mi'), null from dual union all
    12  select 24, to_date(' 23.5.2007 18:30','dd.mm.yyyy hh24:mi'), null from dual union all
    13  select 25, to_date(' 23.5.2007 19:00','dd.mm.yyyy hh24:mi'), 292 from dual union all
    14  select 26, to_date(' 23.5.2007 19:15','dd.mm.yyyy hh24:mi'), 295 from dual
    15  /
    Tabel is aangemaakt.
    SQL> with t as
      2  ( select t.*
      3         , max(case when data_column is not null then rownumber end) over (order by rownumber) lowerbound
      4         , last_value(data_column ignore nulls) over (order by rownumber) prevvalue
      5         , min(case when data_column is not null then rownumber end) over (order by rownumber desc) upperbound
      6         , last_value(data_column ignore nulls) over (order by rownumber desc) nextvalue
      7      from temp_table t
      8  )
      9  select rownumber
    10       , starttime
    11       , case
    12         when data_column is not null then data_column
    13         else   prevvalue * ((upperbound - rownumber) / (upperbound - lowerbound))
    14              + nextvalue * ((rownumber - lowerbound) / (upperbound - lowerbound))
    15         end data_column
    16    from t
    17   order by rownumber
    18  /
                                 ROWNUMBER STARTTIME                                      DATA_COLUMN
                                        15 23-05-2007 16:15:00                                    258
                                        16 23-05-2007 16:30:00                                    339
                                        17 23-05-2007 16:45:00                                  347,5
                                        18 23-05-2007 17:00:00                                    356
                                        19 23-05-2007 17:15:00                                    373
                                        20 23-05-2007 17:30:00                                    355
                                        21 23-05-2007 17:45:00                                    363
                                        22 23-05-2007 18:00:00                                    355
                                        23 23-05-2007 18:15:00                                    334
                                        24 23-05-2007 18:30:00                                    313
                                        25 23-05-2007 19:00:00                                    292
                                        26 23-05-2007 19:15:00                                    295
    12 rijen zijn geselecteerd.Regards,
    Rob.

  • Need help with MAX function to return values

    I am trying to create a report to return slow moving inventory data. One of the requests is that it return only the latest date that an item transacted upon. One sheet will show the last receipt date for a part, another will show the last time a part was issued or shipped on a sales order.
    The hiccup is that it is returning every single last time that an item was received, and every single last issuance of the material (on the second sheet) of items on hand.
    Could someone help me to define the max value function? As listed below, and many variations, the sheet comes up with no data or corrupt dates.
    MAX(Transaction Date MAX) OVER(PARTITION BY Material Transactions.Item ORDER BY Material Transactions.Item )
    Still returns both the following when in reality I just want the one with the most recent date (April 2010).
    100034     BNDSCE-105 - QUALITY BEARINGS OR EQUIVILANT     A400M     AB01D..     $0.00     WIP component issue     11-Sep-2009     -3
    100034     BNDSCE-105 - QUALITY BEARINGS OR EQUIVILANT     A400M     AD01D..     $0.00     WIP component issue     13-Apr-2010     -16
    Thank you for your assistance.
    Becka

    Hi Becka
    It does look correct. When I look at your data I can see 2 different items:
    100034 BNDSCE-105 - QUALITY BEARINGS OR EQUIVILANT A400M AB01D.. $0.00 WIP component issue 11-Sep-2009 -3
    100034 BNDSCE-105 - QUALITY BEARINGS OR EQUIVILANT A400M AD01D.. $0.00 WIP component issue 13-Apr-2010 -16
    One is AB01D and the other being AD01D. Is this expected?
    To get the right date you might want to PARTITION BY the BNDSCE-105 which might be the Item Number?
    If you can get your calculation to return the correct date then you next need to put in a new condition where the Transaction Date = MAX Transaction Date
    One part of the function that I would question is the use of MAX in both parts like this: MAX(Transaction Date MAX). You might be better just using MAX(Transaction Date) OVER ......
    Does this help?
    Best wishes
    Michael

  • Need help with effect / function stop!

    Hi all!
    I tried to build some kind of custom pop-up-menu with fade
    in/out effect, however the menu sometimes (< very often, but not
    always) disappears while the mouse is still over it.
    So i defined a function to stop/abort the effects, but this
    doesn't work right.
    Could anybody please tell me, how to stop all functions,
    while the mouse is over a link?
    /// This is the container to appear / disappear:
    <div id="navislide" style="height:292px;
    overflow:hidden;">
    <a href="mylink.html" onMouseOver="killall();"
    onMouseOut="hideit();">mylink</a>
    </div>
    /// This is the link to show the container:
    <a href="#"
    onMouseOver="slidefadein.start();">mylink</a>
    <script type="text/javascript">
    function displayblock() {
    var thediv = document.getElementById('navislide');
    thediv.style.display= "block";
    slidetimer = setTimeout('slidefadeout.start();', 2000);
    hideit = function() {
    slidetimer = setTimeout('slidefadeout.start();', 2000);
    function displaynone() {
    var thediv = document.getElementById('navislide');
    thediv.style.display= "none";
    killall = function() {
    clearTimeout(slidetimer);
    slidefadeout.stop();
    slidefadein.stop();
    displayblock();
    slidefadeup.start();
    var slidefadein = new Spry.Effect.Fade("navislide", {from:0,
    to:100, toggle:false, setup:displayblock, finish:hideit});
    var slidefadeout = new Spry.Effect.Fade("navislide",
    {from:100, to:0, toggle:false, finish:displaynone});
    var slidefadeup = new Spry.Effect.Fade("navislide",
    {from:100, to:100, toggle:false});
    </script>
    Probably, its all about the "killall"-function, because when
    the mouse moves over the link, the function to abort all other
    effects, does not take effect.
    Thank you so much vor any kind of help or hint!!
    Cheers,
    idefix

    I would be most interested in a reply to this for I asked
    weeks ago how to use an onClick stop() function for the links in my
    page. I was given the stop function by VFusion (it is to stop
    panels from rotating), but I could never figure out how to actually
    get the function to stop the panels and could not get it no matter
    what I tried, eventually had to take the panel rotation out.

  • Need help with responsibility/ functions query

    hi,
    we are working in oracle applications 11i.
    I have a requirement to extract the responsibility list of functions and menus.
    I need to omit the excluded menus from each responsibility
    this what I have so far (after researching the internet):
    SELECT
    FRTL.RESPONSIBILITY_NAME,
    FFL.USER_FUNCTION_NAME, FFF.FUNCTION_NAME,ft.RESPONSIBILITY_NAME
    FROM
    FND_USER_RESP_GROUPS FURG,
    fnd_responsibility_tl ft ,
    FND_RESPONSIBILITY FR,
    FND_COMPILED_MENU_FUNCTIONS FCMF,
    FND_FORM_FUNCTIONS FFF,
    FND_RESPONSIBILITY_TL FRTL,
    FND_FORM_FUNCTIONS_TL FFL
    WHERE
    FURG.RESPONSIBILITY_ID = FR.RESPONSIBILITY_ID
    and ft.RESPONSIBILITY_ID(+)= fr.RESPONSIBILITY_ID
    AND FURG.RESPONSIBILITY_APPLICATION_ID = FR.APPLICATION_ID
    AND FR.MENU_ID = FCMF.MENU_ID
    AND FCMF.GRANT_FLAG = 'Y'
    AND FCMF.FUNCTION_ID = FFF.FUNCTION_ID
    AND SYSDATE BETWEEN FR.START_DATE AND NVL(FR.END_DATE, SYSDATE+1)
    and fr.CREATION_DATE >= to_date('01-jan-2005','dd-mon-yyyy')
    AND FURG.RESPONSIBILITY_ID = FRTL.RESPONSIBILITY_ID
    AND FR.RESPONSIBILITY_ID = FRTL.RESPONSIBILITY_ID
    AND FRTL.LANGUAGE = 'US'
    AND FFL.LANGUAGE = 'US'
    AND FFF.FUNCTION_ID = FFL.FUNCTION_ID
    AND (FURG.END_DATE > SYSDATE
    OR FURG.END_DATE IS NULL)
    AND FFF.FUNCTION_NAME NOT IN
    SELECT FF.FUNCTION_NAME
    FROM FND_RESPONSIBILITY R, FND_USER_RESP_GROUPS RG
    , FND_RESP_FUNCTIONS RF, FND_FORM_FUNCTIONS FF, FND_RESPONSIBILITY_TL FRTL
    WHERE RG.RESPONSIBILITY_ID = R.RESPONSIBILITY_ID
    AND RF.RESPONSIBILITY_ID = R.RESPONSIBILITY_ID
    AND RF.RULE_TYPE = 'F'
    AND FF.FUNCTION_ID = RF.ACTION_ID
    AND FRTL.RESPONSIBILITY_ID = R.RESPONSIBILITY_ID
    AND FRTL.RESPONSIBILITY_ID = RG.RESPONSIBILITY_ID
    AND FRTL.LANGUAGE = 'US'
    help me please to exclude the menus.

    tried it and had the following error:
    if((tbl_menu_id.FIRST is NULL) or (tbl_menu_id.FIRST 1)) then
    ERROR at line 136:
    ORA-06550: line 136, column 54:
    PLS-00103: Encountered the symbol "1" when expecting one of the following:
    *. ( ) , * @ % & | = - + < / > at in is mod not range rem =>*
    *.. <an exponent (**)> <> or != or ~= >= <= <> and or like*
    between ||
    The symbol "," was substituted for "1" to continue.
    from another perspective, from applications front end, when I press ctrl +L on any responsibility menu, I get the list of the forms names.
    which database tables can I get that from?

  • Need help with Math functions for text-based calculator!!!

    I have the calculator working but I am having trouble figuring out thow to do a square root function, nth factorial, absolute value, and Fibonacci. Basically i got the easy part done. Also I am using the case to do the funtions but I am not sure if there are symbols on the keyboard that are commonly used for these funtions so i just made some up. I am new to java and this is only my second assignment so any help would be appreciated. Thanks
    import java.util.*;
    import java.math.*;
    public class calculator
    static Scanner console=new Scanner(System.in);
    public static void main(String[]args)
    double num1=0,num2=0;
    double result=0;
    char expression;
    char operation;
    String Soperation;
    System.out.println("Enter ? for help or enter the operation in which to be processed");
    Soperation=console.next();
    operation = Soperation.charAt(0);
    switch(operation)
    case '+':
    System.out.println("Please the first number");
    num1=console.nextInt();
    System.out.println("Please enter the second number");
    num2=console.nextInt();
    result=num1+num2;
    break;
    case'-':
    System.out.println("Please the first number");
    num1=console.nextInt();
    System.out.println("Please enter the second number");
    num2=console.nextInt();
    result=num1-num2;
    break;
    case'*':
    System.out.println("Please the first number");
    num1=console.nextInt();
    System.out.println("Please enter the second number");
    num2=console.nextInt();
    result=num1*num2;
    break;
    case'/':
    System.out.println("Please the first number");
    num1=console.nextInt();
    System.out.println("Please enter the second number");
    num2=console.nextInt();
    if(num2==0)
    System.out.println("Cannot Divide by Zero");
    result=num1/num2;
    break;
    //square root
    case'^':
    System.out.println("Please enter a number");
    break;
    //fibonacci     
    case'#':
    System.out.println("Please enter the position of the Fibonacci number");
    break;
    //factorial
    case'!':
    System.out.println("Please enter the number for factoring");
    break;
              //absolute value
    case'&':
    System.out.println("Please enter a number");
    num1=console.nextInt();
    result=num1;
    break;
         // help funtion
    case'?':
    System.out.println("Type + for addition, - for subtraction");
    System.out.println("* for multipliction, / for division,^ for the square root");
    System.out.println(" & for absolute value, # for fibonacci,and ! for factorial");
    break;
    System.out.println("The result is:"+result);     
    }

    rmabrey wrote:
    I have the calculator working but I am having trouble figuring out thow to do a square root function, nth factorial, absolute value, and Fibonacci. java.lang.Math.sqrt()
    nothing for factorial - write your own.
    java.lang.Math.abs()
    nothing for Fibonacci - write your own.
    %

  • Help with analytic function

    Hello.
    I am not used to anaylitic funtions and after reading a lot about them I am very confused.
    I have a situation similar to the test_table I post below, I have a table with 2 columns event_code (number) and event_date (date) which make the primary key. I need to see all the event_code's and event_date's of the table, I also need to compare the columns value1 and value2 so that if value1>value2 and event_date for that record belongs to september of 2008 it takes the value 1 (0 otherwise):
    WITH test_table AS
         (SELECT 1 event_code, ADD_MONTHS (SYSDATE - 1, -3) event_date, 1 value1,
                 1 value2
            FROM DUAL
          UNION
          SELECT 1 event_code, ADD_MONTHS (SYSDATE - 1, -2) event_date, 3 value1,
                 2 value2
            FROM DUAL
          UNION
          SELECT 1 event_code, ADD_MONTHS (SYSDATE - 1, -4) event_date,
                 100 value1, -1 value2
            FROM DUAL
          UNION
          SELECT 2 event_code, ADD_MONTHS (SYSDATE - 2, -3) event_date,
                 122 value1, 1 value2
            FROM DUAL
          UNION
          SELECT 2 event_code, ADD_MONTHS (SYSDATE - 2, -2) event_date,
                 133 value1, -4 value2
            FROM DUAL
          UNION
          SELECT 2 event_code, ADD_MONTHS (SYSDATE - 2, -1) event_date,
                 1454 value1, 1 value2
            FROM DUAL
          UNION
          SELECT 3 event_code, ADD_MONTHS (SYSDATE - 3, -3) event_date,
                 125 value1, 1 value2
            FROM DUAL
          UNION
          SELECT 3 event_code, ADD_MONTHS (SYSDATE - 3, -2) event_date,
                 1888 value1, -1 value2
            FROM DUAL
          UNION
          SELECT 3 event_code, ADD_MONTHS (SYSDATE - 3, -1) event_date,
                 144 value1, 1 value2
            FROM DUAL)
    SELECT event_code, event_date, value1, value2,
           CASE
              WHEN ( (value1 > value2) AND (event_date BETWEEN TO_DATE ('09/01/2008 00:00:00','mm/dd/yyyy hh24:mi:ss') AND TO_DATE ('09/30/2008 23:59:59','mm/dd/yyyy hh24:mi:ss')))
                 THEN 1
              ELSE 0
           END bigger
      FROM test_table
    EVENT_CODE EVENT_DA     VALUE1     VALUE2     BIGGER
             1 20/06/08        100         -1          0
             1 20/07/08          1          1          0
             1 20/08/08          3          2          0
             2 19/07/08        122          1          0
             2 19/08/08        133         -4          0
             2 19/09/08       1454          1          1
             3 18/07/08        125          1          0
             3 18/08/08       1888         -1          0
             3 18/09/08        144          1          1
    9 rows selected.Finally and here comes my problem, I need to see, for each row, the maximun date for the event_code of the row whenever that maximun date belongs to september of 2008 (null otherwise), I have not been able to write that, this is the result I need to see:
    EVENT_CODE EVENT_DATE       VALUE1     VALUE2     BIGGER  LAST_DATE
             1   20/06/08          100         -1          0          
             1   20/07/08            1          1          0          
             1   20/08/08            3          2          0          
             2   19/07/08          122          1          0   19/09/08
             2   19/08/08          133         -4          0   19/09/08
             2   19/09/08         1454          1          1   19/09/08
             3   18/07/08          125          1          0   18/09/08
             3   18/08/08         1888         -1          0   18/09/08
             3   18/09/08          144          1          1   18/09/08
    9 rows selected.And this is my try (wrong):
    /* Formatted on 2008/10/21 10:48 (Formatter Plus v4.8.8) */
    WITH test_table AS
         (SELECT 1 event_code, ADD_MONTHS (SYSDATE - 1, -3) event_date, 1 value1,
                 1 value2
            FROM DUAL
          UNION
          SELECT 1 event_code, ADD_MONTHS (SYSDATE - 1, -2) event_date, 3 value1,
                 2 value2
            FROM DUAL
          UNION
          SELECT 1 event_code, ADD_MONTHS (SYSDATE - 1, -4) event_date,
                 100 value1, -1 value2
            FROM DUAL
          UNION
          SELECT 2 event_code, ADD_MONTHS (SYSDATE - 2, -3) event_date,
                 122 value1, 1 value2
            FROM DUAL
          UNION
          SELECT 2 event_code, ADD_MONTHS (SYSDATE - 2, -2) event_date,
                 133 value1, -4 value2
            FROM DUAL
          UNION
          SELECT 2 event_code, ADD_MONTHS (SYSDATE - 2, -1) event_date,
                 1454 value1, 1 value2
            FROM DUAL
          UNION
          SELECT 3 event_code, ADD_MONTHS (SYSDATE - 3, -3) event_date,
                 125 value1, 1 value2
            FROM DUAL
          UNION
          SELECT 3 event_code, ADD_MONTHS (SYSDATE - 3, -2) event_date,
                 1888 value1, -1 value2
            FROM DUAL
          UNION
          SELECT 3 event_code, ADD_MONTHS (SYSDATE - 3, -1) event_date,
                 144 value1, 1 value2
            FROM DUAL)
    SELECT event_code, event_date, value1, value2,
           CASE
              WHEN ( (value1 > value2) AND (event_date BETWEEN TO_DATE ('09/01/2008 00:00:00','mm/dd/yyyy hh24:mi:ss') AND TO_DATE ('09/30/2008 23:59:59','mm/dd/yyyy hh24:mi:ss')))
                 THEN 1
              ELSE 0
           END bigger,
           LAST_VALUE (event_date) OVER (PARTITION BY event_code ORDER BY event_date range between TO_DATE ('09/01/2008 00:00:00','mm/dd/yyyy hh24:mi:ss') PRECEDING and TO_DATE ('09/30/2008 23:59:59','mm/dd/yyyy hh24:mi:ss') FOLLOWING ) last_date
      FROM test_tableThanks in advance.

    I have added a new column to my test_table value3 (number) and I need to see, for each row the value that that column has when it is in the record with has event_date=last_date for each code.
    I have tried this:
    SQL> r
      1  WITH test_table AS
      2       (SELECT 1 event_code, ADD_MONTHS (SYSDATE - 1, -3) event_date, 1 value1,
      3               1 value2, 9 value3
      4          FROM DUAL
      5        UNION ALL
      6        SELECT 1 event_code, ADD_MONTHS (SYSDATE - 1, -2) event_date, 3 value1,
      7               2 value2, 8 value3
      8          FROM DUAL
      9        UNION ALL
    10        SELECT 1 event_code, ADD_MONTHS (SYSDATE - 1, -4) event_date,
    11               100 value1, -1 value2, 7 value3
    12          FROM DUAL
    13        UNION ALL
    14        SELECT 2 event_code, ADD_MONTHS (SYSDATE - 2, -3) event_date,
    15               122 value1, 1 value2, 6 value3
    16          FROM DUAL
    17        UNION ALL
    18        SELECT 2 event_code, ADD_MONTHS (SYSDATE - 2, -2) event_date,
    19               133 value1, -4 value2, 5 value3
    20          FROM DUAL
    21        UNION ALL
    22        SELECT 2 event_code, ADD_MONTHS (SYSDATE - 2, -1) event_date,
    23               1454 value1, 1 value2, 4 value3
    24          FROM DUAL
    25        UNION ALL
    26        SELECT 3 event_code, ADD_MONTHS (SYSDATE - 3, -3) event_date,
    27               125 value1, 1 value2, 3 value3
    28          FROM DUAL
    29        UNION ALL
    30        SELECT 3 event_code, ADD_MONTHS (SYSDATE - 3, -2) event_date,
    31               1888 value1, -1 value2, 2 value3
    32          FROM DUAL
    33        UNION ALL
    34        SELECT 3 event_code, ADD_MONTHS (SYSDATE - 3, -1) event_date,
    35               144 value1, 1 value2, 1 value3
    36          FROM DUAL)
    37  SELECT   event_code, event_date, value1, value2, value3,
    38           CASE
    39              WHEN (    (value1 > value2)
    40                    AND (event_date BETWEEN TO_DATE ('09/01/2008 00:00:00',
    41                                                     'mm/dd/yyyy hh24:mi:ss'
    42                                                    )
    43                                        AND TO_DATE ('09/30/2008 23:59:59',
    44                                                     'mm/dd/yyyy hh24:mi:ss'
    45                                                    )
    46                        )
    47                   )
    48                 THEN 1
    49              ELSE 0
    50           END bigger,
    51           CASE
    52              WHEN MAX (event_date) OVER (PARTITION BY event_code)
    53                     BETWEEN TO_DATE ('09/01/2008 00:00:00',
    54                                      'mm/dd/yyyy hh24:mi:ss'
    55                                     )
    56                         AND TO_DATE ('09/30/2008 23:59:59',
    57                                      'mm/dd/yyyy hh24:mi:ss'
    58                                     )
    59                 THEN MAX (event_date) OVER (PARTITION BY event_code)
    60              ELSE NULL
    61           END last_date,
    62           CASE
    63              WHEN MAX (event_date) OVER (PARTITION BY event_code)
    64                     BETWEEN TO_DATE ('09/01/2008 00:00:00',
    65                                      'mm/dd/yyyy hh24:mi:ss'
    66                                     )
    67                         AND TO_DATE ('09/30/2008 23:59:59',
    68                                      'mm/dd/yyyy hh24:mi:ss'
    69                                     )
    70                 THEN LAST_VALUE (value3) OVER (PARTITION BY event_code ORDER BY event_date)
    71              ELSE NULL
    72           END last_value3
    73      FROM test_table
    74* ORDER BY 1, 2
    EVENT_CODE EVENT_DA     VALUE1     VALUE2     VALUE3     BIGGER LAST_DAT LAST_VALUE3
             1 20/06/08        100         -1          7          0
             1 20/07/08          1          1          9          0
             1 20/08/08          3          2          8          0
             2 19/07/08        122          1          6          0 19/09/08           6
             2 19/08/08        133         -4          5          0 19/09/08           5
             2 19/09/08       1454          1          4          1 19/09/08           4
             3 18/07/08        125          1          3          0 18/09/08           3
             3 18/08/08       1888         -1          2          0 18/09/08           2
             3 18/09/08        144          1          1          1 18/09/08           1
    9 rows selected.But what I want is (I am sorry for my ignorance but I don't unerstand why the "ORDER BY event_date" "breaks" my "PARTITION BY event_code"):
    EVENT_CODE EVENT_DA     VALUE1     VALUE2     VALUE3     BIGGER LAST_DAT LAST_VALUE3
             1 20/06/08        100         -1          7          0
             1 20/07/08          1          1          9          0
             1 20/08/08          3          2          8          0
             2 19/07/08        122          1          6          0 19/09/08           4
             2 19/08/08        133         -4          5          0 19/09/08           4
             2 19/09/08       1454          1          4          1 19/09/08           4
             3 18/07/08        125          1          3          0 18/09/08           1
             3 18/08/08       1888         -1          2          0 18/09/08           1
             3 18/09/08        144          1          1          1 18/09/08           1Thanks again.

  • Need help with DECODE function

    Hello,
    I am trying to use default within the decode function and every time I get a missing expression. I have searched everywhere and cant figure out what I'm doing wrong. Thanks
    select decode (request_id,0,'No files found', DEFAULT)

    Hi,
    Welcome to the forum!
    When you use a default value, the last argument to DECODE is the actual value you want as a default.
    For example:
    SELECT       ename
    ,       deptno
    ,       DECODE ( deptno
                 , 30     , 'Sales'
                      , 'All others'     -- Default value
                  )                 AS dname
    FROM      scott.emp
    ORDER BY  ename
    ;Output:
    ENAME          DEPTNO DNAME
    ADAMS              20 All others
    ALLEN              30 Sales
    BLAKE              30 Sales
    CLARK              10 All others
    FORD               20 All others
    JAMES              30 Sales
    JONES              20 All others
    KING               10 All others
    MARTIN             30 Sales
    MILLER             10 All others
    SCOTT              20 All others
    SMITH              20 All others
    TURNER             30 Sales
    WARD               30 Sales 
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    If you can show the problem using commonly available tables (such as those in the scott schema) then you don't need to post any sample data; just the results and the explanation.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • Need Help With a Function

    Hope this is the right place to ask.
    I have a field that looks like this: LastName, First Name Middle Name Other Name
    I need to have a Last Name field, and a First Name (and possibly other) field.
    In other words, I need to be able to pull out eveything on either side of the comma.
    I know this should be simple; just don't have the time to figure it out for myself.
    Thanks in advance.

    This will extract the last name. This formula bas based on one that looked for spaces, not commas, so you may not need the TRIM functions in there. Plus it does some other checking.
    =IFERROR(LEFT(TRIM(B2),SEARCH(",",TRIM(B2))-1),IF(ISBLANK(B2),"",TRIM(B2)))
    more basic is
    =LEFT(B2,SEARCH(",",B2)-1)

  • Need help with Timer function

    I am using a timer class for my application such that when i log in, i immediately call the timer.start function from the Timer.java class.
    The problem i am having, is that when this timer expires, it calls an exit function, but i want it to restart the original application. i have tried to create an instance of the old session to kill its timer and a new instance that spawns a new start page, but this doesnt work well because i have both applications running and if i close either one of them, both get killed!!
    Can anyone help me out in this regard?
    Sule.
    public void timeout()
            System.err.println ("terminating");        
            System.exit(1);
                         // instance.getContentPane().add(d2.new StartPage());                     
                         // instance.setVisible(true);
                         // previousInstance.timer.stop();
            }

    hey Uhrand.. thanks for your suggestions. I really appreciate them, however it doesnt completely solve my problem. As I stated before my Timer program runs in its own class file. so i have in one class file
    public class Timer extends thread {
    public static Application dl = new Application();
    public void timeout()
                          System.err.println ("Logging-Off");
            new Application();             
            dl.timer.stop();
            }and then i have another class file for the main program like this...
    import java.awt.*;
    import javax.swing.*;
    public class Application {
        public Application() {
            app = new JFrame("'Application' restarts every 15 seconds");
            app.add(new JLabel("Please watch the Title of this frame"));
            app.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            app.setBounds((screenSize.width-400)/2, (screenSize.height-150)/2, 400, 150);
            app.setVisible(true);
            (new Thread(new Timer(app))).start();
        public static void main(String args[]) {new Application();}
        private JFrame app;
        private JFrame app;
    }when the timer expires, i am not able to create a new Application without the old Application.
    I would appreciate it if you can respond.
    thanks
    salau

  • Need help with search function in my program

    Hello all, some of you may remeber me from my previous inventory programs. Well I am finally on my last one and I need to add a search option to the code. Here is the class that will contain that option.
    import java.util.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class Inventory2 extends JFrame implements ActionListener {
    //Utility class for displaying the picture
    //If we are going to use a class/method/variable inside that class only, we declare it private in that class
    private class MyPanel extends JPanel {
    ImageIcon image = new ImageIcon("Sample.jpg");
    int width = image.getIconWidth();
    int height = image.getIconHeight();
    long angle = 30;
    public MyPanel(){
    super();
    public void paintComponent(Graphics g){
         super.paintComponent(g);
         Graphics2D g2d = (Graphics2D)g;
         g2d.rotate (Math.toRadians(angle), 60+width/2, 60+height/2);
         g2d.drawImage(image.getImage(), 60, 60, this);
         g2d.dispose();
    }//end class MyPanel
    int currentIndex; //Currently displayed Item
    Product[] supplies = new Product[4];
    JLabel name ;
    JLabel number;
    JLabel rating;
    JLabel quantity;
    JLabel price;
    JLabel fee;
    JLabel totalValue;
    JTextField nameField = new JTextField(20);
    JTextField numberField = new JTextField(20);
    JTextField ratingField = new JTextField(20);
    JTextField quantityField = new JTextField(20);
    JTextField priceField = new JTextField(20);
    JPanel display;
    JPanel displayHolder;
    JPanel panel;
    boolean locked = false; //Notice how I've used this flag to keep the interface clean
    public Inventory2() {
    makeTheDataItems();
    setSize(700, 500);
    setTitle("Inventory Program");
    //make the panels
    display = new JPanel();
    JPanel other = new JPanel();
    other.setLayout(new GridLayout(2, 1));
    JPanel picture = new MyPanel();
    JPanel buttons = new JPanel();
    JPanel centerPanel = new JPanel();
    displayHolder = new JPanel();
    display.setLayout(new GridLayout(7, 1));
    //other.setLayout(new GridLayout(1, 1));
    //make the labels
    name = new     JLabel("Name :");
    number = new JLabel("Number :");
    rating = new JLabel("Rating     :");
    quantity = new JLabel("Quantity :");
    price = new JLabel("Price     :");
    fee = new JLabel("Restocking Fee (5%) :");
    totalValue = new JLabel("Total Value :");
    //Use the utility method to make the buttons
    JButton first = makeButton("First");
    JButton next = makeButton("Next");
    JButton previous = makeButton("Previous");
    JButton last = makeButton("Last");
    JButton search = makeButton("Search");
    //Other buttons
    JButton add = makeButton("Add");
    JButton modify = makeButton("Modify");
    JButton delete = makeButton("Delete");
    JButton save = makeButton("Save");
    JButton exit = makeButton("Exit");
    //Add the labels to the display panel
    display.add(name);
    display.add(number);
    display.add(rating);
    display.add(quantity);
    display.add(price);
    display.add(fee);
    //add the buttons to the buttonPanel
    buttons.add(first);
    buttons.add(previous);
    buttons.add(next);
    buttons.add(last);
    buttons.add(search);
    //Add the picture panel and display to the centerPanel
    displayHolder.add(display);
    centerPanel.setLayout(new GridLayout(2, 1));
    centerPanel.add(picture);
    centerPanel.add(displayHolder);
    other.add(buttons);
    JPanel forAdd = new JPanel(); // add the other buttons to this panel
    forAdd.add(add);
    forAdd.add(modify);
    forAdd.add(delete);
    forAdd.add(save);
    forAdd.add(exit);
    other.add(forAdd);
    //Add the panels to the frame
    getContentPane().add(centerPanel, "Center");
    getContentPane().add(other, "South");
    this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    setVisible(true);
    private void makeTheDataItems () {
    Product p1 = new DVD("The one", 001, 200, 100, "The one");
    Product p2 = new DVD("Once upon a time in China V", 002, 500, 10000, "Once upon a time in China V");
    Product p3 = new DVD("Rat Race", 003, 100, 3000, "Rat Race");
    Product p4 = new DVD("The Man in the Iron Mask", 004, 3000, 9000, "The Man in the Iron Mask");
    supplies[0] = p1;
    supplies[1] = p2;
    supplies[2] = p3;
    supplies[3] = p4;
    //Utility method for creating and dressing buttons
    private JButton makeButton(String label) {
    JButton button = new JButton(label);
    button.setPreferredSize(new Dimension(100, 25));
    button.setActionCommand(label);
    button.addActionListener(this);
    return button;
    private void addItem() {
    panel = new JPanel();
    JPanel add = new JPanel();
    add.setLayout(new GridLayout(7, 2));
    JButton addIt = makeButton("Add Item");
    JLabel name = new JLabel("Name :");
    JLabel rating = new JLabel("Rating     :");
    JLabel quantity = new JLabel("Quantity :");
    JLabel price = new JLabel("Price     :");
    add.add(name); add.add(nameField);
    add.add(rating); add.add(ratingField);
    add.add(quantity); add.add(quantityField);
    add.add(price); add.add(priceField);
    panel.add(add);
    JPanel forAddIt = new JPanel();
    forAddIt.add(addIt);
    panel.add(forAddIt);
    displayHolder.remove(display);
    displayHolder.add(panel);
    //display = panel;
    this.setVisible(true);
    public static void main( String args[]) {
    new Inventory2().displayFirst(); //The main method should not have too much code
    } // end main method
    public void actionPerformed(ActionEvent event) {
      String command = event.getActionCommand(); //This retrieves the command that we set for the button
      //Always compare strings using the .equals method and not using ==
      if(command.equals("First")) {
       if(!locked) {
         displayFirst();
      else if(command.equals("Next")) {
       if(!locked) {
         displayNext();
      else if(command.equals("Previous")) {
       if(!locked) {
         displayPrevious();
      else if(command.equals("Last")) {
       if(!locked) {
         displayLast();
      else if(command.equals("Exit")) {
       this.dispose();
       System.exit(0);
      else if(command.equals("Add")) {
       if(!locked) {
         addItem();
         locked = true;
      else if(command.equals("Add Item")) {
       addItemToArray();
      else if(command.equals("Modify")) {
       if(!locked) {
         modify();
         locked = true;
      else if(command.equals("Update")) {
          if(!locked) {
         modifyItemInArray();
         locked = true;
      else if(command.equals("Delete")) {
       if(!locked) {
         DVD dvd = (DVD)supplies[currentIndex];
            int confirm = JOptionPane.showConfirmDialog(this, "Are you sure you want to delete item "+dvd.getItemNumber());
                if(confirm == JOptionPane.YES_OPTION) {
          removeItemAt(currentIndex);
          displayFirst();
    private void modify() {
    DVD dvd = (DVD)supplies[currentIndex];
    panel = new JPanel();
    JPanel add = new JPanel();
    add.setLayout(new GridLayout(7, 2));
    JButton update = makeButton("Update");
    JLabel number = new JLabel("Number :");
    JLabel name = new JLabel("Name :");
    JLabel rating = new JLabel("Rating     :");
    JLabel quantity = new JLabel("Quantity :");
    JLabel price = new JLabel("Price     :");
    add.add(number);
    numberField.setText(""+dvd.getItemNumber()); numberField.setEditable(false); add.add(numberField);
    add.add(name);
    nameField.setText(dvd.getItemName()); add.add(nameField);
    ratingField.setText(dvd.getRating()); ratingField.setEditable(false);
    add.add(rating); add.add(ratingField);
    add.add(quantity);
    quantityField.setText(""+dvd.getStockQuantity());
    add.add(quantityField);
    add.add(price);
    add.add(priceField); priceField.setText(""+dvd.getItemPrice());
    panel.add(add);
    JPanel forAddIt = new JPanel();
    forAddIt.add(update);
    panel.add(forAddIt);
    displayHolder.remove(display);
    displayHolder.add(panel);
    //display = panel;
          this.setVisible(true);
    private void addItemToArray() {
    Product p = new DVD(nameField.getText(), supplies.length + 1, Long.parseLong(quantityField.getText()),
    Double.parseDouble(priceField.getText()), ratingField.getText());
    //Extend size of array by one first
    Product[] ps = new Product[supplies.length + 1];
    for(int i = 0; i < ps.length-1; i++) {
    ps[i] = supplies;
    ps[supplies.length] = p;
    supplies = ps;
    displayHolder.remove(panel);
    displayHolder.add(display);
    displayLast();
    this.setVisible(false);
    this.setVisible(true);
    //Utility method to ease the typing and reuse code
    //This method reduces the number of lines of our code
    private void displayItemAt(int index) {
    DVD product = (DVD)supplies[index];
    name.setText("Item Name: "+ product.getItemName());
    number.setText("Item Number: "+ product.getItemNumber());
    rating.setText("Rating: "+ product.getRating());
    quantity.setText("Quantity In Stock: "+ product.getStockQuantity());
    price.setText("Item Price: "+ product.getItemPrice());
    totalValue.setText("Total: " + product.calculateInventoryValue());
    fee.setText("Restocking Fee (5%) :"+product.calculateRestockFee());
    locked = false;
    this.repaint();
    this.setVisible(true);
    private void modifyItemInArray() {
    Product p = new DVD(nameField.getText(), supplies.length + 1, Long.parseLong(quantityField.getText()),
    Double.parseDouble(priceField.getText()), ratingField.getText());
    supplies[currentIndex] = p;
    displayHolder.remove(panel);
    displayHolder.add(display);
         displayItemAt(currentIndex);
    this.setVisible(false);
    this.setVisible(true);
    private void removeItemAt(int index) {
    Product[] temp = new Product[supplies.length-1];
    int counter = 0;
    for(int i = 0; i < supplies.length;i++) {
    if(i == index) { //skip the item to delete
    else {
         temp[counter++] = supplies[i];
    supplies = temp;
    public void displayFirst() {
    displayItemAt(0);
    currentIndex = 0;
    public void displayNext() {
    if(currentIndex == supplies.length-1) {
    displayFirst();
    currentIndex = 0;
    else {
    displayItemAt(currentIndex + 1);
    currentIndex++;
    public void displayPrevious() {
    if(currentIndex == 0) {
    displayLast();
    currentIndex = supplies.length-1;
    else {
    displayItemAt(currentIndex - 1);
    currentIndex--;
    public void displayLast() {
    displayItemAt(supplies.length-1);
    currentIndex = supplies.length-1;
    }//end class Inventory2
    I am not sure where to put it and how to set it up. If you guys need the other two classes let me know. Thanks in advanced.

    Here are the other two classes:
    import java.util.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    class Product implements Comparable {
    String name;
    int number;
    long stockQuantity;
    double price;
    public Product() {
      name = "";
          number = 0;
          stockQuantity = 0L;
          price = 0.0;
    public Product(String name, int number, long stockQuantity, double price) {
      this.name = name;
          this.number = number;
          this.stockQuantity = stockQuantity;
          this.price = price;
         public void setItemName(String name) {
      this.name = name;
    public String getItemName() {
      return name;
    public void setItemNumber(int number) {
      this.number = number;
    public int getItemNumber() {
      return number;
    public void setStockQuantity(long quantity) {
      stockQuantity = quantity;
    public long getStockQuantity() {
      return stockQuantity;
    public void setItemPrice(double price) {
      this.price = price;
    public double getItemPrice() {
      return price;
    public double calculateInventoryValue() {
      return getItemPrice() * getStockQuantity();
    public int compareTo (Object o) {
      Product p = (Product)o;
      return name.compareTo(p.getItemName());
    public String toString() {
      return "Name :"+getItemName() + "\nNumber"+number+"\nPrice"+price+"\nQuantity"+stockQuantity + "\nValue :"+calculateInventoryValue();
    class DVD extends Product implements Comparable {
    private String rating;
    public DVD() {
      super(); //Call the constructor in Product
      rating = ""; //Add the additonal attribute
    public DVD(String name, int number, long stockQuantity, double price, String rating) {
      super(name, number, stockQuantity, price); //Call the constructor in Product
      this.rating = rating; //Add the additonal attribute
         public void setRating(String rating) {
      this.rating = rating;
    public String getRating() {
      return rating;
    public double calculateInventoryValue() {
      return getItemPrice() * getStockQuantity() + getItemPrice()*getStockQuantity()*0.05;
    public double calculateRestockFee() {
      return getItemPrice() * 0.05;
    public int compareTo (Object o) {
      Product p = (Product)o;
      return getItemName().compareTo(p.getItemName());
    public String toString() {
      return "Name :"+getItemName() + "\nNumber"+getItemNumber()+"\nPrice"+getItemPrice()+"\nQuantity"+getStockQuantity() +"\nRating :"+getRating()+"\nValue"+calculateInventoryValue();
    }You should be able to search through these items, and any other items that have been added to the program.

  • Need Help in analytic function (LAG)

    The requirement is like I have a table with belwo colums
    col1 count flag flag2
    abc 1 Y Y
    xyz 1 Y Y
    xyz 1 Y NULL
    xyz *2* N N
    xyz 2 Y NULL
    def 1 Y Y
    def 1 N NULL
    To get the flag2 columns
    1.Assign falg2 as flag for rownum=1
    2. We have to check the colm1,count of current row with colm1,count of previous row .if the colm1 and cnt are same then we have to assign null...
    Below is the query i used to get the flag2 values
    SELECT colm1,count,flag
    CASE WHEN
    LAG(count, 1,null) OVER (PARTITION BY colm1 ORDER BY colm1 DESC NULLS LAST) IS NULL
    and LAG(flag, 1, NULL) OVER (PARTITION BY colm1 ORDER BY colm1,cycle DESC NULLS LAST) IS NULL
    THEN flag
    END AS flag2
    FROM table1
    but the above query returns the below o/p which is wrong
    col1_ count flag flag2
    abc 1 Y Y
    xyz 1 Y Y
    xyz 1 Y NULL
    xyz *2* N NULL
    xyz 2 Y NULL
    def 1 Y Y
    def 1 N NULL
    Thanks
    Edited by: user9370033 on Apr 8, 2010 11:25 PM

    Well, you haven't quite explained your full requirement in this
    1.Assign falg2 as flag for rownum=1
    2. We have to check the colm1,count of current row with colm1,count of previous row .if the colm1 and cnt are same then we have to assign null...as you don't say what flag2 should be set to if com1 and cnt are not the same as the previous row.
    but how about this as my first guess what you mean...
    SQL> with t as (select 'abc' as col1, 1 as cnt, 'Y' as flag from dual union all
      2             select 'xyz', 1, 'Y' from dual union all
      3             select 'xyz', 1, 'Y' from dual union all
      4             select 'xyz', 2, 'N' from dual union all
      5             select 'xyz', 2, 'Y' from dual union all
      6             select 'def', 1, 'Y' from dual union all
      7             select 'def', 1, 'N' from dual)
      8  -- END OF TEST DATA
      9  select col1, cnt, flag
    10        ,case when lag(col1) over (order by col1, cnt) is null then flag
    11              when lag(col1) over (order by col1, cnt) = col1 and
    12                   lag(cnt) over (order by col1, cnt) = cnt then null
    13              else flag
    14         end as flag2
    15  from t
    16  /
    COL        CNT F F
    abc          1 Y Y
    def          1 Y Y
    def          1 N
    xyz          1 Y Y
    xyz          1 Y
    xyz          2 Y Y
    xyz          2 N
    7 rows selected.
    SQL>

  • [solved] Need Help with bash function

    I would like to have a bash function that lets me create tar.xz archives. I have the following in my bash now:
    mktar() { tar cf "${1%%/}.tar" "${1%%/}/"; }
    mktgz() { tar czf "${1%%/}.tar.gz" "${1%%/}/"; }
    mktbz() { tar cjf "${1%%/}.tar.bz2" "${1%%/}/"; }
    Any advice would be appreciated.
    Last edited by orphius1970 (2010-09-06 11:10:39)

    orphius1970 should learn some shell scripting.
    $FILE is obviously the archive name and is $1 the first argument.
    $* would be the rest of the arguments (only so after the shift command.
    So, archive archive_name list of files to be archived.
    Example: archive stuff.tar.gz stuff/

  • Need help with INSTR function

    I am trying use INSTR and SUBSTR function to parse a variable without breaking up the variable. As you can see the problem arises negotiating the blank space,
    DECLARE
         blank_space NUMBER(2);
         full_name VARCHAR2(30) := 'Robert P. Simmons');
         first_name VARCHAR2(30);
         last_name VARCHAR2(30);
    BEGIN
         blank_space := INSTR(full_name, ' ');
         first_name := SUBSTR(full_name, 1, (blank_space -1));
         DBMS_OUTPUT.PUT_LINE( 'Your first name is ' || first_name);
         last_name := SUBSTR(full_name, (blank_space + 1),
         (LENGTH(full_name) - blank_space));               
         DBMS_OUTPUT.PUT_LINE( 'You have ' ||
         LENGTH(last_name) || ' characters in your last name!');
    END;     How can I list the number of characters in the last_name only? It just list everything to the right side of the 1st blank_space.
    Thanks

    SQL> DECLARE
      2     blank_space NUMBER(2);
      3     full_name VARCHAR2(30) := 'Robert P. Simmons';
      4     first_name VARCHAR2(30);
      5     middle_initial VARCHAR2(30);
      6     last_name VARCHAR2(30);
      7
      8  BEGIN
      9     blank_space := INSTR(full_name, ' ');
    10     first_name := SUBSTR(full_name, 1, (blank_space -1));
    11     DBMS_OUTPUT.PUT_LINE( 'Your first name is ' || first_name);
    12     middle_initial := SUBSTR(full_name, (blank_space +1), INSTR(full_name, ' ',1,2)-blank_space-1);
    13     DBMS_OUTPUT.PUT_LINE( 'Your middle initial is ' || middle_initial);
    14  last_name := SUBSTR(full_name, INSTR(full_name, ' ',1,2)+1);
    15     DBMS_OUTPUT.PUT_LINE( 'You have ' ||
    16     LENGTH(last_name) || ' characters in your last name!');
    17
    18  END;
    19  /
    Your first name is Robert
    Your middle initial is P.
    You have 7 characters in your last name!
    Procedura PL/SQL completata correttamente.Max
    http://oracleitalia.wordpress.com

Maybe you are looking for

  • Problem with logging in

    So, I powered up my computer, entered the login password and got an error message that I could not login right now. I tried all sorts of things, safe boot, restarting, etc. A friend, helping me out (??), decided we should reinstall the OS SW, which w

  • Code to connect jsp with MS SQL SERVER 2000

    i have my SQL Server in my local machine and i need to conne ct my jsp page with that instance. please provide a sample code to accomplish the same. along with that can you please send me procedure to establish a DSN for SQL SERVER 2000. thank you wi

  • BlackBerry closing down in the UK

    I've been shopping around in London to see the new BlackBerry Passport. They are *extremely difficult* to find as only a handful of stores will stock them. My carrier is o2. But as I've trekked all over the place to find a Passport (I don't want to b

  • How do I change a layer selection color from black to a color?

    Somehow I've turned off the color selection so that I don't have a color when I select a part of a drawing on a layer. The drawing area stays black whether I have selected it or not and I don't know how to turn back on the color. Could someone tell m

  • Donwload Test Plan does not work in GRC PC 3.0 Portal

    Hello Experts, We have GRC PC 3.0 SP3 ABAP and JAVA standalone systems. Configured ADS configuration and all the ADS related checks "FP_TEST_00" and others working fine, even are able to see the print version of documents from portal. Trying to downl