Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

unable to create Query ? (Interesting Scenerio)

569986Dec 2 2009 — edited Dec 7 2009
Hi all, i am unable to create a query for below expected output with the following data. Any help will be appreciated?


Expected output

ID1 NAME1 ID2 NAME2
1 test1 2 test2
3 test3 4 test4
5 test5 6 test6



Thanks in Advance
This post has been answered by 730428 on Dec 2 2009
Jump to Answer

Comments

jgarry

Oracle tables are heap tables, there is no intrinsic order.

You can either use the order by statement when you select, or use an index-organized table with an order by.  The correct answer depends on what exactly you intend to do with the table, why you feel there should be an inherent order.

unknown-7404
I was trying to import a large text file to a table.  The text file has more that 1 million lines.  The table has only 1 column to hold one line from the text file.  I made sure that the CLEAR TABLE is checked before I start the process.  Commit every 100.

Oracle has no 'CLEAR TABLE' command so you must be using some tool or GUI front-end you haven't told us about.

If you commit every 100 you will just slow things down so just issue a commit at the end of the data load.

When I checked the resulting table, I noticed that it reoganized the sequence of lines from the text file.

No - Oracle doesn't 'organize' or 'reorganize' the rows. It just dumps them into a table; there is NO first row or last row. Just like if you throw a bunch of tennis balls into a basket you won't know afterward which one was the first ball you threw in.

How can I import from the text file onto a table without reorganizing the data.  I really need the data on this table to be in the same line sequence as the text file.  I also tried commit every 1 record.

Just use my 'tennis ball' example from above. If you want the balls to have an order you need to write a number on each one as you throw it into the basket. Then later you can find ball #1, #37 or sort the balls in order if you want.

For your use case that means add a second column to the table (e.g. LINE_NO) and use an Oracle sequence to 'number' them.

lov2tango

Now I understand.  Thank you very much!

lov2tango

I did used PL/SQL Developer's Text Importer feature.

unknown-7404
I did used PL/SQL Developer's Text Importer feature.

Thanks for sharing but how is that relevant? Your problem is that you need to create your own ordering since the database doesn't create one for you. What tool you use to import the data doesn't really matter unless that tool won't allow you to create an ordering.

1 - 5
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jan 4 2010
Added on Dec 2 2009
6 comments
936 views