Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2011
    Posts
    34

    Unanswered: SQL - Split dataset by every other row

    Hi Guys,

    I'm using SQL and can anyone help me split a dataset into 2 different groups. I need to split the customers base on every other row.

    i.e odd rownums go to 1 file and even rownums go to another.

    Thanks!

    P.S we just updated our database from DB2 to Oracle, so this kind of stuff is different for me.
    - Using Oracle 11g with Toad v12

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    you will need to write PL/SQL procedure & utilize UTL_FILE
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    Code:
    begin
    for pnt in (select col1,col2,col3,rownum rnum
                        from my_table) loop
    if mod(pnt.rnum,2) = 0 then
      insert into new_file1 values(pnt.col1,pnt.col2,pnt.col3);
    else
      insert into new_file2 values(pnt.col1,pnt.col2,pnt.col3);
    end if;
    end loop;
    commit;
    end;
    /
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

  4. #4
    Join Date
    Aug 2011
    Posts
    34
    I actually added this and ran the query twice and it worked...

    where mod(rownum,2) <> 0 -- gets even records
    and then....
    where mod(rownum,2) = 0 -- get odd records

    thanks for your help beilstwh
    - Using Oracle 11g with Toad v12

  5. #5
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool

    Quote Originally Posted by nadecian View Post
    - Using DB2 9.7 LUW
    DB2?
    It seems we here at the Oracle Forum are the BEST!
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •