Insert New Records to the same table based on an existing record

How do I write a query to get the output shown in the OutputTable?  Salary in OutputTable  = TableA.Salary * TableB.SCode
I posted a similar question earlier but no solution, so, I've decided to use a different approach to get it done.
TableA
EmpId
FName
LName
EType
ECat
Salary
1
John
Doe
Perm
E
100
3
Jane
Jones
Perm
E
150
4
Mike
Moses
Cont
C
50
7
Eric
Holder
Cont
C
75
9
Pete
Pan
Perm
E
60
TableB
EmpId
ECat
SCode
1
L
2
2
L
5
3
L
5
4
L
10
5
L
7
OutputTable
EmpId
FName
LName
EType
ECat
Salary
1
John
Doe
Perm
E
100
3
Jane
Jones
Perm
E
150
4
Mike
Moses
Cont
C
50
7
Eric
Holder
Cont
C
75
9
Pete
Pan
Perm
E
60
1
John
Doe
Manual
E
200
3
Jane
Jones
Manual
C
750
4
Eric
Holder
Manual
C
500

The first line of your code; is the syntax correct?
INSERT TableA
yes
so far as table structure matches with the source you dont need a column list
Just use destination table name instead
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page

Similar Messages

  • Duplicate records in the same table

    Hello.
    I want to duplicate records in the same table, changing just two date fields and id. Id is changed with sequence.
    Example:
    id name start_date end_date
    1 record_1 01.01.04 31.12.04
    2 record_2 01.01.03 31.12.03
    I want to duplicate record with the start_date year 04 and the duplicated record would change that start_date into year 05.
    After duplicate it should look like:
    1 record_1 01.01.04 31.12.04
    2 record_2 01.01.03 31.12.03
    3 record_1 01.01.05 31.12.05
    How should my insert look like?
    Thanks

    create sequence A_SEQ
       start with 3
       nocache
    insert into tableA
            (ID, name, start_date end_date)
       select
               A_SEQ.nextval   
              ,NAME
              ,start_date + add_months (12)
              ,end_date   + add_months (12)
         from
               tableA
        where
               start_date >= to_date('01.01.2004','dd.mm.yyyy')
          and  start_date <= to_date('01.01.2004','dd.mm.yyyy')

  • Master and Detail records in the same table

    Hi Steve,
    I have master and detail address records in the same table (self-reference). The master addresses are used as templates for detail addresses. Master addresses do not have any masters. Detail addresses have three masters: a master address, a calendar reference and a department. Addresses change from time to time and every department has its own email-account, but they refer to the same master to pre-fill some common values.
    Now I need to edit the master and detail address records on the same web page simultaneously.
    My question is: Can I implement a Master-View and Detail-View which refer to the same Entity-Object? Or should I implement a second Entity-Object? Or can it be done in a single Master-Detail-View?
    Thanks a lot.
    Kai.

    At a high level, wouldn't this be similar to an Emp entity based on the familiar EMP table that has an association from Emp to itself for the Emp.Mgr attribute?
    You can definitely build a view object that references two entity usages of the same entity like this to show, say, an employee's ENAME and at the same time their manager's ENAME.
    If there are multiple details for a given master, you can also do that with separate VO's both based on the same entity, sure. Again, just like a VO that shows a manager, and a view-linked VO of all the employees that report to him/her.

  • Calculating average time from two records from the same table.

    Hi all
    I need to calculate the average time between two events that are recorded in the same table.
    The table is TMS_MESSAGE_AUDIT_LOG
    MESSAGE_ID VARCHAR2(16 BYTE) NOT NULL,
    MESSAGE_VERSION NUMBER(2) NOT NULL,
    CREATE_TM VARCHAR2(18 BYTE) NOT NULL,
    MESSAGE_STATUS VARCHAR2(30 BYTE),
    TRANSACTION_TYPE_NM VARCHAR2(30 BYTE),
    MESSAGE_TP VARCHAR2(3 BYTE),
    WORKFLOW_OBJECT VARCHAR2(30 BYTE) NOT NULL,
    WORKFLOW_REQUEST VARCHAR2(30 BYTE) NOT NULL,
    WORKFLOW_RETURN_CD VARCHAR2(30 BYTE) NOT NULL,
    AUDIT_ACTION VARCHAR2(255 BYTE),
    LAST_UPDATE_USER_LOGON_ID VARCHAR2(12 BYTE),
    LOCAL_TM VARCHAR2(18 BYTE) NOT NULL,
    LOCAL_TIME_ZN_NM VARCHAR2(70 BYTE) NOT NULL,
    LOCAL_DAYLIGHT_IN CHAR(1 BYTE) NOT NULL,
    FPRINT VARCHAR2(30 BYTE)
    What i now need is
    When the MESSAGE_ID is the same i need have the average time between when the MESSAGE_STATUS is AA and BB ( I need the time out of the CREATE_TM field )
    And this for every 15 minutes interval.
    Because this table will become BIG millions and millions of records it needs to be fast.
    Can anybody help me.
    Marcel

    Something like this?
    CREATE TABLE wr_test
    ( message_id                 VARCHAR2(16 BYTE) NOT NULL
    , message_version            NUMBER(2) NOT NULL  -- Assumption: Acknowledged ver > Received ver
    , create_tm                  VARCHAR2(18 BYTE) NOT NULL
    , message_status             VARCHAR2(30 BYTE)
    , transaction_type_nm        VARCHAR2(30 BYTE)
    , workflow_object            VARCHAR2(30 BYTE) DEFAULT 'x' NOT NULL
    , workflow_request           VARCHAR2(30 BYTE) DEFAULT 'x' NOT NULL
    , workflow_return_cd         VARCHAR2(30 BYTE) DEFAULT 'x' NOT NULL
    , audit_action               VARCHAR2(255 BYTE)
    , last_update_user_logon_id  VARCHAR2(12 BYTE)
    , local_tm                   VARCHAR2(18 BYTE) NOT NULL
    , local_time_zn_nm           VARCHAR2(70 BYTE) DEFAULT 'GMT' NOT NULL
    , local_daylight_in          CHAR(1 BYTE) DEFAULT 'x' NOT NULL );
    INSERT ALL
    INTO   wr_test
           ( message_id
           , message_version
           , create_tm
           , message_status
           , local_tm )
    VALUES ( message_id
           , 1
           , create_tm
           , '(Receive)'
           , TO_CHAR(local_tm,'YYYYMMDD HH24:MI:SS') )
    INTO   wr_test
           ( message_id
           , message_version
           , create_tm
           , message_status
           , local_tm )
    VALUES ( message_id
           , 2
           , create_tm
           , 'Wait CLSB Ack'
         , TO_CHAR
           ( local_tm + NUMTODSINTERVAL(DBMS_RANDOM.VALUE(0,2e5),'SECOND')
           , 'YYYYMMDD HH24:MI:SS' ) )
    SELECT ROWNUM AS message_id
         , TO_CHAR(SYSDATE,'YYYYMMDD HH24:MI:SS') AS create_tm
         , DATE '2000-01-01' + DBMS_RANDOM.VALUE(0,3) AS local_tm
    FROM dual CONNECT BY ROWNUM < 100000;
    WITH src AS
         ( SELECT message_id
                , message_status
                , message_version
                , TO_DATE(SUBSTR(local_tm,1,17),'YYYYMMDD HH24:MI:SS') AS dt
                , TO_DATE(SUBSTR(local_tm,1,8),'YYYYMMDD') AS dt_day
                , TO_CHAR(TO_DATE(SUBSTR(local_tm,10,8),'HH24:MI:SS'),'SSSSS') AS dt_sec
           FROM   wr_test
           WHERE  message_status IN ('(Receive)','Wait CLSB Ack') )
    SELECT dt_day + NUMTODSINTERVAL(period,'SECOND') AS dt
         , NUMTODSINTERVAL(AVG(elapsed),'DAY') AS avg_elapsed
         , NUMTODSINTERVAL(MIN(elapsed),'DAY') AS min_elapsed
         , NUMTODSINTERVAL(MAX(elapsed),'DAY') AS max_elapsed
         , COUNT(*)
    FROM   ( SELECT message_id
                  , message_status
                  , dt_day
                  , TRUNC(dt_sec/300)*300 AS period
                  , LEAD(dt) OVER (PARTITION BY message_id ORDER BY message_version) AS ack_dt
                  , LEAD(dt) OVER (PARTITION BY message_id ORDER BY message_version) - dt AS elapsed
             FROM   src ) cal
    WHERE  cal.message_status = '(Receive)'
    GROUP BY dt_day, period
    ORDER BY 1;Replace "wr_test" with "tms_message_audit_log" in the WITH subquery to test on your data.

  • How to populate data in the same table based on different links/buttons

    Hi
    I'm using jdeveloper 11.1.4. I have a use case in which i need to populate data in the same table based on click of different links.
    Can anyone please suggest how can this be achieved.
    Thanks

    I have a use case in which i need to populate data in the same table based on click of different linksDo you mean that you need to edit existing rows ?
    What format do you have the date in - table / form ?

  • How can I start a new paragraph within the same table cell?

    In Numbers, when adding text within a table frame, how can I start a new line within the same frame (rather than advancing to the next cell)?  I'd like to enter a mini-list of several items of various lengths of data.

    While Wayne's answer solves your problem, another possibility is to uncheck the box at the bottom of the Table inspector for "Return key moves to next cell." If that is unchecked, the return key types a paragraph return within the cell (the same as Option Return with the box checked).
    With that box unchecked, Shift Return types a soft return (new line without a paragraph break).

  • Parallel Insert statements (bulk) to the same table

    Hi,
    I am in need to insert set of insert statements 50000+ in to table and wanted to split them in to tow halves and run in two SQL worksheets.
    Note that both will try to insert on the same table.
    Please let me know whether it is advisable or tell me an alternative way.
    Using...Oracle 11g DB.
    Regards
    Deep.

    935195 wrote:
    I am in need to insert set of insert statements 50000+ in to table and wanted to split them in to tow halves and run in two SQL worksheets.Small number of rows. 50,000 rows can be inserted in seconds. Not sure why you want to split it. Parallel inserts into the same table is not usually a problem. Contention could be around free lists, initrans and so on - especially if using RAC and inserting something like 50,000+ rows every second. But the table defaults usually suffice.
    Note that both will try to insert on the same table.So what? This is exactly what Oracle expects and what it is designed to do.
    Please let me know whether it is advisable or tell me an alternative way.Well, you mentioned SQL worksheets - why? Exactly how does the INSERT statements look like? Where does the data to insert come from? Is shared insert cursors used (bind variables compulsory)? The bottleneck and problem could very well be on your side and not with the actual inserts into the table.

  • How to compare records in the same table?

    I have a table of course registrations.  I would like to select course registrations as of a certain date that do not have a dropped status against it.
    CREATE TABLE REGISTRATIONS
    (ID VARCHAR(7) ,
    COURSE VARCHAR(4),
    CURRENT_STATUS VARCHAR(10),
    STATUS_DATE VARCHAR(10))
    INSERT INTO REGISTRATIONS
    (ID, COURSE, CURRENT_STATUS, STATUS_DATE)
    VALUES
    ('1111111','ADMN', 'REGISTERED', '2014-04-10'),
    ('1111111','MATH', 'REGISTERED', '2014-04-10'),
    ('1111111','ADMN', 'DROPPED', '2014-04-10'),
    ('1111111','MATH', 'DROPPED', '2014-04-12'),
    ('1111111','BIOL', 'REGISTERED', '2014-04-10')
    SELECT * FROM REGISTRATIONS
    ORDER BY COURSE, CURRENT_STATUS
    drop table REGISTRATIONS
    ID COURSE CURRENT_STATUS STATUS_DATE
    1111111 ADMN DROPPED 2014-04-10
    1111111 ADMN REGISTERED 2014-04-10
    1111111 BIOL REGISTERED 2014-04-10
    1111111 MATH DROPPED 2014-04-12
    1111111 MATH REGISTERED 2014-04-10
    The above example shows that ID '1111111' has registered for ADMN and BIOL on April 10th but dropped ADMN the same day.  It also shows that they registered for MATH on April 10th but dropped it on the 12th.
    If I were to select course registrations to date as of April 10 I would see both ADMN records, BIOL and MATH.  BIOL and MATH would be OK but I don't want to see the ADMN data in the result because they have essentially cancelled themselves out. 
    In saying that, how do I write a script to select all course registrations as of a certain date but omit the ones that have been dropped at anytime before the select date?

    check below,
    SELECT * FROM REGISTRATIONS a
    WHERE CURRENT_STATUS <> 'DROPPED' AND STATUS_DATE <= '2014-04-12'
    AND COURSE NOT IN (
    SELECT COURSE FROM REGISTRATIONS
    WHERE CURRENT_STATUS = 'DROPPED' AND STATUS_DATE <= '2014-04-12')
    ORDER BY a.COURSE, a.CURRENT_STATUS

  • How can I run a check for a record across other records in the same dataset based on unique key constraint?

    Dear community,
    I have a flat data set which I run through a lookup and return. I want to check if at least one of the records matching a unique key constraint had a successful return without merging all the records. Can some one point me in the right direction?
    Thanks!
    Marc

    Hi,
    Sounds like a job for the Lookup Check processor!
    As with all check processors, it adds a flag attribute (with a Y/N value) that denotes if the lookup was successful or not, as well as filtering records based on this at output.
    Lookup Check does the same as Lookup and Return but does not return the record(s) looked up.
    Also note that Lookup and Return does not actually merge records, but it does pull back the return data (which you can then split if you want a record for each).
    Regards,
    Mike

  • Compare several records in the same table

    Hello, i´m writing a BAT file so i can export some information that i query.
    I have a automatic integration that from time to time checks if there is any new client´s and generates a trigger.
    If an error ocurs i it will repeat the process until the client is in the database.
    I cannot create tables or modify structure.
    My problem is that i need to compare the most updated record with the field CLIENT_ID
    Let me give up an example:
    Table A
    CLIENT_ID CREATEDTIME ERROR_MESSAGE
    0 01-01-2009 Sucess
    1 01-01-2009 Error
    2 01-01-2009 Sucess
    1 02-01-2009 Sucess
    3 02-01-2009 Sucess
    4 02-01-2009 Error
    I need to compare client "1" created on 01-01-2009 that gived Error with all new records to see if is Sucess and my
    query should only return the client_ID "4" and export with sqlplus
    Could you please help me out?

    with my_tab as (select 0 client_id, to_date('01/01/2009', 'dd/mm/yyyy') createdtime, 'Sucess' error_message from dual union all
                    select 1 client_id, to_date('01/01/2009', 'dd/mm/yyyy') createdtime, 'Error' error_message from dual union all
                    select 2 client_id, to_date('01/01/2009', 'dd/mm/yyyy') createdtime, 'Sucess' error_message from dual union all
                    select 1 client_id, to_date('02/01/2009', 'dd/mm/yyyy') createdtime, 'Sucess' error_message from dual union all
                    select 3 client_id, to_date('02/01/2009', 'dd/mm/yyyy') createdtime, 'Sucess' error_message from dual union all
                    select 4 client_id, to_date('02/01/2009', 'dd/mm/yyyy') createdtime, 'Error' error_message from dual)
    -- end of test data set up to mimic a table called "my_tab"
    select client_id
    from   my_tab
    group by client_id
    having max(decode(error_message, 'Error', 1, 2)) = 1;should do what you want.
    Edited by: Boneist on 05-Jan-2009 16:06
    Hmm, not quite.... thinking of an amendment if the answer to BluShadow's question is Yes
    Aha,
    with my_tab as (select 0 client_id, to_date('01/01/2009', 'dd/mm/yyyy') createdtime, 'Sucess' error_message from dual union all
                    select 1 client_id, to_date('01/01/2009', 'dd/mm/yyyy') createdtime, 'Error' error_message from dual union all
                    select 2 client_id, to_date('01/01/2009', 'dd/mm/yyyy') createdtime, 'Sucess' error_message from dual union all
                    select 1 client_id, to_date('02/01/2009', 'dd/mm/yyyy') createdtime, 'Sucess' error_message from dual union all
                    select 3 client_id, to_date('02/01/2009', 'dd/mm/yyyy') createdtime, 'Sucess' error_message from dual union all
                    select 4 client_id, to_date('02/01/2009', 'dd/mm/yyyy') createdtime, 'Error' error_message from dual union all
                    select 1 client_id, to_date('03/01/2009', 'dd/mm/yyyy') createdtime, 'Error' error_message from dual)
    -- end of test data set up to mimic a table called "my_tab"
    select client_id
    from   my_tab
    group by client_id
    having max(decode(error_message, 'Error', 1, 2)) keep (dense_rank last order by createdtime) = 1;(which happens to be a more generalised form of what Frank's posted below!)

  • Two records from the same table in for loop

    I have a table that holds teams, a table that holds scores and a table that holds match data.
    I am finding it dificult to get the player data for the second team.
    Currently It is showing player information for one team.
    It does echo out the second team name, but not their player info.
    Can someone have a look at my code and make it work.
    I took off the code I had for the second team becuase it was ging me Error 1065
    Main Query:
    mysql_select_db($database_db, $db);
    $query_match_fixtures = "select m.match_id, date_format(m.date, '%d/%m/%Y') as mDate, m.time, t1.division, m.report, t1.team_name as team1_name, s1.score as score1, t2.team_name as team2_name, s2.score as score2
    from matches m left join (matchscores s1 left join team t1 on t1.team_id = s1.team) on (s1.match_id = m.match_id) left join (matchscores s2 left join team t2 on t2.team_id = s2.team) on (s2.match_id = m.match_id)
    where s1.team <> s2.team AND m.match_id = $matchID
    group by match_id
    order by m.match_id";
    $match_fixtures = mysql_query($query_match_fixtures, $db) or die(mysql_error());
    //$row_match_fixtures = mysql_fetch_assoc($match_fixtures);
    $totalRows_match_fixtures = mysql_num_rows($match_fixtures);
    Player extraction:
    mysql_select_db($database_db, $db);
    $row_match_player = array();
    for ($i = 0; $i < $totalRows_history; $i++)
        $row_history[$i] = mysql_fetch_assoc($history);
    for ($i = 0; $i < $totalRows_match_fixtures; $i++)
        $row_match_fixtures[$i] = mysql_fetch_assoc($match_fixtures);
        $match_player_query = "SELECT *
                               FROM match_player
                                LEFT JOIN player on player.player_id = match_player.player_id
                                LEFT JOIN team ON player.team_id = team.team_id
                               WHERE match_id = ".$matchID."
                                AND team.team_name = '".$row_match_fixtures[$i]['team1_name']."'";
        $result_match_player = mysql_query($match_player_query, $db) or die("large error ".mysql_errno());
        $totalRows_match_player = mysql_num_rows($result_match_player);
        for ($r; $r < $totalRows_match_player; $r++)
            $temp_row_match_player[$r] = mysql_fetch_assoc($result_match_player);
        array_push($row_match_player, $temp_row_match_player);
    The display table:
            <div class="tableHeading">
            <h2><?php echo $row_history['mDate']; ?></h2>
            </div>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="25" bgcolor="#000000"><div align="left" style="color:#FFFFFF"><strong>Type</strong></div></td>
        <td height="25" bgcolor="#000000"><div align="left" style="color:#FFFFFF"><strong>Home</strong></div></td>
        <td height="25" bgcolor="#000000"><div align="center" style="color:#FFFFFF"><strong>Score</strong></div></td>
        <td height="25" bgcolor="#000000"><div align="center" style="color:#FFFFFF"><strong>Away</strong></div></td>
        <td height="25" bgcolor="#000000"><div align="center" style="color:#FFFFFF"><strong>Kick-Off</strong></div></td>
        <td height="25" bgcolor="#000000"><div align="center" style="color:#FFFFFF"><strong>Venue</strong></div></td>
        <td height="25" bgcolor="#000000"><div align="center" style="color:#FFFFFF"><strong>Referee</strong></div></td>
      </tr>
      <tr>
        <?php foreach ($row_match_fixtures as $show_match_fixtures)
        { ?>
            <td height="25" bgcolor="#dfdfdf">
            <div align="left"><?php echo $show_match_fixtures['division']; ?></div>
            </td>
            <td height="25" bgcolor="#dfdfdf">
            <div align="left"><?php echo $show_match_fixtures['team1_name']; ?></div>
            </td>
            <td height="25" bgcolor="#dfdfdf">
            <div align="center"><?php echo $show_match_fixtures['score1']; ?> - <?php echo $show_match_fixtures['score2']; ?></div>
            </td>
            <td height="25" bgcolor="#dfdfdf">
            <div align="center"><?php echo $show_match_fixtures['team2_name']; ?></div>
            </td>
            <td height="25" bgcolor="#dfdfdf">
            <!-- You do not want a nested loop inside the header so these results will have to go inside the table-->
            <div align="center"><?php echo $row_history['time']; ?></div>
            </td>
            <td height="25" bgcolor="#dfdfdf">
            <div align="center"><?php echo $row_history['venue_name']; ?></div>
            </td>
            <td height="25" bgcolor="#dfdfdf">
            <div align="center"><?php echo $row_history['fname']; ?> <?php echo $row_history['sname']; ?></div>
            </td>
        </tr>
          <tr>
            <?php foreach ($row_match_player as $player_array)
                   foreach ($player_array as $player_display)
            ?>
            <td valign="top">Goalscorers</td>     
            <td>
              <?php echo $player_display['fname']." ".$player_display['sname']." (".$player_display['Goals']; ?>)<br />
            </td>
            <td> </td>
            <td>
              <?php echo $player_display['fname']." ".$player_display['sname']." (".$player_display['Goals']; ?>)<br />
            </td>
            <td> </td>
            <td> </td>
            <td> </td>
          </tr>
          <tr>
            <td valign="top">Yellow Cards</td>
            <td><?php echo $player_display['YC']; ?></td>
            <td> </td>
            <td><?php echo $player_display['YC']; ?></td>
            <td> </td>
            <td> </td>
            <td> </td>
          </tr>
          <tr>
            <td valign="top">Red Cards</td>
            <td><?php echo $player_display['RC']; ?></td>
            <td> </td>
            <td><?php echo $player_display['RC']; ?></td>
            <td> </td>
            <td> </td>
            <td> </td>
          </tr>
          <tr>
            <td valign="top">Man of the Match</td>
            <td><?php echo $player_display['fname']; ?> <?php echo $player_display['sname']; ?></td>
            <td> </td>
            <td><?php echo $player_display['fname']; ?> <?php echo $player_display['sname']; ?></td>
            <td> </td>
            <td> </td>
            <td> </td>
          </tr>
                <?php
                    }// close and unset $player_display
                    unset($player_display);
                } //close and unset $player_array
            unset($player_array);
         } //close and unset $show_match_fixtures
        unset($show_match_fixtures);?>
    </table>
    As you can see from  the picture above the table is displayed with the name of the "goal  scorer" for that team under (home) or Home team
    When I try to create the same thing for away team I get a error, either a syntax error or 1065.
    I tried having a foreach do two queries but that did not work.
    Any help would be appriecated

    I did try that, but I have messed it up.
    Now the team names do not display at the top of the table.

  • Trying to insert a single row in a table based on NOT EXIST

    Hi,
    I have a procedure where i am doing an insert into the table say
    create table ABC(PK number, valu varchar2(10));
    insert into ABC values(1,'hi');
    Now my problem is that this procedure may be run several times so if a PK already exists, it should not try to insert again. so I came up with the solution..
    insert into ABC select (1,'hi') from ABC where not exists (select 1 from ABC where PK=1);
    but the problem with this is that if Pk=1 does not exist and if the table already has 5 rows, 5 insertions of PK=1 are being done..
    can anyone plz help me.
    thanks

    Why dont you let Oracle handle the uniqueness of the records and you make your code robust to handle that exception?
    DUP_VAL_ON_INDEX exception can be caught in your procedure and no action needs to be taken on that in this case.

  • How do you Copy a row to create a new row in the same table?

    Hi,
    We have a PurchaseOrderHeaderView object and on click of Copy Purchase Order we want to copy a row in PURCHASE_ORDER_HEADER table to create a new row. We don't want to copy the primary key only the remaining fields.
    Regards
    Madhuri

    If you use ADF BC, you can create a new row programatically via createRow and use a sequence to create the Id and use the "original" row (probably the current row in the view object) to copy the values from to newly created row. Then use insertRow and commit to create the copied row.
    Ronald

  • Findout the record in the same table

    Hi dear
    i have attendance table which have following columns
    CO_CODE NOT NULL VARCHAR2(2)
    CARD_NO NOT NULL VARCHAR2(6)
    PERIOD NOT NULL VARCHAR2(6)
    ATTEN_DATE NOT NULL DATE
    TIME_IN NOT NULL DATE
    TIME_OUT DATE
    BREAK_CODE NOT NULL NUMBER(1)
    in the table break_code = 2 its mean 'lunch break'
    and break_code = 3 its mean 'out door duty'
    break_code = 1 its meaning 'duty off'
    card_no period date time_in time_out break_code
    000220 200801 01-JAN-08 08:00 16:30 1
    000220 200801 02-JAN-08 08:01 09:30 3
    000220 200801 02-JAN-08 14:25 16:30 1
    000220 200801 03-JAN-08 08:00 08:45 3
    000220 200801 03-JAN-08 10:10 16:30 1
    000220 200801 04-JAN-08 08:00 16:30 1
    i just find the records which date have break_code and also duty off.
    please send us the query
    result will be as
    000220 200801 02-JAN-08 08:01 09:30 3
    000220 200801 02-JAN-08 14:25 16:30 1
    000220 200801 03-JAN-08 08:00 08:45 3
    000220 200801 03-JAN-08 10:10 16:30 1
    an early response will be highly appreciated.
    thanks
    regards
    abid

    1 = duty off
    3 = out door duty (perform duty out side the plant)
    I just select those records which card have two rows and break_code (1,3).
    CARD_N PERIOD ATTEN_DAT TIME_IN TIME_out BREAK_CODE
    000220 200801 01-JAN-08 08:00     16:33 1
    000220 200801 02-JAN-08 08:02      11:00 3
    000220 200801 02-JAN-08 12:53      16:32 1
    000220 200801 03-JAN-08 07:49      10:18 3
    000220 200801 03-JAN-08 11:12      16:33 1
    000521 200801 04-JAN-08 07:57      16:34 1
    000521 200801 05-JAN-08 07:56      10:38 3
    000521 200801 05-JAN-08 11:59      16:34 1
    000521 200801 07-JAN-08 08:00      08:31 3
    000521 200801 07-JAN-08 10:08      16:36 1
    000521 200801 08-JAN-08 08:00      09:36 3
    000521 200801 08-JAN-08 11:10      16:37 1
    000526 200801 09-JAN-08 08:00      10:20 3
    000526 200801 09-JAN-08 11:57      16:33 1
    000526 200801 10-JAN-08 08:21      16:34 1
    000526 200801 11-JAN-08 08:05      10:26 3
    000526 200801 11-JAN-08 11:34      12:37 2
    000526 200801 11-JAN-08 13:35      16:35 1
    000526 200801 12-JAN-08 08:00      09:02 3
    000526 200801 12-JAN-08 09:52      16:36 1
    000542 200801 14-JAN-08 07:50      16:35 1
    000542 200801 15-JAN-08 07:59      10:20 3
    000542 200801 15-JAN-08 12:17      16:32 1
    000542 200801 16-JAN-08 07:52      10:34 3
    000542 200801 16-JAN-08 11:40      16:35 1
    000542 200801 17-JAN-08 07:53      16:35 1
    000513 200801 18-JAN-08 07:59      16:35 1
    000513 200801 21-JAN-08 07:54      10:47 3
    000513 200801 21-JAN-08 11:52      16:33 1
    000513 200801 22-JAN-08 07:54      09:35 3
    000513 200801 22-JAN-08 10:36      16:31 1
    000520 200801 23-JAN-08 07:52      11:15 3
    000520 200801 23-JAN-08 11:55      16:32 1
    000520 200801 24-JAN-08 08:04      10:54 3
    000520 200801 24-JAN-08 12:27      16:32 1
    000520 200801 25-JAN-08 08:04      16:33 1
    000520 200801 26-JAN-08 07:51      10:15 3
    my result should be.
    CARD_N PERIOD ATTEN_DAT TIME_IN TIME_out BREAK_CODE
    000220 200801 02-JAN-08 08:02      11:00 3
    000220 200801 02-JAN-08 12:53      16:32 1
    000220 200801 03-JAN-08 07:49      10:18 3
    000220 200801 03-JAN-08 11:12      16:33 1
    000521 200801 05-JAN-08 07:56      10:38 3
    000521 200801 05-JAN-08 11:59      16:34 1
    000521 200801 07-JAN-08 08:00      08:31 3
    000521 200801 07-JAN-08 10:08      16:36 1
    000521 200801 08-JAN-08 08:00      09:36 3
    000521 200801 08-JAN-08 11:10      16:37 1
    000526 200801 09-JAN-08 08:00      10:20 3
    000526 200801 09-JAN-08 11:57      16:33 1
    000526 200801 11-JAN-08 08:05      10:26 3
    000526 200801 11-JAN-08 11:34      12:37 2
    000526 200801 11-JAN-08 13:35      16:35 1
    000526 200801 12-JAN-08 08:00      09:02 3
    000526 200801 12-JAN-08 09:52      16:36 1
    000542 200801 15-JAN-08 07:59      10:20 3
    000542 200801 15-JAN-08 12:17      16:32 1
    000542 200801 16-JAN-08 07:52      10:34 3
    000542 200801 16-JAN-08 11:40      16:35 1
    000513 200801 21-JAN-08 07:54      10:47 3
    000513 200801 21-JAN-08 11:52      16:33 1
    000513 200801 22-JAN-08 07:54      09:35 3
    000513 200801 22-JAN-08 10:36      16:31 1
    000520 200801 23-JAN-08 07:52      11:15 3
    000520 200801 23-JAN-08 11:55      16:32 1
    000520 200801 24-JAN-08 08:04      10:54 3
    000520 200801 24-JAN-08 12:27      16:32 1

  • Inserting a LONG to a BLOB in the same table

    I have a table with a LONG column and would like to concatenate all existing columns into a new column in the same table and define it as a BLOB. I'm trying to figure out a way to do this. I tried the following and got error message
    insert into cma_search_test
    select obj_id,
         line_id,
         doc_nmbr,
         supplier_part_num,
         mnfctr,
         mnfctr_part_nmbr,
         line_desc,
         ext_desc_txt,
         vend_name,
         cma_effect_dt,
         cma_expir_dt,
         last_updt_usr,
         last_updt_tmsp,
         obj_id||
         line_id||
         doc_nmbr||
         supplier_part_num||
         mnfctr||
         mnfctr_part_nmbr||
         line_desc||
         to_lob(ext_desc_txt)||
         vend_name||
         cma_effect_dt||
         cma_expir_dt||
         last_updt_usr||
         last_updt_tmsp "All_Columns"
    from cma_search
    to_lob(ext_desc_txt)||
    ERROR at line 22:
    ORA-00932: inconsistent datatypes
    Any help would be appreciated.
    Thanks,
    Tracy

    You cannot concatenate a LONG field. You will have to use a procedure to accomplish what you want.
    Use the DBMS_LOB package.

Maybe you are looking for