Select  sum(substr(8763,3,4)||'+'||9) from dual   how to add ?

i want to add this substring value with 9
select sum(substr(8763,3,4)||'+'||9) from dual
means i need output 72

FOR I IN C1 LOOP
IF V_COUNT=0 THEN
V_FILENAME:='AB'||P_DOCUMENT_NUM||'.txt';
ELSE
V_FILENAME:='AB'||SUBSTR(P_DOCUMENT_NUM,2,5)||+||V_COUNT||'.txt';
END IF;
L_FILE :=UTL_FILE.FOPEN('D:\oracle\visdb\9.2.0\plsql\temp',V_FILENAME,'W');
UTL_FILE.PUT_LINE(L_FILE ,'E2|' || TRUNC(I.RAC_BILL_TO_CUSTOMER_NUM,0) ||l_attr||
TRUNC(I.RAC_SHIP_TO_CUSTOMER_NUM,0) );
V_COUNT:=V_COUNT+1;
end loop;
Actuelly i have write the data into different files names(i have to increase the filename for tranction) for each record of cursor
but oracle is not allowing to add (V_FILENAME:='AB'||SUBSTR(P_DOCUMENT_NUM,2,5)||+||V_COUNT||'.txt';)
that sum -----SUBSTR(P_DOCUMENT_NUM,2,5)||+||V_COUNT can any one help;

Similar Messages

  • How to select a substring in oracle up to a more than one specific character

    How to select a substring in oracle up to a more than one specific character
    for ex : 121.051^NP: FAMILY PRACTICE  ( trim the values before ^ )
                121.051^*NP: FAMILY PRACTICE (trim the value before *).
    with below function I can only get rid of ^ , I want both the specific characters ^ and ^* to be removed at the same time.   
    SUBSTR(p.phys_sub_grp_2_desc,INSTR(p.phys_sub_grp_2_desc, '^') +1)

    Another option is to boldly replace 'em:
    SQL> with t as (
      2  select '121.051^NP: FAMILY PRACTICE' str from dual union
      3  select '121.051^*NP: FAMILY PRACTICE' from dual
      4  )
      5  --
      6  -- actuel query:
      7  --
      8  select substr( replace(str, '*')
      9               , instr(replace(str, '*'), '^')+1
    10               ) str
    11  from   t;
    STR
    NP: FAMILY PRACTICE
    NP: FAMILY PRACTICE
    2 rows selected.

  • [11g] increasing efforts for select xmlserialize(content(...))) into ... from dual

    I wonder, that i don't get any feedback here (please see below).
    Can somebody first just confirm this observation?
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    "CORE 11.2.0.3.0 Production"
    TNS for Linux: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    NLSRTL 11.2.0.3.0 Production
    Oracle Database 11g Enterprise Edition 11.2.0.3.0 64bit Production
    PL/SQL 11.2.0.3.0 Production
    TNS for Linux: 11.2.0.3.0 Production
    I recognized for my application, that there is an increasing efforts (in terms of time) for executing
    (in a pl/sql package procedure invoked by a BIU trigger)
    SELECT XMLSERIALIZE(CONTENT(p_xml_data)) INTO v_xml_clob FROM DUAL;
    Here is a little demo sqlplus script:
    create or replace package test_pkg
    as
           procedure check_xml(
             p_xml_data in out nocopy xmltype);
    end;
    create or replace package body test_pkg
    as
           procedure log(
             p_txt in varchar2)
           is
             ts     TIMESTAMP WITH TIME ZONE := systimestamp;
           begin
             dbms_output.put_line(to_char(ts, 'hhmiss.FF3') || ':' || p_txt);
           end;
           procedure check_xml(
             p_xml_data in out nocopy xmltype)
           is
             v_xml_clob CLOB;
             v_len NUMBER;
           begin
             log('check_xml(): enter');
             SELECT XMLSERIALIZE(CONTENT(p_xml_data)) INTO v_xml_clob FROM DUAL;
             log('  serialized');
             v_len := dbms_lob.getlength(v_xml_clob);
             log('check_xml(): done - length = #'  || v_len);
           exception
           when others then
               oerror_pkg.set_ora_error;
               raise;
           end;
    end;
    drop table test_table;
    create table test_table(
           tid number(19,0),
           data xmltype
    create or replace trigger BIU_TEST_TABLE
    before insert or update on test_Table
    for each row
    declare
    begin
       test_pkg.check_xml(:new.data);
    end;
    insert into test_table(tid, data)
    select ctr_tab.ctr, '<root><node>' || ctr_tab.ctr || '</node></root>'
    from (  SELECT LEVEL ctr
           FROM dual
           CONNECT BY LEVEL <= 200) ctr_tab;
    The output is going like this
    021543.204:check_xml(): enter
    021543.204:  serialized
    021543.204:check_xml(): done - length = #32
    021543.206:check_xml(): enter
    021543.206:  serialized
    021543.206:check_xml(): done - length = #32
    021543.207:check_xml(): enter
    021543.208:  serialized
    021543.208:check_xml(): done - length = #32
    021543.209:check_xml(): enter
    021543.210:  serialized
    021543.210:check_xml(): done - length = #32
    021543.211:check_xml(): enter
    021543.212:  serialized
    021543.212:check_xml(): done - length = #32
    021543.214:check_xml(): enter
    021543.214:  serialized
    021543.214:check_xml(): done - length = #32
    021549.625:check_xml(): enter
    021549.664:  serialized
    021549.665:check_xml(): done - length = #34
    021549.708:check_xml(): enter
    021549.746:  serialized
    021549.747:check_xml(): done - length = #34
    021549.791:check_xml(): enter
    021549.829:  serialized
    021549.830:check_xml(): done - length = #34
    021549.874:check_xml(): enter
    021549.912:  serialized
    021549.913:check_xml(): done - length = #34
    When i filter it with a little perl script to extract the efforts (xmlserialize / dbms_lob.getlength):
    0 / 0
    0 / 0
    1 / 0
    1 / 0
    1 / 0
    0 / 0
    0 / 0
    0 / 1
    1 / 0
    0 / 0
    0 / 1
    1 / 0
    0 / 0
    0 / 1
    1 / 0
    0 / 1
    0 / 1
    0 / 0
    0 / 1
    0 / 0
    0 / 1
    0 / 0
    1 / 0
    0 / 1
    0 / 0
    31 / 1
    31 / 1
    32 / 1
    32 / 1
    32 / 1
    33 / 0
    33 / 0
    34 / 1
    34 / 0
    34 / 1
    34 / 0
    34 / 1
    34 / 1
    35 / 1
    35 / 1
    36 / 0
    36 / 1
    36 / 1
    37 / 1
    37 / 0
    37 / 1
    38 / 0
    38 / 0
    39 / 1
    38 / 1
    38 / 1
    38 / 1
    Unfortunately i can't easily change the way the insert from select is done (legacy code not under my control)
    Can someone tell me, if there is a way starting with the trigger to avoid those increasing efforts?
    - many thanks!
    best regards,
    Frank

    [ Addendum - 24.01.2014:
      This only worked for the test/demo program. It didn't work for my application.
       For my application i really had to move the logic to the INSERT before the trigger
       - similar to the 3rd posting for my monologue(!) here.
    A little step further:
    I also don't have the problem if i expand the code of the PROCEDURE test_pkg.check_xml(...) directly into the trigger
    - instead of invoking the PROCEDURE in the trigger:
    create or replace package test_pkg
    as
           procedure log(
             p_txt in varchar2);
    end;
    create or replace package body test_pkg
    as
           procedure log(
             p_txt in varchar2)
           is
             ts     TIMESTAMP WITH TIME ZONE := systimestamp;
           begin
             dbms_output.put_line(to_char(ts, 'hhmiss.FF3') || ':' || p_txt);
           end;
    end;
    drop table test_table;
    create table test_table( 
           tid number(19,0),
           data xmltype
    create or replace trigger BIU_TEST_TABLE
    before insert or update on test_Table
    for each row
    declare
    begin 
      -- test_pkg.check_xml(:new.data);
           declare
             v_xml_clob CLOB;
             v_len NUMBER;
           begin
             test_pkg.log('check_xml(): enter');
             SELECT XMLSERIALIZE(CONTENT(:new.data)) INTO v_xml_clob FROM DUAL;
             test_pkg.log('  serialized');
             v_len := dbms_lob.getlength(v_xml_clob);
            test_pkg.log('check_xml(): done - length = #'  || v_len);
           exception
           when others then
               oerror_pkg.set_ora_error;
               raise;
           end;
       end; 
    insert into test_table(tid, data)
    select ctr_tab.ctr, '<root><node>' || ctr_tab.ctr || '</node></root>'
    from (  SELECT LEVEL ctr
           FROM dual
           CONNECT BY LEVEL <= 200) ctr_tab;
    -- rollback;
    That gives some hint.
    Does oracle have some problem / limit for invoking procedures (functions) from triggers?
    Or only if those use certain features?
    An issue about deterministic and re-entrance?
    Well, that boxes me into a corner.
    Because the single package procedure implements a functionality at a central place - i.e. a single central place to extend it or to fix it.
    If i now have to expand its content (like a macro) into the triggers of the respective table i am in trouble.
    Because those tables (and their triggers) are dynamically generated by a compiler tool of a c++ client.
    This means for extension and fixes i need to change, test, deliver and deploy a list of c++ client processes :-(
    Is there any way around?
    How can i inform oracle that the invocation of a PL/SQL procedure is functionally identically with expanding the PL/SQL functions code into the trigger?
    rgds,
    Frank

  • Form 6i not support this SELECT sys_context('userenv', 'host') from dual;

    hi master
    sir i use this command for user ip address
    SELECT sys_context('userenv', 'host'), sys_context('userenv', 'ip_address') FROM dual;
    BUT
    form6i give me this error
    Error 201 at line 26, column 12
    Identifier ‘SYS_CONTEXT’ must be declared
    please give me idea how i get ip_address in form
    thank

    thank for your reply
    sir my need is
    i check user computer name if that computer in table then i update the user feeding ouer wise i insert that computer name as new and give the feeding form access to user
    you see my code
    SELECT sys_context('userenv','host'), sys_context('userenv', 'ip_address') INTO HOSTNAME,IPADD FROM dual;
    SELECT COUNT(*) INTO USERCOUNT FRoM forclosingyear WHERE HOSTNAME=HOSTNAME AND IPADD=IPADD;
    IF USERCOUNT>0 THEN
    update forclosingyear SET YEARID=:SYID,datefrom=:ysdate,dateto=:yedate WHERE HOSTNAME=HOSTNAME AND IPADD=IPADD;
    ELSIF USERCOUNT=0 THEN
    INSERT INTO forclosingyear (YEARID,datefrom,dateto,HOSTNAME,IPADD) VALUES (:SYID,:ysdate,:yedate,HOSTNAME,IPADD);
    END IF;
    this is my need
    please give me idea how i get termenal name or user computer name
    thank
    aamir

  • Query Issue with select level from dual

    Hi,
    I have a question regarding this query. The problem seems that when selecting level from dual while including another table the rows returned seem to increase exponentially.
    I can add distinct and get the correct number of rows but am worried that this will cause a possible performance issue. Am I using the level option wrong?
    I have included details below.
    There are 4 rows in tbl_incidents
    When I run the following queries I get rows returned based on the total number of rows
    select start_date + level - 1, tbl_incidents.incident_id, level
    from dual, tbl_incidents
    where incident_id = 6
    connect by level <= 1;
    returns 1 row
    select start_date + level - 1, tbl_incidents.incident_id, level
    from dual, tbl_incidents
    where incident_id = 6
    connect by level <= 2;
    returns 5 rows
    select start_date + level - 1, tbl_incidents.incident_id, level
    from dual, tbl_incidents
    connect by level <= 3 and incident_id = 6;
    returns 21 rows
    select start_date + level - 1, tbl_incidents.incident_id, level
    from dual, tbl_incidents
    connect by level <= 4 and incident_id = 6;
    returns 85 rows
    select start_date + level - 1, tbl_incidents.incident_id, level
    from dual, tbl_incidents
    connect by level <= 5 and incident_id = 6;
    returns 341 rows
    So with
         r being the number of rows in tbl_incidents and
         l being the number used in the connect by for level and
         q being the number of rows returned by the query
         it appears that
    q(l) = r * q(l-1) + 1
    level 2:     4 * 1 + 1 = 5
    level 3:     4 * 5 + 1 = 21
    level 4:     4 * 21 + 1 = 85
    level 5:     4 * 85 + 1 = 341
    Thanks much,
    Nora

    Hi,
    The dual table is used when you want to do something in SQL when you are not otherwise using a table.
    Generating a "counter table" of the integers 1, 2, 3,..., X is an example
    SELECT  LEVEL   AS n
    FROM    dual
    WHERE   LEVEL   <= x;There is never any point in joining dual to another table, as in
    select  start_date + level - 1
    ,       tbl_incidents.incident_id
    ,       level
    from    dual
    ,       tbl_incidents
    where    incident_id = 6
    connect by  level <= x;You will always get the same more easily by just eliminating dual:
    select  start_date + level - 1
    ,       incident_id
    ,       level
    from    tbl_incidents
    where    incident_id = 6
    connect by  level <= x;It is quite useful and common to join a counter-table to a real table, like this cross-join:
    WITH    counter_table  AS
        SELECT  LEVEL   AS n
        FROM    dual
        WHERE   LEVEL   <= x
    select  start_date + n - 1
    ,       incident_id
    ,       n
    from    tbl_incidents
    ,       counter_table
    where    incident_id = 6

  • Issue with select query to fetch data using Join from two tabels

    Hello All-
    I want to fetch the ShowName as "SUN NIGHTLY NEWS" and EpisodeName as "091706"
    based on the condition a.TitleNo=b.TitleNo and a.seriesNo=b.TitleNo.
    If i use the only first condition-a.TitleNo=b.TitleNo than output is displayed as-
    SchedItemNo |      Showname|      EpisodeName
    2702154     |     091706     |     091706
    If i use the second Condition-a.seriesNo=b.TitleNo than Output is displayed as-
    SchedItemNo|     Showname      |     EpisodeName
    2702154     |     SUN NIGHTLY NEWS |     SUN NIGHTLY NEWS
    Than i tried following Query to use the Union based on two conditions:-
    Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
    from ScheduleItem a,Titles b where a.TitleNo=b.TitleNo and
    a.ScheditemNo in ('2702154')
    Union All
    Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
    from ScheduleItem a,Titles b where b.TitleNo=a.SeriesNo and
    a.ScheditemNo in ('2702154')
    than it display the following result-
    SchedItemNo|     Showname |     EpisodeName
    2702154     |     091706          |     091706
    2702154     |     SUN NIGHTLY NEWS |     SUN NIGHTLY NEWS
    Here also values are not what i want :(
    I want the result to be displayed as using SQL:-
    SchedItemNo |     Showname      |     EpisodeName
    2702154     |     SUN NIGHTLY NEWS |     091706
    Please help me out!
    Thanks in Advance for putting your efforts.Looking forward for your replies.

    SQL> create table scheduleitem
      2  as
      3  select 2702154 scheditemno, 1 titleno, 11 seriesno from dual
      4  /
    Tabel is aangemaakt.
    SQL> create table titles
      2  as
      3  select 1 titleno, '071706' titlename from dual union all
      4  select 11, 'SUN NIGHTLY NEWS' from dual
      5  /
    Tabel is aangemaakt.
    SQL> Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
      2  from ScheduleItem a,Titles b where a.TitleNo=b.TitleNo and
      3  a.ScheditemNo in ('2702154')
      4  /
                               SCHEDITEMNO TITLENAME        EPISODENAME
                                   2702154 071706           071706
    1 rij is geselecteerd.
    SQL> Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
      2  from ScheduleItem a,Titles b where b.TitleNo=a.SeriesNo and
      3  a.ScheditemNo in ('2702154')
      4  /
                               SCHEDITEMNO TITLENAME        EPISODENAME
                                   2702154 SUN NIGHTLY NEWS SUN NIGHTLY NEWS
    1 rij is geselecteerd.
    SQL> Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
      2  from ScheduleItem a,Titles b where a.TitleNo=b.TitleNo and
      3  a.ScheditemNo in ('2702154')
      4  Union All
      5  Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
      6  from ScheduleItem a,Titles b where b.TitleNo=a.SeriesNo and
      7  a.ScheditemNo in ('2702154')
      8  /
                               SCHEDITEMNO TITLENAME        EPISODENAME
                                   2702154 071706           071706
                                   2702154 SUN NIGHTLY NEWS SUN NIGHTLY NEWS
    2 rijen zijn geselecteerd.
    SQL> select a.SchedItemNo "SchedItemNo"
      2       , show.TitleName "Showname"
      3       , episode.TitleName "EpisodeName"
      4    from ScheduleItem a
      5       , Titles episode
      6       , Titles show
      7   where a.TitleNo = episode.TitleNo
      8     and a.SeriesNo = show.TitleNo
      9  /
                               SchedItemNo Showname         EpisodeName
                                   2702154 SUN NIGHTLY NEWS 071706
    1 rij is geselecteerd.Regards,
    Rob.

  • Selecting from dual

    Does anyone have a list of all of the environment selections available from dual.
    e.g. select user from dual;
    Thanks in advance
    Bob

    Hi Bob,
    there are a lot of usful selections possible using DUAL. For more
    information I'd like to suggest you to look into SQL Reference Guide
    chapter 4, which describes for example the powerful SYS_CONTEXT
    function.
    Regards,
    Roland
    Find attached some usful examples on using dual:
    ================================================
    Current session:
    ================
    SQL> select sid,serial#
    from v$session
    where audsid in (SELECT USERENV('SESSIONID') FROM DUAL);
    SID SERIAL#
    13 830
    Which protocol is currently used for connection?
    ================================================
    SQL> SELECT SYS_CONTEXT('USERENV','NETWORK_PROTOCOL') from dual;
    SYS_CONTEXT('USERENV','NETWORK_PROTOCOL')
    tcp
    When nothing will be returned then you're using the BEQUEATH protocol.
    (Session on loacal server that has connected without using a listener)
    Which IP address will be used by session?
    =========================================
    SQL> SELECT SYS_CONTEXT('USERENV','IP_ADDRESS') "My IP Address" from dual;
    My IP Address
    140.84.134.14
    Which NLS Environment will be used?
    ===================================
    SQL> SELECT SYS_CONTEXT('USERENV','LANGUAGE') "nls_lang" from dual;
    nls_lang
    AMERICAN_AMERICA.WE8ISO8859P1

  • Access the results of the following query in Java? SELECT sum(COL_X) FROM TABLE_A

    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery(
    "SELECT sum(COL_X) FROM TABLE_A");
    int = rset.getInt("sum(NUM_CUSTOMER)");This is obviously wrong. Could someone please help me a little on the syntax? I just want to be able to get the sum of the numeric values in a column without having to loop through a ResultSet and manually adding up the total. My question is how can I access the results of this query by assigning the sum to a java variable?

    Hi,
    Probably the easiest way is to use an alias for the sum column, i.e.:
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery(
    "SELECT SUM(COL_X) MY_SUM FROM TABLE_A"
    int i = rset.getInt("MY_SUM");null

  • Select sum(distinct column ) from ....

    Hello All,
    I have a table the contains ID and size.
    An ID identifies a unique object, but it can be repeated. The following is valid:
    ID Size
    1 3
    4 5
    5 3
    1 3
    What I am trynig to do is get the sum of all sizes in the table. I tried this query:
    select sum(distinct size) from table;
    But it does give the right result since different objects could have the same size. I tried
    select sum(size) group by ID;
    But it prints to me huge number of IDs and sums the sizes of an ID together. What I want thuogh is to look at the unique rows (without duplicates) and then sum their sizes together and get the result.
    Any help would be greatly appreciated.
    Thank you
    P.S.: Sorry, I am an absolute Oracle/SQl newbie.
    Thanks for your help in advance

    An ID identifies a unique object, but it can be repeated.Fnord.
    I think your data model could withstand some refactoring but what you need to do is:
    SELECT sum(size) FROM
      (  SELECT distinct id, size FROM your_table)
    /This of course assumes that your duplication is complete and you don't have duplicate IDs with different sizes.
    You still ought to check out the concept of UNIQUE constraints though. A database ain't a database without relational integrity.
    Cheers, APC

  • Bug: in ManagedDataAccess while fetch from "Select .., NULL, ... From dual"

    Hi,
    I have the problem with the new managed ODP.Net driver.
    If I fetch data from a select which has column with a fixed value "NULL" the driver decides after a certain amount of data that the value is not null any more. Which causes a lot of problems especially if you try to hide not needed blob data.
    The Problem somehow depends on the FetchSize of the command. It seems like the error occurs if more than one db round trip to fetch the result is necessary.
    System: Windows 7 64 Bit
    Platform: .net 4.0 x86
    database: 11g Release 11.2.0.3.0 - 64bit Production
    Oracle.ManagedDataAccess Version: 4.112.350
    I created a small example to reproduce the problem.
    Thanks for your help
    Dominik
    Stored Proc:
    create or replace PROCEDURE TestNullField
      v_IntPara IN NUMBER DEFAULT NULL ,
      v_StrPara IN VARCHAR2 DEFAULT NULL,
      cv_1 OUT SYS_REFCURSOR
    AS
    BEGIN
          OPEN cv_1 FOR
            select rownum, v_StrPara, NULL from dual connect by level <= v_IntPara;
            --select IDX, NULL, DESCRIPTION FROM TEST_BLOBTABLE;
    END;C# Code:
    using System;
    using System.Text;
    using Oracle.ManagedDataAccess.Client;
    using System.Data;
    namespace OracleBlobTest
        class Program
            private static string _connectionString = @"User ID=YourUser;Password=YourPwd;Data Source=YourServer:YourPort/YourSchema;";
            private static string _spName = @"TestNullField";
            private static string _strPara = @" Long test string";
            private static int _intPara = 200;
            static void Main(string[] args)
                using (OracleConnection connection = new OracleConnection(_connectionString))
                    using (OracleCommand cmd = connection.CreateCommand())
                        cmd.CommandText = _spName;
                        cmd.CommandType = CommandType.StoredProcedure;
                        connection.Open();
                        string alongString = _strPara;
                        while (alongString.Length < 2000)
                            alongString += alongString;
                        alongString = alongString.Substring(0, 2000);
                        OracleCommandBuilder.DeriveParameters(cmd);
                        if (cmd.Parameters.Count > 0 && (cmd.Parameters[0]).Direction != ParameterDirection.ReturnValue)
                            cmd.Parameters[0].Value = _intPara;
                            cmd.Parameters[1].Value = alongString;
                        // change this to change the moment when it starts to go wrong
                        ///cmd.FetchSize = 5000;
                        using (OracleDataReader reader = cmd.ExecuteReader())
                            int count = 0;
                            while (reader.Read())
                                count++;
                                for (int idx = 0; idx < reader.FieldCount; idx++)
                                    if (reader.GetName(idx) == "NULL")
                                        if (!reader.IsDBNull(idx))
                                            //something is very wrong here - why is not not null any more???
                                            Console.WriteLine("Fix NULL Field[{0}] {1} is not null >{2}< in row {3} ", idx, reader.GetName(idx), reader[idx], count);
                            Console.WriteLine("Rows found: " + count);
                    connection.Close();
                Console.WriteLine("done press enter");
                Console.ReadLine();
    }Edited by: user540519 on 10.12.2012 15:11
    Edited by: user540519 on 19.12.2012 13:50

    Hello
    I ran the testcase here and reproduced the issue on 32 bit unmanaged beta v4.0.30319
    note: same testcase works with Oracle.DataAccess (but not with managed).
    This appears to match unpublished defect Bug 14666093 and is meant to be fixed in a later beta release.
    Some things I noticed when testing
    with the default fetchsize the breaking point is 67 iterations.
    e.g.
    private static int _intPara = 66;    // Works
    private static int _intPara = 67;  // Fails
    If I increase the fetchsize then it breaks at different values as you noticed..
    Hope this helps.
    Kind Regards
    John

  • How to calculate a string (select '1 + 1' from dual;)

    I have this system that gives me data (roughly a gig per hour) in the format:
    Time_idle
    13h 56m
    56m 23s
    24h 23m
    4h 3m
    4m 3s
    I have to translate it into date, or desimal hour so I can use it in calculations and SQL.
    How can I do this?
    I have tried the following:
    select RTRIM(REPLACE(REPLACE(REPLACE(REPLACE(time_idle,'h',''),'m','/60'),'s','/3600'),' ','+'),'+') from thedate where prosess = 1;
    and I then get:
    result:
    10+54/60
    14+12/60
    54/60+1/3600
    which is correct, if I could get Oracle to calculate the number sum instead of just providing me with the string value. How do I make Oracle calculate the value of the string?
    Or how can I use to_date function to translate the text into a date?
    Anyone know?
    BB

    Unfortunately this soultion breaks down when the time involved exceeds 24 hours. Try it for the given data sample 24h 23m ...
    SQL> select (to_number(to_char(to_date('24m 23m', 'HH24"h" MI"m" SS"s"'), 'HH24'))) +
      2   (to_number(to_char(to_date('24m 23m', 'HH24"h" MI"m" SS"s"'), 'MI'))/60) +
      3   (to_number(to_char(to_date('24m 23m', 'HH24"h" MI"m" SS"s"'), 'SS'))/3600) total
      4   from dual
      5  /
    select (to_number(to_char(to_date('24m 23m', 'HH24"h" MI"m" SS"s"'), 'HH24'))) +
    ERROR at line 1:
    ORA-01850: hour must be between 0 and 23
    SQL> Cheers, APC

  • HELP "Select SUM(x), SUM(y)" different between 8.1.6 and 8.1.7.2 ?

    The following query runs fine under 8.1.6 but returns bad result under 8.1.7.2 :
    SELECT SUM(NBANOMALIE4), SUM(NBANOMALIE2)
    FROM
    (SELECT COUNT(*) "NBANOMALIE2" FROM CPN A, ANOCPN B WHERE A.CODENS= '128' AND B.CODANO='2' AND A.NUMFOR = B.NUMFOR ) ,
    (SELECT COUNT(*) "NBANOMALIE4" FROM CPN A, ANOCPN B WHERE A.CODENS= '128' AND B.CODANO='4' AND A.NUMFOR = B.NUMFOR )
    GROUP BY NBANOMALIE2, NBANOMALIE4;
    Result given under 8.1.6 is
    SUM(NBANOMALIE4) SUM(NBANOMALIE2)
    1 0 (correct)
    Result given under 8.1.7.2 is
    0 0 (wrong)
    if query is changed to "SELECT SUM(NBANOMALIE2), SUM(NBANOMALIE4) ..."
    Result given under 8.1.7.2 is
    1 1 (wrong too !)
    actually the result given for ALL is the result of the last "SUM()" in the select ...
    Is it a bug ? if so any patch ? Is there a workaround ?
    Thanks for any help
    Charlie [email protected]

    a solution was to use decode()
    here is a workaround :
    SELECT DECODE(B.CODANO,'2',1,0) NBANOMALIE2, DECODE(B.CODANO,'4',1,0) NBANOMALIE4
    FROM CPN A, ANOCPN B
    WHERE A.CODENS= '128' AND B.CODANO IN ('2','4') AND A.NUMFOR = B.NUMFOR;
    I had it from http://www.orafaq.com/. ...
    Charlie [email protected]

  • SELECT SUM( field1 field2 ) INTO C1

    Is that possible with a select statement in ABAP or do I need to sum each row by itself then add them together afterwords?

    Hi Craig,
    this is not possible with a select statement in ABAP. You can use the routine mentioned by you:
    DATA: C1 TYPE i,
          C2 TYPE i,
          total type i.
    SELECT SUM( field1 ) SUM( fiedl2 ) into ( c1 c2 )from tablename.
    total = c1 + c2.
    Of course you can use the exec sql statement proposed by Andreas, but you have to select for the cllient explicitly. There are some disadvantages for native sql, too:
    1. platform dependent
    2. no syntax check for the native sql part
    3. you bypass the SAP database buffer
    For more details refer to the online help about EXEC SQL.
    Cheers,
    Morten

  • Why a function within a SELECT FROM DUAL is faster?

    1)I have a SELECT with a function. Ex:
    "SELECT DISTINCT function(...) FROM table"
    2)I changed the SELECT and put the function inside a SUB-SELECT with FROM DUAL. Ex:
    "SELECT DISTINCT (SELECT function(...) FROM DUAL) FROM table"
    3)The second SELECT is faster than the first.
    I discovered this problem on my tables and my functions. So I did a generic example for this forum with a common function and large table. My results:
    Table has 2.196.058 records and the field is a VARCHAR2:
    SELECT DISTINCT SUBSTR(field, 2) FROM Table -> Executed in 110 seconds
    SELECT DISTINCT (SELECT SUBSTR(field, 2) FROM DUAL) FROM Table -> Executed in 39 seconds
    Why "SELECT DISTINCT (SELECT function(...) FROM DUAL) FROM table" is faster than "SELECT DISTINCT function(...) FROM table"
    thanks,
    Fernando

    Hi hoek,
    I followed your informations and, sorry, I am more confused! I did an interesting example below.
    1)I created a table:
    CREATE TABLE T
         name VARCHAR2(50)
    );     2)I inserted 10 lines:
    NAME                                              
    A                                                 
    B                                                 
    C                                                 
    D                                                 
    E                                                 
    F                                                 
    G                                                 
    H                                                 
    I                                                 
    J                                                  3)I created a function that returns the parameter concatenated with the current millisecond:
    CREATE OR REPLACE FUNCTION f (param1 IN VARCHAR2) RETURN VARCHAR IS
    BEGIN
         return param1 || '-' || to_char(CURRENT_TIMESTAMP, 'FF');
    END;     4)The query(A): SELECT f(name) AS col1, f(name) AS col2, f(name) AS col3 FROM t; gave me:
    COL1        COL2        COL3
    A-693786000 A-693887000 A-693941000
    B-693989000 B-694017000 B-694043000
    C-694071000 C-694097000 C-694124000
    D-694153000 D-694180000 D-694206000
    E-694235000 E-694261000 E-694287000
    F-694316000 F-694341000 F-694367000
    G-694396000 G-694422000 G-694448000
    H-694477000 H-694503000 H-694529000
    I-694557000 I-694583000 I-694609000
    J-694638000 J-694664000 J-694690000If I repeat the SELECT, new values are generated.
    4)The query(B): SELECT (SELECT f(name) FROM Dual) AS col1, (SELECT f(name) FROM Dual) AS col2, (SELECT f(name) FROM Dual) AS col3 FROM t; gave me:
    COL1        COL2        COL3
    A-253546000 A-253643000 A-253746000
    B-253791000 B-253821000 B-253850000
    C-253881000 C-253909000 C-253937000
    D-253969000 D-253997000 D-254026000
    E-254057000 E-254085000 E-254113000
    F-254145000 F-254173000 F-254202000
    G-254232000 G-254261000 G-254289000
    H-254320000 H-254348000 H-254376000
    I-254407000 I-254436000 I-254464000
    J-254495000 J-254523000 J-254551000The result generated new values too.
    5)I changed the function and I put the DETERMINISTIC clause:
    CREATE OR REPLACE FUNCTION f (param1 IN VARCHAR2) RETURN VARCHAR DETERMINISTIC IS
    BEGIN
         return param1 || '-' || to_char(CURRENT_TIMESTAMP, 'FF');
    END;     6)I repeated the queries(A) and (B) and the result has generated different values. Then, with the DETERMINISTIC clause, the result has not changed
    7)I changed the function and I put the RESULT_CACHE clause:
    CREATE OR REPLACE FUNCTION f (param1 IN VARCHAR2) RETURN VARCHAR RESULT_CACHE IS
    BEGIN
         return param1 || '-' || to_char(CURRENT_TIMESTAMP, 'FF');
    END;8)I repeated the query(A) and now, the result was different:
    COL1        COL2        COL3
    A-381048000 A-381048000 A-381048000
    B-381242000 B-381242000 B-381242000
    C-381322000 C-381322000 C-381322000
    D-381400000 D-381400000 D-381400000
    E-381481000 E-381481000 E-381481000
    F-381556000 F-381556000 F-381556000
    G-381634000 G-381634000 G-381634000
    H-381815000 H-381815000 H-381815000
    I-381895000 I-381895000 I-381895000
    J-381971000 J-381971000 J-381971000The line columns are equals and if I repeat the SELECT, all the result is the same too. The query(B) returned the same result like the query(A)! Now I see the cache in action!
    After the tests, I concluded that the function in the subquery doesn't use cache and it is faster than the normal function. The mistery continues...

  • Performance Measure - Select SUM and Collect Statement.

    Dear All,
    I am using YNME_PROCESS_PO_CUST Badi in this i writing some validation Delivery Completion.
    For that i need to calculate GR qty and Delivery quantity based on this i need some validation. But here i confussed which statement i need to use for bast performance.
    Note: In Badi Item Level Data will be process one by one..like item level 10 then 20 then 30......Like that
    Code will like that---
    SELECT  SUM( menge )  FROM ekes
                                INTO  l_delqty
                                WHERE ebeln =  ls_mepoitem-ebeln
                                AND   ebelp =    ls_mepoitem-ebelp.
            SELECT  SUM( dabmg  )  FROM ekes
                             INTO  l_grqty
                             WHERE ebeln =  ls_mepoitem-ebeln
                             AND   ebelp =  ls_mepoitem-ebelp.
            l_delqty1 =  l_grqty - l_delqty.
            IF l_delqty1 NE 0.
              ls_mepoitem-elikz = ''.
              CALL METHOD im_item->set_data( ls_mepoitem ).
            ENDIF.
    I check in SE38 response is better in this code.
    Other code may be like that .. same data will be like upper/
          SELECT * FROM ekes
                     INTO CORRESPONDING FIELDS OF TABLE it_ekes
                     WHERE ebeln =  ls_mepoitem-ebeln
                     AND    ebelp =   ls_mepoitem-ebelp.
          LOOP AT it_ekes.
            MOVE-CORRESPONDING it_ekes TO it_ekes1.
            COLLECT it_ekes1.
            CLEAR  it_ekes.
          ENDLOOP.
          READ TABLE it_ekes1 INDEX 1.
          IF sy-subrc EQ 0.
            l_delqty1 =  it_ekes1-menge - it_ekes1-dabmg.
          ENDIF.
        IF l_delqty1 NE 0.
              ls_mepoitem-elikz = ''.
              CALL METHOD im_item->set_data( ls_mepoitem ).
       ENDIF.
    Can any send me document--
    Regard
    DK

    Hi,
    Single Select statement is certainly better.
    But no need to do select * and using into corresponding fields. These will reduce the performance. Also the loop statment is not absolutely correct. Following could be a sample code.
    TYPES: BEGIN OF gx_ekes,  (maintaining same sequence of fields as in select statement, this way no need of into corresponding fields)
                 ebeln type ebeln,
                 ebelp type ebelp,
                 menge type bbmng,
                 dabmg type dabmg,
                 END OF gx_ekes.
    DATA : lit_ekes TYPE TABLE OF gx_ekes,
                git_ekes TYPE TABLE OF gx_ekes,
                wa_ekes TYPE gx_ekes.
    SELECT ebeln
                  ebelp
                  menge
                  dabmg
    FROM ekes
      INTO TABLE it_ekes
    WHERE ebeln = ls_mepoitem-ebeln
    AND ebelp = ls_mepoitem-ebelp.
    LOOP AT lit_ekes INTO wa_ekes.
    COLECT wa_ekes INTO git_ekes.
    CLEAR: wa_ekes.
    ENDLOOP.
    CLEAR: lit_ekes.
    Now the first record in git_ekes will have the sum as only one line item is being passed in the user exit.
    Regards,
    Pranav.

Maybe you are looking for

  • Error in quantity translation in CO-PA valuation using material costing

    Dear SAP Gurus, While releasing the billing document to accounting I am getting the following error: Error in quantity translation in CO-PA valuation using material costing Message no. K/821 Diagnosis In Profitability Analysis (CO-PA), the system tri

  • "Recovered" CR2 files will not open in Photoshop CS6

    My son recently completed the National Three Peaks Challenge. Regrettably, having taken loads of pictures, he discovered that one of the CF cards was corrupt. He and his fellow climbers have now paid a company (a considerable sum) to recover these ph

  • More than one Quant in a Storage bin section (Strategy P)

    Dear all, We have a Storage type with Putaway strategy P, the SUT check active but no SU Management active, Mixed storage = X and Addition to stock = X. For this Storage type, our Storage bin type and SUT we have set up in customizing a Bin sectionin

  • Using iTunes as an audiophile quality music server

    I have recently setup up a music server using iTunes on a Wintel PC, connected through a Creative Audigy 2 external sound card to a Yamaha Class A stereo amp and Dynaudio speakers. Using Apple lossless compression, the sound quality of ripped CDs is

  • Itunes infinite hanging

    Hi Itunes is driving me crazy! It hangs frequently and it shows itself as not responding, if i try to force quit (even from the manager) it just restart immediately. When in this state it even cancel logouts! The only ways i've found so far are the h