Calendar function returns strange values

Can someone please help

Calendar rightNow = Calendar.GetInstance ();
int aa = Calendar.DATE;
int bb = Calendar.MONTH;

in aa value is 5, it is and in the bb, it is 2.

I checked my date system as well as the date of Simulator. I don't know why it's happening.

These values Calendar.DATE and Calendar.MONTH are the contacts to be used in conjueciton with the Calendar.getField () method.

Like this:

int = rightNow.getField (Calendar.MONTH) MB

Tags: BlackBerry Developers

Similar Questions

  • Function return undefined values

    My function returns undefined values. It seems that the return of the function statement is executed before the database is queried and values are assigned to variables. If I do an alert within the loop for () I get the correct values from the database, but these values are not affected before excecuting the return statement function. How can I do this differently?

    function getColumnNames(table){
        var rs1, rs2, rs3, rs4, rs5;
        db.transaction(function (tx) {
            tx.executeSql("SELECT * FROM schema WHERE table_name=?",[table], function(ax, results){
                var size = results.rows.length, i;
                var item;
                for (i = 0; i < size; i++){
                    item = results.rows.item(i);
                    rs1 = item.col1;
                    rs2 = item.col2;
                    rs3 = item.col3;
                    rs4 = item.col4;
                    rs5 = item.col5;
                                    alert(rs1); //correct value is returned here
                }
            });
        });
        return [rs1, rs2, rs3, rs4, rs5];
    }
    

    Hey Fabian,.

    You are quite correct that the return statement is executed before the database returns the results. There are ongoing asynchronous calls. You can set breakpoints in JavaScript code to see what is happening. You can correct the problem by using function callbacks. I edited your code below to use the callback functions - there might be a few typos, but the general approach should be wooded.

    function getColumnNames(table, callback){
        var rs1, rs2, rs3, rs4, rs5;
        db.transaction(function (tx) {
            tx.executeSql("SELECT * FROM schema WHERE table_name=?",[table], function(ax, results){
                var size = results.rows.length, i;
                var item;
                for (i = 0; i < size; i++){
                    item = results.rows.item(i);
                    rs1 = item.col1;
                    rs2 = item.col2;
                    rs3 = item.col3;
                    rs4 = item.col4;
                    rs5 = item.col5;
                        alert(rs5); //correct values are being returned
                    callback([rs1, rs2, rs3, rs4, rs5]);
                }
            });
        });
    }
    
    // example of how to call getColumnNames with callback
    getColumnNames('importantTable', function (result)
    {
        console.log(result);
    });
    
    // alternative version
    function onCallback(result)
    {
        console.log(result);
    }
    
    getColumnNames('importantTable', onCallback);
    

    I hope this helps.

    See you soon,.

    James

  • ORA-06503: PL/SQL: function returned no value ORA-06512:

    Hi all

    SQL > set serveroutput on

    SQL > CREATE OR replace FUNCTION qty_value (p_item_id number)

    2 RETURN NUMBER

    3 EAST

    4 v_qty_arrival NUMBER;

    5 BEGIN

    6. SELECT THE CASE SENSITIVE OPTION

    7. WHAT (SUM (b.quantity) - SUM (b.quantity_received)) < = 0 THEN 0

    8 ELSE (SUM (b.quantity) - SUM (b.quantity_received))

    9 END Qty_Arrival

    10 INTO v_qty_arrival

    Po_lines_all 11 a,

    po_line_locations_all 12 b

    13 WHERE a.po_line_id = b.po_line_id

    14 AND a.item_id = p_item_id;

    15 EXCEPTION

    16 THEN THAN OTHERS THEN

    17 v_qty_arrival: = NULL;

    18 RETURN v_qty_arrival;

    19 END qty_value;

    20.

    The function is created.

    SQL >

    SQL > select xxc_qty_arrivale (214960) double

    2.

    Select xxc_qty_arrivale (214960) double

    *

    ERROR on line 1:

    ORA-06503: PL/SQL: function returned no value

    ORA-06512: at the 'APPS '. XXC_QTY_ARRIVALE', line 19

    Back AFTER using the exception block is fine as long as your code actually REACHED the exception block.

    When there are no errors, then your code will not enter the exception block, but you still NEED to return a value, since it is what functions a function wants to return a value, that's what the functions are made for.

    Spot the differences between the following 3 functions. Understand how they work.

    The first function has only a return in the exception block but runs correctly. Result: error, because the back is missing in the code block.

    The second function has a return in the exception block and one in the block of code and runs correctly. Result: no error, because the return is not missing in the code block.

    The third function has a return in the exception block and one in the block of code and is forced into an error. Result: no error, because the return of the exception handler is used (instead of retriggering of the error, which you would normally do).

    SQL > create or replace function myfunc

    2 return number

    3 as

    4 start

    5 dbms_output.put_line ('in the section of code');

    6 null;

    7 exception

    8 then than others

    9. can

    10 dbms_output.put_line (' in the exception handler ' |) SQLERRM);

    11      --

    12 return 0;

    13      --

    14 end;

    15.

    The function is created.

    SQL > select double myfunc;

    Select double myfunc

    *

    ERROR on line 1:

    ORA-06503: PL/SQL: function returned no value

    ORA-06512: at "GHPLUS. MYFUNC", line 14

    In the section of code

    SQL > create or replace function myfunc

    2 return number

    3 as

    4 start

    5 dbms_output.put_line ('in the section of code');

    6 null;

    7    --

    8 return 1;

    9    --

    10 exceptional

    11 so that others

    12. can

    13 dbms_output.put_line (' in the exception handler ' |) SQLERRM);

    14      --

    15 return 0;

    16      --

    end 17;

    18.

    The function is created.

    SQL > select double myfunc;

    MYFUNC

    ----------

    1

    1 selected line.

    In the section of code

    SQL > create or replace function myfunc

    2 return number

    3 as

    n number 4;

    5. start

    6 dbms_output.put_line ('in the section of code');

    7 n: = 1/0; -force an error (zero divisor) to join the exception handler

    8    --

    9 return 1;

    10-

    exception 11

    12 so that others

    13. can

    14 dbms_output.put_line (' in the exception handler ' |) SQLERRM);

    15      --

    16 return 0;

    17      --

    18 end;

    19.

    The function is created.

    SQL > select double myfunc;

    MYFUNC

    ----------

    0

    1 selected line.

    In the section of code

    In the handler for exception ORA-01476: divisor is equal to zero

    SQL >

  • ORA-06503: PL/SQL: function returned no value

    Hi guys,.
    I wrote a function that returns the number of quarter for a given date.
    Here's the function

    FUNCTION to CREATE or REPLACE fn_get_quarter
    (p_date DATE)
    RETURN NUMBER
    AS
    v_qtr NUMBER;
    BEGIN
    Select TO_CHAR (p_date, 'Q')
    IN v_qtr
    DOUBLE;
    dbms_output.put_line (' it's quarter ' | v_qtr);
    END;

    It compiled without error.

    Here is the test case that I wrote

    DECLARE
    p_date DATE: = TO_DATE('12/22/2009','MM/DD/YYYY');
    v_qtr NUMBER;
    BEGIN
    v_qtr: = fn_get_quarter (p_date);
    END;

    When I run the present, I get the following error.

    ORA-06503: PL/SQL: function returned no value
    ORA-06512: at "GPS_FVO. FN_GET_QUARTER', line 13
    ORA-06512: at line 7

    But surprisingly, I get the result.

    Please suggest and let me know how to get rid of this error and why I get this error.

    Thanks in advance.
    Sam

    RETURN v_qtr;
    should be added after DBMS_OUTPUT

  • Function - return multiple values in a concatenated string

    Hello

    Is it possible for a function return a concatenated string (combining more than one number). I'm trying to return the purchase by the introduction and invoice_id number and code order number, but an invoice_id can have several PO with the same code number. I want to concatenate the PO numbers with commas, for example

    10124, 10090, 10987

    At the present time, the function returns NULL for those cases that have more than one purchase order number.

    Thank you
    func_get_po(i.invoice_id, cc.code_combination_id) "PO No",
    func_get_po_requester(i.invoice_id, cc.code_combination_id, func_get_po(i.invoice_id, cc.code_combination_id)) "PO Requester",
    

    Of course, this can be done without any problem.
    If it returns NULL, then you must debug function and check the operating logic. I know that it will take a little of your time, but not problems with the logic of syntax and concatenation.

  • APEX 4.0.1: $v () function returns multiple values for the box?

    Hello

    I have a report that uses apex_item.checkbox (...) to generate the check box. This report correctly displays a check box for each line. The source code that is generated in the html page is:
    < input type = "checkbox" name = "f01" value = "202" id = "P1_CHECKBOX" / >
    ...
    ...
    < input type = "checkbox" name = "f01" value = "220" id = "P1_CHECKBOX" / >
    ...
    ...
    < input type = "checkbox" name = "f01" value = "210" id = "P1_CHECKBOX" / >
    ...
    ...

    I want to use the javascript function $v () to get the values of the enabled check box. I thought that the return of this function all the checked values separated by ':' but I noticed that my code alert ($v ('P1_CHECKBOX')); return whenever the value of the first checkbox if it is checked.
    It returns '202' if the first box is checked, but nothing, if only the second checkbox is checked and '202' if the box of the first and the second is checked.

    Hello

    first of all, $v, $x and $s are supposed to not work for items on the page, not the columns in a table or manually generated HTML elements.

    Secondly, I think that your HTML code is not correct, because each of your boxes has the same ID. But the ID must be unique in the DOM of the browser tree. Thus the different box should actually named P1_CHECKBOX_1... P1_CHECKBOX_3. Just look at what is actually generated for a page element real checkbox. BTW, I think that you should not name the checkbox as part of page elements, because they are not actually page elements. I think that this could be confusing for other developers.

    Hope that helps
    Patrick
    -----------
    My Blog: http://www.inside-oracle-apex.com
    APEX 4.0 Plug-Ins: http://apex.oracle.com/plugins
    Twitter: http://www.twitter.com/patrickwolf

  • Function returned no value error

    create or replace function dssppv.hra_find_short_path (
       p_new_rgmn_grp_gid    in   number
      ,p_tail_rgmn_grp_gid   in   number
      ,p_mkt_cnfgr_gid       in   number
    )
       return string
    
    is
       v_rgmn_grp_path varchar2 ( 2000 );
       check_step varchar2 ( 2000 );
    begin
       dbms_output.put_line
          ( 'Begin of function  hra_find_short_path to Check Circular Loop : '
            || to_char ( sysdate, 'YYYY-MM-DD HH24:MI:SS' )
          );
       check_step                 := ' Step 1 - Circular loop Check up.';
    
       --Checking for the circular loop
       select rgmn_path || '/' || gt.rgmn_grp_nam
       into   v_rgmn_grp_path
       from   ( select  min_rgmn_node
                       ,rgmn_path
                       ,rgmn_grp_gid
               from     ( select    level as min_rgmn_node
                                   ,dt.rgmn_grp_gid
                                   ,dt.tail_rgmn_grp_gid
                                   ,gp.rgmn_grp_nam
                                   ,rtrim
                                       ( reverse
                                            ( sys_connect_by_path
                                                      ( reverse ( gp.rgmn_grp_nam )
                                                       ,'/ '
                                                      )
                                            )
                                        ,'/ '
                                       ) as rgmn_path
                         from       dssppv.t_market_cnfgr_rgmn_grp_dtl dt join dssppv.t_market_cnfgr_rgmn_grp gp
                                    on (     dt.rgmn_grp_gid = gp.rgmn_grp_gid
                                         and gp.mkt_cnfgr_gid = p_mkt_cnfgr_gid
                                       )
                         start with dt.tail_rgmn_grp_gid = p_new_rgmn_grp_gid
                         connect by nocycle prior dt.rgmn_grp_gid =
                                                              dt.tail_rgmn_grp_gid )
               where    rgmn_grp_gid = p_tail_rgmn_grp_gid
               order by min_rgmn_node )
             ,dssppv.t_market_cnfgr_rgmn_grp gt
       where  gt.rgmn_grp_gid = p_new_rgmn_grp_gid and rownum = 1;
    
       dbms_output.put_line ( ' Circular Loop is formed as shown :'
                              || v_rgmn_grp_path
                            );
    
       if ( v_rgmn_grp_path is not null )
       then
          dbms_output.put_line ( ' Circular Loop is formed as shown :'
                                 || v_rgmn_grp_path
                               );
       else
          dbms_output.put_line ( ' No Loop is formed.' );
       end if;
    
       dbms_output.put_line
             ( 'End of function  hra_find_short_path to Check Circular Loop : '
               || to_char ( sysdate, 'YYYY-MM-DD HH24:MI:SS' )
             );
       return v_rgmn_grp_path;
    exception
     --  when no_data_found
      -- then
       --   dbms_output.put_line
        --     ( 'End  of function  hra_find_short_path to Check Circular Loop : '
         --      || to_char ( sysdate, 'YYYY-MM-DD HH24:MI:SS' )
          --   );
          --return null;
       when others
       then
          dbms_output.put_line
                         ( 'Error in function DSSPPV.hra_find_short_path at: '
                           || check_step
                         );
          dbms_output.put_line ( sqlerrm );
          dbms_output.put_line
             ( 'End of function  hra_find_rgmn_grp_loops to Check Circular Loop : '
               || to_char ( sysdate, 'YYYY-MM-DD HH24:MI:SS' )
             );
    end hra_find_short_path;
    /
    I have fully commented goal no. Data Exception not found top check if she is to return null when no record is found.

    But he was wrong in not found exception when there is no data record.

    But when run sql separately he showed zero records without don't raise the no found error of data.

    He would not even through the loop fi... Please correct me if I did something wrong
     if ( v_rgmn_grp_path is not null )
       then
          dbms_output.put_line ( ' Circular Loop is formed as shown :'
                                 || v_rgmn_grp_path
                               );
       else
          dbms_output.put_line ( ' No Loop is formed.' );
       end if;

    You may not assume that v_rgmn_grp_path will retain the NULL value if the query returns no rows. In this case AS the value of the variable is not defined. I suggest yo change:

    Select rgmn_path. '/' || gt.rgmn_grp_nam

    TO

    Select count (*) case when 1 then max(rgmn_path ||) '/' || end of gt.rgmn_grp_nam)

    This way NO_DATA_FOUND will not be raised and the v_rgmn_grp_path will be NULL if there is no corresponding line.

    SY.

  • MONTHS_BETWEEN function returns negative values 'bad '?

    Hello

    I can't understand why these values are results.

    SQL > select months_between (to_date (February 2, 13 ',' DD-MON-RR'), to_date ('February 28, 13 ', ' DD-MON-RR')) twice;

    MONTHS_BETWEEN(TO_DATE('02-FEB-13','DD-MON-RR'),TO_DATE('28-FEB-13','DD-MON-RR')

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

    -.83870968

    SQL > select months_between (to_date (February 2, 13 ',' DD-MON-RR'), to_date ('April 1, 13 ', ' DD-MON-RR')) twice;

    MONTHS_BETWEEN(TO_DATE('02-FEB-13','DD-MON-RR'),TO_DATE('01-APR-13','DD-MON-RR')

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

    -1.9677419

    SQL > select months_between (to_date (February 2, 13 ',' DD-MON-RR'), to_date ('April 2, 13 ', ' DD-MON-RR')) twice;

    MONTHS_BETWEEN(TO_DATE('02-FEB-13','DD-MON-RR'),TO_DATE('02-APR-13','DD-MON-RR')

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

    -2

    user13393428 wrote:

    But,

    Select months_between (to_date (February 2, 13 ',' DD-MON-RR'), to_date ('April 2, 13 ', ' DD-MON-RR')) twice;

    How it is-2? Should not be-1?

    Do you really think there's only 1 month between February and April?  you have a very convenient calendar you can watch...

  • Analytical function - return 2 values

    I don't know I need to use an analytical function to do this, I can't do things. I appreciate the help.
    Statements of table and insert:
    create table TST_CK
    (
    DOC_ID NUMBER(6)      not null,
    ROW_SEQ_NBR NUMBER(6) not null,
    IND_VALUE VARCHAR2(2) null
    )
    INSERT INTO TST_CK VALUES ('1','6',NULL);
    INSERT INTO TST_CK VALUES ('1','5',NULL);
    INSERT INTO TST_CK VALUES ('1','4','T');
    INSERT INTO TST_CK VALUES ('1','3','R');
    INSERT INTO TST_CK VALUES ('1','9',NULL);
    INSERT INTO TST_CK VALUES ('1','10',NULL);
    INSERT INTO TST_CK VALUES ('1','7','T');
    INSERT INTO TST_CK VALUES ('1','8','R');
    INSERT INTO TST_CK VALUES ('2','1',NULL);
    INSERT INTO TST_CK VALUES ('2','2',NULL);
    INSERT INTO TST_CK VALUES ('2','3','T');
    INSERT INTO TST_CK VALUES ('2','4','R');
    INSERT INTO TST_CK VALUES ('2','5',NULL);
    INSERT INTO TST_CK VALUES ('2','6',NULL);
    INSERT INTO TST_CK VALUES ('2','7','T');
    INSERT INTO TST_CK VALUES ('2','8','R');
    INSERT INTO TST_CK VALUES ('4','1',NULL);
    INSERT INTO TST_CK VALUES ('4','2',NULL);
    INSERT INTO TST_CK VALUES ('4','3','X1');
    INSERT INTO TST_CK VALUES ('4','4',NULL);
    INSERT INTO TST_CK VALUES ('4','5',NULL);
    INSERT INTO TST_CK VALUES ('4','6',NULL);
    INSERT INTO TST_CK VALUES ('4','7','T');
    INSERT INTO TST_CK VALUES ('4','8','R');
    INSERT INTO TST_CK VALUES ('4','9',NULL);
    INSERT INTO TST_CK VALUES ('4','10',NULL);
    INSERT INTO TST_CK VALUES ('4','11',NULL);
    INSERT INTO TST_CK VALUES ('4','12',NULL);
    INSERT INTO TST_CK VALUES ('4','13','T');
    INSERT INTO TST_CK VALUES ('4','14','R');
    INSERT INTO TST_CK VALUES ('4','15',NULL);
    INSERT INTO TST_CK VALUES ('4','16',NULL);
    COMMIT;
    Here is what I tried that gets me close:
    SELECT MAX (TST_CK.DOC_ID), MAX (TST_CK.ROW_SEQ_NBR), TST_CK.IND_VALUE
      FROM ASAP.TST_CK TST_CK
     WHERE (TST_CK.IND_VALUE IS NOT NULL)
    GROUP BY TST_CK.IND_VALUE
    ORDER BY 2 ASC
    Here is my desired outcome:
    CV_1      CV_2
    T           R
    Or even better result would be:
    concat(CV_1,CV_2)
    Result:
    T,R
    Thanks for looking

    G

    GMoney says:
    Basically, I just need to make sure what I captures the last T and R entered in the column

    Still not clear. You want to find the last two lines (function ROW_SEQ_NBR) where IND_VALUE is 't' & 'R', right? If so:

    with t as (
               select  doc_id,
                       row_seq_nbr,
                       ind_value,
                       row_number() over(partition by ind_value order by row_seq_nbr desc) rn
                 from  tst_ck a
                 where ind_value in ('T','R')
              )
    select  doc_id,
            row_seq_nbr,
            ind_value
      from  t
      where rn = 1
    / 
    
        DOC_ID ROW_SEQ_NBR IN
    ---------- ----------- --
             4          14 R
             4          13 T
    
    SQL> 
    

    SY.

  • I need to return multiple values in function

    create or replace function f (p) in varchar2) return varchar2
    is
    a number (10);
    Start

    for loop 1 in 1.10
    Select instr('yyyyyyyyynnnnnyynny','y',1,i) in the doubles.
    end loop;
    return a;
    end;

    my function return a value, but I need to return multiple values
    Thanks in advance

    I don't know if that's what you want (you should give expected results also)

    SQL> create or replace type mytabletype as table of number;
      2  /
    
    Type created.
    
    SQL> create or replace function f (p in varchar2) return myTableType pipelined is
      2    a number(10);
      3  begin
      4    for i in 1..10 loop
      5      select instr('yyyyyyyyynnnnnyynny','y',1,i) into a from dual;
      6      pipe row (a);
      7    end loop;
      8  end;
      9  /
    
    Function created.
    
    SQL> select * from table(f('1'));
    
    COLUMN_VALUE
    ------------
               1
               2
               3
               4
               5
               6
               7
               8
               9
              15
    
    10 rows selected.
    
    SQL>
    

    Published by: Leo Mannhart on March 22, 2011 11:01

    could even be compressed into

    create or replace function f (p in varchar2) return myTableType pipelined is
    begin
      for i in 1..10 loop
        pipe row (instr('yyyyyyyyynnnnnyynny','y',1,i));
      end loop;
    end;
    
  • How to return two values of a function?

    Hi all
    I have a function which returns a varchar2 value. This value is used in the SQL of a ref cursor

    Now I want this function returns two values. I tried to use varray, but could not accomplish the task.

    Can you tell me how can I find the two values from a function? and how this function can be called in a SQL query?

    Thank you very much

    The query should look like:

    SELECT v.col.name AS name
         , v.col.flag AS flag
    FROM   ( SELECT kk_test_kk(t.somecolumn,t.someothercolumn,42) AS col
             FROM   sometable t ) v;
    

    Note that you need to prefix with the name of view inline ('v' in the example) and the expression of the function ('col' in the example).

  • How the two function return values

    Dear all,

    Please explain, how the two values of function return?

    give a simple example.

    OK, a few examples...

    First example, using a type of structured on the database object:

    SQL > create or replace type tMyValues as an object (yr number, number, number of dy mn)
    2.

    Type of creation.

    SQL > create or replace function getMyValues return tMyValues is
    2 number of y: = extraction (year sysdate);
    number of 3 m: = extraction (sysdate months);
    number of 4 d: = extract (day of sysdate);
    5. start
    6 return new tMyValues(y,m,d);
    7 end;
    8.

    The function is created.

    SQL > set serverout on

    SQL > declare
    2 myValues tMyValues;
    3. start
    4 myValues: = getMyValues();
    5 dbms_output.put_line (' year: ' | myValues.yr);
    6 dbms_output.put_line (' month: ' | myValues.mn);
    7 dbms_output.put_line (' date: ' | myValues.dy);
    8 end;
    9.
    Year: 2015
    Month: 4
    Day: 1

    PL/SQL procedure successfully completed.

    Second example, using an associative array within PL/SQL:

    SQL > set serverout on
    SQL > declare
    2 type tMyValues is table of the index number to varchar2 (10);
    3 myValues tMyValues;
    4
    5 function getMyValues return tMyValues is
    6 retValues tMyValues;
    7. start
    8 retValues ('Year'): = extraction (year sysdate);
    9 retValues ('Month'): = extraction (sysdate months);
    10 retValues ('Day'): = extract (day of sysdate);
    11 return retValues;
    12 end;
    13. begin
    14 myValues: = getMyValues();
    15 dbms_output.put_line (' year: ' | myValues ('Year'));
    16 dbms_output.put_line (' month: ' | myValues ('Month'));
    17 dbms_output.put_line (' date: ' | myValues ('Day'));
    18 end;
    19.
    Year: 2015
    Month: 4
    Day: 1

    PL/SQL procedure successfully completed.

    For the pipeline functions, see the example I wrote on the link provided by ReemaPuri (answer No. 3) that I don't need to re - write what I did before.

  • Mathmatical function to return the value in injectors

    Hello
    I have obliged. If value for ex Lake 4400000, he should return as 4.4millions even for billions.
    is there an oracle function to return the value in this format. ???

    Hello

    When I want to have a "readable" released in large numbers, I use to do the following:

    Scott@my11g SQL>with t as (
      2  select 3456123456 n from dual
      3  union all select 4567123 from dual
      4  union all select 123465 from dual
      5  )
      6  select n, case when n>1000000000 then trunc(n/1000000000,1)||' Billions'
      7  when n>1000000 then trunc(n/1000000,1)||' Millions'
      8  else to_char(n) end fmtn
      9  from t ;
    
             N FMTN
    ---------- -------------------------------------------------
    3456123456 3.4 Billions
       4567123 4.5 Millions
        123465 123465
    

    ------
    * + [change] + *.
    Moreover, lakh [url http://en.wikipedia.org/wiki/Lakh] has no meaning outside of South Asia.
    Especially for a French man like me, grown with [url http://en.wikipedia.org/wiki/International_System_of_Units] International system of units that is fighting against what I call "funky" measures empirical such miles, yards, feet, inches, just not multiple of 10³
    Same billion mean differ depending on the country (see [url http://en.wikipedia.org/wiki/Long_and_short_scales] long and short scales)

    Just for "fun": [url http://articles.cnn.com/1999-09-30/tech/9909_30_mars.metric.02_1_climate-orbiter-spacecraft-team-metric-system?_s=PM:TECH] this is what can happen when we do not use the same system of units.

  • Return multiple values from a function in a SELECT statement

    I hope I've provided enough information here. If not, let me know what I'm missing.

    I create a view that will combine the information from several tables. Most are pretty simple, but there are a couple of columns in the view that I need to get by running a function within a package. Even if this is quite simple (I have a function named action_date in a package called rp, for example, that I can use to return the date that I need through SOME rp.action_date (sequence_number).

    Here is the question: I really need to return several bits of information of the same record (not only action_date, but also action_office, action_value, etc.)-a join of the tables will work not here, as I will explain below. I can, of course, perform a function separate for each statement, but this is obviously inefficient. Within the select statement of the view, however, I don't know how each of the values that I need to get back.

    For example, right now, I have:

    Table 1:
    sequence_number NUMBER (10),
    name varchar (30),
    ...

    Table2:
    Table1_seq NUMBER (10),
    action_seq NUMBER (10),
    action_date DATE,
    action_office VARCHAR (3),
    action_value VARCHAR (60),
    ...

    I can't just simply join Table1 and Table2 because I have to perform processing in order to determine the rows returned matching, I really need to select. If the package opens a cursor and treats each line until it finds the one I need.

    The following works but is ineffective since all calls to the package returns the columns of the same record. I don't know how to put all the values that I need in the SELECT statement.
    CREATE VIEW all_this_stuff AS
    SELECT sequence_number, name,
    RP.action_date (sequence_number) action_date,
    RP.action_office (sequence_number) action_office,
    RP.action_value (sequence_number) action_value
    FROM table1

    Is there a way to return multiple values in my SELECT statement or I'm going about this all wrong?

    Any suggestions?

    Thank you very much!

    Hello

    What you want is a Query of Top - N , what you can do using the ROW_NUMBER analytic function in a subquery, like this:

    WITH     got_rnum     AS
    (
         SELECT     action_seq, action_dt, action_office, action_type, action_value
         ,     ROW_NUMBER () OVER ( ORDER BY  action_date
                                   ,            action_seq
                             ,            action_serial
                           ) AS rnum
         FROM     table2
         WHERE     action_code     = 'AB'
         AND     action_office     LIKE 'E'     -- Is this right?
    )
    SELECT     action_seq, action_dt, action_office, action_type, action_value
    FROM     got_rnum
    WHERE     rnum     = 1
    ;
    

    As written, this returns a single line (at most).
    I suspect you'll actually get a rank for each group , where a group is defined by a value in a table in which you join.
    In this case, add a PARTITION BY clause to the ROW_NUMBER function.
    If post you a small example of data (CREATE TABLE and INSERT statements), I could show you exactly how.
    As I don't have your tables, I'll show you the use of the tables in the scott schema.
    This is a view containing data in the scott.dept table and also to scott.emp, but only for the highest employee in each Department (in other words, the employee whose oldest hire date). If there be a tie for the first hire date, while the candidate with the lowest empno is selected.

    CREATE OR REPLACE VIEW     senior_emp
    AS
    WITH     got_rnum     AS
    (
         SELECT     d.deptno
         ,     d.dname
         ,     e.empno
         ,     e.ename
         ,     e.hiredate
         ,     ROW_NUMBER () OVER ( PARTITION BY  d.deptno
                                   ORDER BY          e.hiredate
                             ,                e.empno
                           ) AS rnum
         FROM     scott.dept     d
         JOIN     scott.emp     e     ON     d.deptno     = e.deptno
    )
    SELECT     deptno
    ,     dname
    ,     empno
    ,     ename
    ,     hiredate
    FROM     got_rnum
    WHERE     rnum     = 1
    ;
    
    SELECT     *
    FROM     senior_emp
    ;
    

    Output:

    .    DEPTNO DNAME               EMPNO ENAME      HIREDATE
    ---------- -------------- ---------- ---------- ---------
            10 ACCOUNTING           7782 CLARK      09-JUN-81
            20 RESEARCH             7369 SMITH      17-DEC-80
            30 SALES                7499 ALLEN      20-FEB-81
    

    Moreover, one of the conditions to the query you posted has been

    action_office     LIKE 'E'
    

    which equals

    action_office     = 'E'
    

    (AS is always equivalent to = if the string that follows AS does not contain the winning cards.)
    Did you mean say that or did you mean something like this:

    action_office     LIKE 'E%'
    

    Instead?

  • Return a value of date using a function

    I have a function in which I'm passing a date, but given the entry as a varchar data type.

    I'm the date inside the print function value and then return the value date.

    When I'm passing through January 20, 2009 as the date, I make out like 20 January 09 only.
    The year is get truncated in the output.

    How can I get January 20, 2009 as the value of output.

    Thanks in advance

    Kind regards
    Rambeau

    Try this:

    DECLARE
      MANIFEST_DT VARCHAR2(25) := '20-Jan-2009';
      V_SAMP_DT DATE;
    BEGIN
      SELECT TO_DATE(MANIFEST_DT,'DD-MON-YYYY') + 4
      INTO   V_SAMP_DT
      from   dual;
      DBMS_OUTPUT.PUT_LINE('SAMPLE DATE IS: ' ||to_char(V_SAMP_DT, 'dd-Mon-yyyy'));
    END;
    /
    

    When you store/work with dates in the database, it is best to convert the dates as a string in the format of date (with to_date) as soon as possible.

    When you need a date in the format of a specific way when it came to the end/screen/report on the forehead, then use to_char to return a date into a string format.

    Published by: Boneist on January 20, 2009 11:41

Maybe you are looking for

  • writing in shared variable published network hosted on rt (defined as slave modbus for crio) problems

    Hello Forums or This is my first post on this forum and I've been using labview for about 8 months now I have a problem about writing data in the modbus registers through a server of e/s defined as a slave modbus for my hardware 9074. Once I finished

  • Computers get tired?

    Computers get tired? No, I'm not trying to be funny, it's like this: sometimes, when I click on an icon, nothing happens. Or if I select 'my documents' and click on one of the elements, even when nothing is happening. Same story for Ctrl-Alt-Delete.

  • Static IP remote access for the media center

    I NMH410 work through a WRT610N router.   My ports are configured for static IP access.  Seems to just going through www.ciscomediahub.com does not work well for me. Can someone provide the 'exact' URL I would enter in order to access my media center

  • App PlayBook signature does not

    Hello I submitted my request about 2 and a half weeks he is shortly thereafter submitted version 1.1 by following the instructions of builder 4.5 Adobe.  Today I received a refusal of my application due to the lack of signature for versions 1.0 and 1

  • If I buy the retail version of Windows 7 Home Premium can I use the key to product again if I have to reinstall?

    Original title: first installation purchase windows 7 Home premium full version IM on best buy and I want to know if something happens to my pc and I reinstall windows 7 again once that I have to use a new product key or can I still use the same seri