Help with simple sql statement usiing Rank function..

Hello I have very important question..this is how i have a dataset...
This is the Log Table 
And the actual Table holds the current value.   12345
Current Table 
12345    575 232 4567
Log Table Values
Objectid InvalidatedTime
PhoneArea
Phoneno Rank
12345   2014-04-23
570          
822-4438      0  
3
12345   2014-04-28
NULL
658-7789      0
2
12345   2014-05-09
578        
658-8521      0 
1
As you can see on 23 they invlalidated the areacode and phone no and changed it to .. 578 658-8521 but on 04-28 they just changed the phone no and not the area code.. 
I want the result set to be like this
Date Fromvalue   
ToValue  
2014-04-23 
570-822-4438      
  578 658-7789
2014-04-28 578 658-7789 
578 658-8521
2014-05-09  578 658-8521
575 
232 4567
 I have tried this code.. 
select 
--'Home Phone',
--tt.invalidationtime ,
--Case when 
-- tt.*,tt_prev.* --,
'Home Phone' as PropertyName,
tt.invalidationtime,
case when tt.rank1 = 1 then tt.phoneareacode+'-'+tt.phoneno
when tt.rank1 <> 1 then Isnull(tt.phoneareacode,tt_prev.phoneareacode)+'-'+ isnull(tt.phoneno,tt_prev.phoneno)
end as FromAddress,
case when tt.rank1 = 1 then Haddress.phoneareacode+'-'+HAddress.phoneno
when tt.rank1 <> 1 then Isnull(tt_prev.phoneareacode,tt.phoneareacode)+'-'+isnull(tt_prev.phoneno,tt.phoneno)
end as ToPhone
from
 #Phone_Final  tt
left join  #Phone_Final tt_prev on tt_prev.objectid = tt.objectid and tt.rank1-11 = tt_prev.rank1
inner join (select * from Soarian_Clin_Prd_1.dbo.Haddress   where PP_id = 2346   and Addresstype = 0) Haddress
Can you please tell me what is wrong here.. 

should be this I reckon
;With CTE
AS
SELECT ROW_NUMBER() OVER (PARTITION BY ObjectID ORDER BY InvalidatedTime) AS Seq, *
FROM
SELECT ObjectID,InvalidatedTime,PhoneArea,Phoneno,Rank
FROM LogTable
UNION ALL
SELECT ObjectID, GETDATE(),PhoneArea,Phoneno,NULL
FROM Current
)t
SELECT c1.InvalidatedDate AS [Date],
COALESCE(c1.PhoneArea,c2.PhoneArea,'') + c1.Phoneno AS FromValue,
COALESCE(c2.PhoneArea,c1.PhoneArea,'') + c2.Phoneno AS ToValue
FROM CTE c1
INNER JOIN CTE c2
ON c2.Objectid = c1.Objectid
AND c2.Seq = c1.Seq + 1
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

Similar Messages

  • Help with simple INSERT statement?

    How can I do an insert into Oracle without having to
    specify EVERY field name in the table? This isn't necessary
    with Access or
    SQL Server, which will insert null's in the non-specified
    fields, the Oracle SQL
    tool tells me that there aren't enough field values when I run
    this SQL Statement:
    INSERT INTO TABLE_NAME VALUES (1234, 'test', 'test')
    There are over 10 different fields, but I get the error message:
    Native Error Code 947, Not enough values.
    TIA
    Kris
    null

    Kristofer Goss (guest) wrote:
    : How can I do an insert into Oracle without having to
    : specify EVERY field name in the table? This isn't necessary
    : with Access or
    : SQL Server, which will insert null's in the non-specified
    : fields, the Oracle SQL
    : tool tells me that there aren't enough field values when I run
    : this SQL Statement:
    : INSERT INTO TABLE_NAME VALUES (1234, 'test', 'test')
    : There are over 10 different fields, but I get the error
    message:
    : Native Error Code 947, Not enough values.
    : TIA
    : Kris
    You may omit the columns list, but if you do then the VALUES
    clause must provide values for every column in the table.
    FOR EXAMPLE: if your table were created as follows:
    COLUMN_1 NOT NULL, VARCHAR2(4)
    COLUMN_2 NUMBER(6)
    COLUMN_3 DATE
    COLUMN_4 VARCHAR2(4)
    You could submit a statement like:
    insert into my_table VALUES ('ALLA', , , 'XYZ');
    You could also submit a statement like:
    insert into my_table (column_1, column_4) VALUES ('ALLA', 'XYZ');
    If you do not want to store any value in a particular column,
    then that column must be allowed to accept NULLs.
    Hope this helps.
    null

  • Help with an sql statement

    String Queue = jComboBox3.getSelectedItem().toString();
    String Start_Date = jComboBox2.getSelectedItem().toString();
    String End_Date = jComboBox1.getSelectedItem().toString();
    int bins []= new int [size];
    String sql = "SELECT Count(Accepts.Queue)FROM Accepts WHERE Accepts.Queue = 'Queue' And (Accepts.TimeOfAccept Between 'Start_Date' And 'End_Date');";
    ResultSet result = stmt.executeQuery(sql);
    if (result.next())
    int res = result.getInt(1);
    for (int k = size; k<0; k--)
    for (int i = 0; i<res+1; i++)
    bins[i] = res% k;
    Im trying to get information from a table using an sql statement i have converted the items selected in combo boxes into strings and am using these strings in the sql statement but it is still wrong can anyone help me

    . . . WHERE Accepts.Queue = 'Queue' And (Accepts.TimeOfAccept Between 'Start_Date' And 'End_Date')As others have mentioned, it looks like you have a data type mis-match.
    Try:
    . . . . . Accepts.TimeOfAccept Between TO_DATE(Start_Date) AND TO_DATE(End_Date)
    This assumes that the two DATE variables - Start_Date and End_Date - are in standard format - DD-MON-YY.
    If not, you will need to supply a format model as a second argument to the TO_DATE functions:
    TO_DATE(character_string , format_model)
    i.e.
    . . . . . BETWEEN TO_DATE(Start_Date,'MM/DD/YY') AND TO_DATE(End_Date,'MM/DD/YY')
    Hope this helps.

  • Help with UNION sql statement......

    Hi guys,
    So I've got 3 tables (CHILD, TEENANGER and ADULT) and each have a column called 'Planned_Dosage_Date' and 'Actual_Dosage_Date'.
    I have put together a SELECT statement like this:
    SELECT     
         ITEV.AGE_SECTOR,
         ICPL.AGE_SECTOR_CODE,
         ITR.PLANNED_DOSAGE_DATE || '/' || ITR.ACTUAL_DOSAGE_DATE
    FROM
        PAT_TR_EVENT ITEV,
        PAT_MEDICAL_PLANICPL,
        PAT_EXAMINATION ITR
    WHERE
        ITEV.AGE_SECTOR = ICPL.AGE_SECTOR
    AND ITEV.ID_NO = ITR.ID_NO
    AND ITEV.ID_NO = 269
    AND ITEV.MED_NO = 3200
    UNION
    SELECT
         ITEV.AGE_SECTOR,
         ICPL.AGE_SECTOR_CODE,
         ITRC.PLANNED_DOSAGE_DATE || '/' || ITRC.ACTUAL_DOSAGE_DATE
    FROM
        PAT_TRC_EVENT IYEV,
        PAT_MEDICAL_PLAN ICPL,
        PAT_EXAMINATION ITR,   
        PAT_EXAMINATION_COUNTRY ITRC,
        PAT_TR_EVENT ITEV
    WHERE
        IYEV.AGE_SECTOR = ICPL.AGE_SECTOR
        AND IYEV.MED_NO = ITEV.MED_NO
        AND IYEV.ID_NO = ITR.ID_NO
        AND IYEV.ID_NO = ITRC.ID_NO
        AND IYEV.ID_NO = ITEV.ID_NO
        AND IYEV.COUNTRY_CODE = ITRC.COUNTRY_CODE
        AND IYEV.ID_NO = 269
        AND IYEV.MED_NO = 3200
    UNION
    SELECT
         ITEV.AGE_SECTOR,
         ICPL.AGE_SECTOR_CODE,
         ITU.PLANNED_DOSAGE_DATE || '/' || ITU.ACTUAL_DOSAGE_DATE
    FROM
         PAT_TR_EVENT ITEV,
         PAT_MEDICAL_PLAN ICPL,
         PAT_EXAMINATION ITR,
         PAT_TU_EVENT IUEV,
         PAT_EXAMINATION_UNIT ITU,
         PAT_EXAMINATION_COUNTRY ITRC,
         PAT_TRC_EVENT IYEV
    WHERE
         IUEV.AGE_SECTOR = ICPL.AGE_SECTOR
         AND IUEV.MED_NO = ITEV.MED_NO
         AND IUEV.MED_NO = IYEV.MED_NO
         AND IUEV.ID_NO=ITR.ID_NO
         AND IUEV.ID_NO=ITRC.ID_NO
         AND IUEV.ID_NO=ITU.ID_NO
         AND IUEV.ID_NO = ITEV.ID_NO
         AND IUEV.ID_NO = IYEV.ID_NO
         AND IUEV.COUNTRY_CODE=ITRC.COUNTRY_CODE 
         AND IUEV.COUNTRY_CODE=ITU.COUNTRY_CODE
         AND IUEV.COUNTRY_CODE = IYEV.COUNTRY_CODE
         AND IUEV.ID_NO= 269
         AND IUEV.MED_NO = 3200
    ORDER BY COUNTRY_DESC ASC, UNIT_NO ASCNow the output from this is:
    AGE_SECTOR                AGE_SECTOR_CODE            ITR. PLANNED_DOSAGE_DATE/ITR.ACTUAL_DOSAGE_DATE
    10-20                               ADU                                                       01-JAN-09/07-FEB-09
    What I want is for the results of:
    ITRC.PLANNED_DOSAGE_DATE || '/' || ITRC.ACTUAL_DOSAGE_DATE
    ITU.PLANNED_DOSAGE_DATE || '/' || ITU.ACTUAL_DOSAGE_DATE
    to also be printed so it looks like:
    AGE_SECTOR        AGE_SECTOR_CODE       ITR. PLANNED_DOSAGE_DATE/ITR.ACTUAL_DOSAGE_DATE         ITRC.PLANNED_DOSAGE_DATE/ITRC.ACTUAL_DOSAGE_DATE    ITU.PLANNED_DOSAGE_DATE/ITU.ACTUAL_DOSAGE_DATE
    10-20                    ADU                                   01-JAN-09/07-FEB-09                                    01-MAR-09/07-JUL-09                 01-DEC-08/07-DEC-08How can this be achieved? Am I using the UNION statemen in the incorrect way?
    Thanks!
    Edited by: Sastry on Oct 29, 2009 2:48 AM
    Edited by: Sastry on Oct 29, 2009 2:57 AM
    Edited by: Sastry on Oct 29, 2009 2:58 AM
    Edited by: Sastry on Oct 29, 2009 3:01 AM
    Edited by: Sastry on Oct 29, 2009 3:09 AM
    Edited by: Sastry on Oct 29, 2009 3:10 AM

    I don't think you should be using union here - you will lose the data from soem of the 3 sectors if the dates are the same as UNION does a unique sort. Maybe use UNION ALL, but I think you'd be better off joining.
    Not tested, and you may wish to review whether you need to use outer joins in the last query (What happens if there's no dates for some of the 3 sections?), but something like this:
    WITH itr AS
        SELECT     
             ITEV.AGE_SECTOR,
             ICPL.AGE_SECTOR_CODE,
             ITR.PLANNED_DOSAGE_DATE || '/' || ITR.ACTUAL_DOSAGE_DATE AS dt
        FROM
            PAT_TR_EVENT ITEV,
            PAT_MEDICAL_PLANICPL,
            PAT_EXAMINATION ITR
        WHERE
            ITEV.AGE_SECTOR = ICPL.AGE_SECTOR
        AND ITEV.ID_NO = ITR.ID_NO
        AND ITEV.ID_NO = 269
        AND ITEV.MED_NO = 3200
    itrc AS
        SELECT
             ITEV.AGE_SECTOR,
             ICPL.AGE_SECTOR_CODE,
             ITRC.PLANNED_DOSAGE_DATE || '/' || ITRC.ACTUAL_DOSAGE_DATE AS dt
        FROM
            PAT_TRC_EVENT IYEV,
            PAT_MEDICAL_PLAN ICPL,
            PAT_EXAMINATION ITR,   
            PAT_EXAMINATION_COUNTRY ITRC,
            PAT_TR_EVENT ITEV
        WHERE
            IYEV.AGE_SECTOR = ICPL.AGE_SECTOR
            AND IYEV.MED_NO = ITEV.MED_NO
            AND IYEV.ID_NO = ITR.ID_NO
            AND IYEV.ID_NO = ITRC.ID_NO
            AND IYEV.ID_NO = ITEV.ID_NO
            AND IYEV.COUNTRY_CODE = ITRC.COUNTRY_CODE
            AND IYEV.ID_NO = 269
            AND IYEV.MED_NO = 3200
    itu AS
        SELECT
             ITEV.AGE_SECTOR,
             ICPL.AGE_SECTOR_CODE,
             ITU.PLANNED_DOSAGE_DATE || '/' || ITU.ACTUAL_DOSAGE_DATE AS dt
        FROM
             PAT_TR_EVENT ITEV,
             PAT_MEDICAL_PLAN ICPL,
             PAT_EXAMINATION ITR,
             PAT_TU_EVENT IUEV,
             PAT_EXAMINATION_UNIT ITU,
             PAT_EXAMINATION_COUNTRY ITRC,
             PAT_TRC_EVENT IYEV
        WHERE
             IUEV.AGE_SECTOR = ICPL.AGE_SECTOR
             AND IUEV.MED_NO = ITEV.MED_NO
             AND IUEV.MED_NO = IYEV.MED_NO
             AND IUEV.ID_NO=ITR.ID_NO
             AND IUEV.ID_NO=ITRC.ID_NO
             AND IUEV.ID_NO=ITU.ID_NO
             AND IUEV.ID_NO = ITEV.ID_NO
             AND IUEV.ID_NO = IYEV.ID_NO
             AND IUEV.COUNTRY_CODE=ITRC.COUNTRY_CODE 
             AND IUEV.COUNTRY_CODE=ITU.COUNTRY_CODE
             AND IUEV.COUNTRY_CODE = IYEV.COUNTRY_CODE
             AND IUEV.ID_NO= 269
             AND IUEV.MED_NO = 3200
    SELECT itr.age_sector,
           itr.age_sector_code,
           itr.dt AS itr_dates,
           itrc.dt AS itrc_dates,
           itu.dt AS itu_dates
    FROM itr
    JOIN itrc ON itrc.age_sector = itr.age_sector_code
    JOIN itu ON itu.age_sector_code = itr.age_sector_code

  • Help with a SQL Statement

    Hello,
    I have the following two tables:
    !http://img189.imageshack.us/img189/5093/tablesf.jpg!
    Now I want to create a report form that shows the user everything from "DO_RELATIONSHIP". That is pretty easy, but now comes the tricky part. As you can see, the "dobj1_nr" and the "dobj2_nr" are both linked with the table "DATAOBJECT". Now I want that the user also sees "namsp" and "dobj_name" from dataobject for dobj1_nr AND dobj2_nr.
    Is there an easy way to do something like this? This is how it should look like:
    !http://img339.imageshack.us/img339/4403/resultt.jpg!
    Thank you all sooo much!!!
    Edited by: user12067949 on Dec 1, 2009 1:33 PM

    Hi,
    Does the value of dobj1_nr actually equal dobj_nr or is dobj_nr a combination of dobj1_nr & 2?
    Try:
    select do_relationship.dobj1_nr, dataobject.namsp
    from do_relationship JOIN dataobject ON do_relationship.dobj1_nr || do_relationship.dobj2_nr = dataobject.dobj_nrThis is assuming that:
    dobj1_nr = 11
    dobj2_nr = 44
    dataobject.dobj_nr = 1144
    If dataobject.dobj_nr were something like 11-44 then your join clause would look like do_relationship.dobj1_nr || '-' || do_relationship.dobj2_nr
    Edit: Also, terrible excuse by Ben for using the non-standard join syntax...next you'll be saying that you use RPAD/LPAD rather than SUBSTR because its quicker to type :P
    Mike
    Edited by: Dird on Dec 2, 2009 10:27 AM

  • Help with alternate sql statement?

    I have the following setup:
    create table sc_t1
    ( n1 number, n2 number, n3 number, constraint sc_t1_pk primary key ( n1 ) );
    create table sc_t2
    ( n1 number, n2 number, primary key ( n1 ) )
    organization index;
    insert into sc_t1 values ( 1, 2, 1);
    insert into sc_t1 values ( 2, 1, 1);
    insert into sc_t1 values ( 3, null, null );
    insert into sc_t1 values ( 4, null, null );
    insert into sc_t2 values ( 1, 11 );
    insert into sc_t2 values ( 2, 12 );
    insert into sc_t2 values ( 3, 13 );
    insert into sc_t2 values ( 5, 15 );
    I would like to see the following result:
    11      12      11
    12      11      11
    13           
    The following query achieves the result, but it joins sc_t2 three times. Is there a way have just one join because tables sc_t1 and sc_t2 will have 1,000,000+ rows.
    select b.n2 as r1
    , nvl2( a.n2, c.n2,null ) as r2
    , nvl2( a.n3, d.n2, null ) as r3
    from sc_t1 a
    join sc_t2 b on a.n1 = b.n1
    join sc_t2 c on nvl( a.n2, a.n1 ) = c.n1
    join sc_t2 d on nvl( a.n3, a.n1 ) = d.n1;
    I was hoping to pivot the result from the following query, but it returns only two instead of three rows per row in sc_t1:
    select a.*
    , b.*
    , row_number() over ( partition by a.n1 order by a.n1 ) as rn
    from sc_t1 a
    join sc_t2 b
    on a.n1 = b.n1
    or nvl( a.n2, a.n1 ) = b.n1
    or nvl( a.n3, a.n1 ) = b.n1
    /

    you MUST join it 3 times. if it's slow, make indexes
    select b.n2 as r1, c.n2 as r2, d.n2as r3
    from sc_t1 a, sc_t2 b, sc_t2 c, sc_t2 d
    where a.n1 = b.n1
    and a.n2 = c.n1(+)
    and a.n3 = d.n1(+)

  • What's wrong with my SQL statement?

    Guys,
    Please help me with this one.
    I am using Oracle JDBC Driver 9.2.0. When I did "select column1, column2 from tableName where rownum<1000", it was really fast. But when I do "select column1, column2 from tableName where rownum between 100 and 200", it won't return. The whole program just sit there, like there is some kind of infinite loop going on or something. I don't know Oracle database at all. Is there anything wrong with my SQL statements or there is some special Oracle SQL statement requirement/syntax?
    Thanks.

    Guys,
    Please help me with this one.
    I am using Oracle JDBC Driver 9.2.0. When I did
    "select column1, column2 from tableName where
    rownum<1000", it was really fast. But when I do
    "select column1, column2 from tableName where rownum
    between 100 and 200", it won't return. The whole
    program just sit there, like there is some kind of
    infinite loop going on or something. I don't know
    Oracle database at all. Is there anything wrong with
    my SQL statements or there is some special Oracle SQL
    statement requirement/syntax?
    Thanks.
    why don't you just try a standard WHERE
    "select column1, column2 from tableName where rownum > 100 and rownum < 200"

  • Whats wrong with this sql statement ??

    Hello all, I am trying to run the below query out of persheet(tanel poder) performance excel chart...but i get below error...db is on 9.2
    what is wrong with this sql statement ?
    http://blog.tanelpoder.com/2008/12/28/performance-visualization-made-easy-perfsheet-20-beta/
    select * from (
    with fsq as (
      select /*+ materialize */
       i.dbid
        , i.instance_name
        , i.instance_number
    --    , trunc(s.snap_time, 'DD')     DAY
    --    , to_number(to_char(s.snap_time, 'HH24'))  HOUR
    --   -- , to_char(s.snap_time, 'MI')    MINUTE
    --    , 0           MINUTE
        , trunc(
          lag(s.snap_time, 1)
          over(
           partition by
          v.dbid
           , i.instance_name
           , v.instance_number
           , v.event
         order by
          s.snap_time
          , 'HH24'
         )           SNAP_TIME
        , v.event_type        EVENT_TYPE
        , v.event          EVENT_NAME
        , nvl(
        decode(
         greatest(
          time_waited_micro,
          nvl(
           lag(time_waited_micro,1,0)
           over(
            partition by
             v.dbid
              , i.instance_name
              , v.instance_number
              , v.event
            order by v.snap_id
           , time_waited_micro
         time_waited_micro,
         time_waited_micro - lag(time_waited_micro,1,0)
         over (
          partition by
           v.dbid
            , i.instance_name
            , v.instance_number
            , v.event
          order by v.snap_id
         time_waited_micro
           , time_waited_micro
         ) / 1000000         SECONDS_SPENT
        , total_waits         WAIT_COUNT
      from
       (select distinct dbid, instance_name, instance_number from stats$database_instance) i
        , stats$snapshot s
        , ( select
         snap_id, dbid, instance_number, 'WAIT' event_type, event, time_waited_micro, total_waits
        from
         stats$system_event
        where
         event not in (select event from stats$idle_event)
        union all
        select
         snap_id, dbid, instance_number,
         case
          when name in ('CPU used by this session', 'parse time cpu', 'recursive cpu usage') then 'CPU'
          when name like 'OS % time' then 'OS'
          else 'STAT'
         end,
         name , value, 1
        from
         stats$sysstat
    --    where      name in ('CPU used by this session', 'parse time cpu', 'recursive cpu usage')
    --    or  name like('OS % time')
    --    or 1 = 2 -- this will be a bind variable controlling whether all stats need to be returned
       ) v
      where
       i.dbid = s.dbid
      and i.dbid = v.dbid
      and s.dbid = v.dbid
      and s.snap_id = v.snap_id
      and s.snap_time between '%FROM_DATE%' and '%TO_DATE%'
      and i.instance_name = '%INSTANCE%'
    select * from (
      select
       instance_name
        , instance_number
        , snap_time
        , trunc(snap_time, 'DD')  DAY
        , to_char(snap_time, 'HH24') HOUR
        , to_char(snap_time, 'MI') MINUTE      
        , event_type  
        , event_name  
        , seconds_spent
        , wait_count  
        , ratio_to_report(seconds_spent) over (
    --      partition by (to_char(day, 'YYYYMMDD')||to_char(hour,'09')||to_char(minute, '09'))
          partition by (snap_time)
          ) ratio
      from fsq
      where
       snap_time is not null -- lag(s.snap_time, 1) function above will leave time NULL for first snapshot
      -- to_char(day, 'YYYYMMDD')||to_char(hour,'09')||to_char(minute, '09')
      -- > ( select min(to_char(day, 'YYYYMMDD')||to_char(hour,'09')||to_char(minute, '09')) from fsq)
    where ratio > 0
    order by
        instance_name
      , instance_number
      , day
      , hour
      , minute
      , event_type
      , seconds_spent desc
      , wait_count desc
    Error at line 6
    ORA-00604: error occurred at recursive SQL level 1
    ORA-00972: identifier is too long

    Hi Alex,
    Subquery factoring a.k.a. the with-clause should be possible on 9.2:
    http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_103a.htm#2075888
    (used it myself as well on 9.2)
    @OP
    I recall having problems myself using PL/SQL Developer and trying to get the with clause to work on 9.2 some years ago.
    A workaround might be to create a view based on the query.
    Also, your error message is "ORA-00972: identifier is too long"...
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14219/e900.htm#sthref419
    Can't test things currently, no 9.2 available at the moment, but perhaps tomorrow I'll have a chance.

  • Can we Run a simple SQL statement from OBIEE Middle Tier node

    Hi
    i am working in OBIEE 11g environment. Database is installed on one node and Middle tier (BI services ) in other node,
    Can i use any utility to run a simple SQL statement from Middle tier ?
    Thanks
    Reddy

    Any utility means?
    We can create an ODBC connection on the BI server and run the sql.
    Mark if helps.

  • Copy records: is there a simpler sql statement

    For each record in one table "msTab" of a MS Sql Server database, I need basically to insert a new record to another one table "oraTab" in Oracle.
    I want to do this via codes to meet other requirements. I use Java with jdbc.
    It looks like a sql statement (built using codes) must look like:
    "Insert into oraTab(field1, field2, field3) values ('XXX', TO_DATE('13-NOV-92','DD-MON-YY', 322)"
    If my codes find the date data in msTab being null I thought I need to build insert statement as:
    "Insert into oraTab(field1, field3) values ('XXX', 322)", in order that Oracle will insert the default value for field2 automatically (field 2 of oraTab does not allow null).
    The logic is not as complicated if there are only 3 fields. But for a table with over a hundred fields, the codes to achieve this is not quite simple. Do I miss some simpler sql statement to do the job?
    Thanks.

    I believe Satish's suggestion was to use the DEFAULT keyword in the insert
    INSERT INTO table_name( col1, col2, col3 )
      VALUES( 1, DEFAULT, 2 );will insert the default value for col2. If you don't know which columns should take on the default value, though, I'm not sure how practical that would be.
    Were it me, I'd probably create a BEFORE INSERT trigger that replaced NULL values with appropriate default values and then just do
    INSERT INTO oracleTable( column_list )
      SELECT column_list
        FROM sqlTable@databaseLinkJustin

  • OO4O & VC++ Access Violation with large sql statement

    Using Oracle C++ Class Library OO4O for Oracle9i Version 9.0.1.4.3 for
    Windows 98/NT/2000/XP.
    Open a dynaset with a large sql statemant more then 1000 chars you get
    a Access Violation, like below.
    szSQL = "select..."
    ores = oDyn.Open( odb, szSQL, ODYNASET_READONLY || ODYNASET_NOCACHE);
    The same sql query works without any problem in SQL Plus. A simple SQL statement works fine using OO4O.
    Any ideas?

    I am using Jboss 2.44 with tomcat3.2.3, and I get deployment problems when using jdk1.5, I also tried JBoss 4 but I also have lots of problems with that.
    I have this huge system developed long time ago. I have problems with printing in jdk1.3 so upgrade to 1.4 or higher will fix the printing. Upgrading to jdk1.5 and JBoss 4 will need lots of rewrite which is not an option.
    So to me it seems easier if I keep using jboss2.44 and tomcat 3.2.3 but just upgrade to JDK 1.4. All off this is just because jdk1.3.1 has printing bugs.
    Bushwack, I am ding exactly like you are, the only difference is, ResultSet.CONCUR_UPDATABLE and I used , ResultSet.CONCUR_READONLY. But I tried and still the same error.
    I will try using a new JDBC driver, hope it works, I am just struggling to find a free one

  • OO4O & VC++ Access Violation with large sql statement  - REPOST

    This is a repost - my email address was incorrect on the previous message
    OO4O & VC++ Access Violation with large sql statement
    Using Oracle C++ Class Library OO4O for Oracle9i Version 9.0.1.4.3 for
    Windows 98/NT/2000/XP.
    Open a dynaset with a large sql statemant more then 1000 chars you get
    a Access Violation, like below.
    szSQL = "select..."
    ores = oDyn.Open( odb, szSQL, ODYNASET_READONLY || ODYNASET_NOCACHE);
    The same sql query works without any problem in SQL Plus. A simple SQL statement works fine using OO4O.
    Any ideas?
    [email protected]

    I am using Jboss 2.44 with tomcat3.2.3, and I get deployment problems when using jdk1.5, I also tried JBoss 4 but I also have lots of problems with that.
    I have this huge system developed long time ago. I have problems with printing in jdk1.3 so upgrade to 1.4 or higher will fix the printing. Upgrading to jdk1.5 and JBoss 4 will need lots of rewrite which is not an option.
    So to me it seems easier if I keep using jboss2.44 and tomcat 3.2.3 but just upgrade to JDK 1.4. All off this is just because jdk1.3.1 has printing bugs.
    Bushwack, I am ding exactly like you are, the only difference is, ResultSet.CONCUR_UPDATABLE and I used , ResultSet.CONCUR_READONLY. But I tried and still the same error.
    I will try using a new JDBC driver, hope it works, I am just struggling to find a free one

  • Help with this update statement..

    Hi everyone,
    I am trying to update a column in a table .I need to update that column
    with a function that takes patient_nbr and type_x column values as a parameter.
    That table has almost "300,000" records. It is taking long time to complete
    almost 60 min to 90 min.
    Is it usual to take that much time to update that many records?
    I dont know why it is taking this much time.Please help with this update statement.
    select get_partner_id(SUBSTR(patient_nbr,1,9),type_x) partner_id from test_load;
    (it is just taking 20 - 30 sec)
    I am sure that it is not the problem with my function.
    I tried the following update and merge statements .Please correct me if i am wrong
    in the syntax and give me some suggestions how can i make the update statement fast.
    update test_load set partner_id = get_partner_id(SUBSTR(patient_nbr,1,9),type_x);
    merge into test_load a
    using (select patient_nbr,type_x from test_load) b
    on (a.patient_nbr = b.patient_nbr)
    when matched
    then
    update
    set a.partner_id = get_partner_id(SUBSTR(b.patient_nbr,1,9),b.type_x);
    there is a index on patient_nbr column
    and the statistics are gathered on this table.

    Hi Justin,
    As requested here are the explain plans for my update statements.Please correct if i am doing anything wrong.
    update test_load set partner_id = get_partner_id(SUBSTR(patient_nbr,1,9),type_x);
    "PLAN_TABLE_OUTPUT"
    "Plan hash value: 3793814442"
    "| Id  | Operation          | Name             | Rows  | Bytes | Cost (%CPU)| Time     |"
    "|   0 | UPDATE STATEMENT   |                  |   274K|  4552K|  1488   (1)| 00:00:18 |"
    "|   1 |  UPDATE            |        TEST_LOAD |       |       |            |          |"
    "|   2 |   TABLE ACCESS FULL|        TEST_LOAD |   274K|  4552K|  1488   (1)| 00:00:18 |"
    merge into test_load a
    using (select patient_nbr,type_x from test_load) b
    on (a.patient_nbr = b.patient_nbr)
    when matched
    then
    update
    set a.partner_id = get_partner_id(SUBSTR(b.patient_nbr,1,9),b.type_x);
    "PLAN_TABLE_OUTPUT"
    "Plan hash value: 1188928691"
    "| Id  | Operation            | Name             | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |"
    "|   0 | MERGE STATEMENT      |                  |   274K|  3213K|       |  6660   (1)| 00:01:20 |"
    "|   1 |  MERGE               |        TEST_LOAD |       |       |       |            |          |"
    "|   2 |   VIEW               |                  |       |       |       |            |          |"
    "|*  3 |    HASH JOIN         |                  |   274K|    43M|  7232K|  6660   (1)| 00:01:20 |"
    "|   4 |     TABLE ACCESS FULL|        TEST_LOAD |   274K|  4017K|       |  1482   (1)| 00:00:18 |"
    "|   5 |     TABLE ACCESS FULL|        TEST_LOAD |   274K|    40M|       |  1496   (2)| 00:00:18 |"
    "Predicate Information (identified by operation id):"
    "   3 - access("A"."patient_nbr"="patient_nbr")"Please give some suggestions..
    what's the best approach for doing the updates for huge tables?
    Thanks

  • Need help with the session state value items.

    I need help with the session state value items.
    Trigger is created (on After delete, insert action) on table A.
    When insert in table B at least one row, then trigger update value to 'Y'
    in table A.
    When delete all rows from a table B,, then trigger update value to 'N'
    in table A.
    In detail report changes are visible, but the trigger replacement value is not set in session value.
    How can I implement this?

    You'll have to create a process which runs after your database update process that does a query and loads the result into your page item.
    For example
    SELECT YN_COLUMN
    FROM My_TABLE
    INTO My_Page_Item
    WHERE Key_value = My_Page_Item_Holding_Key_ValueThe DML process will only return key values after updating, such as an ID primary key updated by a sequence in a trigger.
    If the value is showing in a report, make sure the report refreshes on reload of the page.
    Edited by: Bob37 on Dec 6, 2011 10:36 AM

  • Help with oracle sql to get all possible combinations in a table.

    Hello guys I have a small predicatement that has me a bit stumped. I have a table like the following.(This is a sample of my real table. I use this to explain since the original table has sensitive data.)
    CREATE TABLE TEST01(
    TUID VARCHAR2(50),
    FUND VARCHAR2(50),
    ORG  VARCHAR2(50));
    Insert into TEST01 (TUID,FUND,ORG) values ('9102416AB','1XXXXX','6XXXXX');
    Insert into TEST01 (TUID,FUND,ORG) values ('9102416CC','100000','67130');
    Insert into TEST01 (TUID,FUND,ORG) values ('955542224','1500XX','67150');
    Insert into TEST01 (TUID,FUND,ORG) values ('915522211','1000XX','67XXX');
    Insert into TEST01 (TUID,FUND,ORG) values ('566653456','xxxxxx','xxxxx');
    "TUID"                        "FUND"                        "ORG"                        
    "9102416AB"                   "1XXXXX"                      "6XXXXX"                     
    "9102416CC"                   "100000"                      "67130"                      
    "955542224"                   "1500XX"                      "67150"                      
    "915522211"                   "1000XX"                      "67XXX"                      
    "566653456"                   "xxxxxx"                      "xxxxx"                       The "X"'s are wild card elements*( I inherit this and i cannot change the table format)* i would like to make a query like the following
    select tuid from test01 where fund= '100000' and org= '67130'however what i really like to do is retrieve any records that have have those segements in them including 'X's
    in other words the expected output here would be
    "TUID"                        "FUND"                        "ORG"                        
    "9102416AB"                   "1XXXXX"                      "6XXXXX"                     
    "9102416CC"                   "100000"                      "67130"                      
    "915522211"                   "1000XX"                      "67XXX"                      
    "566653456"                   "xxxxxx"                      "xxxxx"  i have started to write a massive sql statement that would have like 12 like statement in it since i would have to compare the org and fund every possible way.
    This is where im headed. but im wondering if there is a better way.
    select * from test02
    where fund = '100000' and org = '67130'
    or fund like '1%' and org like '6%'
    or fund like '1%' and org like '67%'
    or fund like '1%' and org like '671%'
    or fund like '1%' and org like '6713%'
    or fund like '1%' and org like '67130'
    or fund like '10%' and org like '6%'...etc
    /*seems like there should be a better way..*/can anyone give me a hand coming up with this sql statement...

    mlov83 wrote:
    if i run this
    select tuid,fund, org
    from   test01
    where '100000' like translate(fund, 'xX','%%') and '67130' like translate(org, 'xX','%%');this is what i get
    "TUID"                        "FUND"                        "ORG"                        
    "9102416AB"                   "1XXXXX"                      "6XXXXX"                     
    "9102416CC"                   "100000"                      "67130"                      
    "915522211"                   "1000XX"                      "67XXX"                      
    "566653456"                   "xxxxxx"                      "xxxxx"                      
    "9148859fff"                  "1XXXXXX"                     "X6XXX"                       the last item should be excluded. The second digit in "org" is a "7" Fund is wrong, too. You're looking for 6 characters ('100000'), but fund on that row is 7 characters ('1XXXXXX').
    and this is sitll getting picked up.That's why you should use the _ wild-card, instead of %
    select  tuid, fund, org
    from    test01
    where  '100000' like translate (fund, 'xX', '__')
    and    '67130'  like translate (org,  'xX', '__')
    ;It's hard to see, but, in both calls to TRANSLATE, the 3rd argument is a string of 2 '_'s.

Maybe you are looking for