We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Oracle table insert new row question

toooki
toooki asked
on
Medium Priority
378 Views
Last Modified: 2012-05-11
I created an oracle (11gR2) table TAB1
with this command:
CREATE TABLE LCTB_REPORT_SRVC
   (      ID NUMBER,
      F1 VARCHAR2(20)
   );

Now I insert into this table:
(1, 'myval1')
(2, 'myval2')
...
...
and so on

Later if type select * from TAB1
The o/p does not show with id value ascending.

Is there any way that the select * from TAB1  will always show the o/p in id values ascending?
Comment
Watch Question

Commented:
select * from TAB1 order by id
Top Expert 2011

Commented:
hi
- your table is TAB1 or LCTB_REPORT_SRVC?

select * from TAB1 order by id ASC
OR
select * from LCTB_REPORT_SRVC order by id ASC
Top Expert 2011

Commented:
- 'ASC' is ascending order

Author

Commented:
Thank you all for your replies.

My table is MYTAB1. Sorry.

I know select * from TAB1 order by id will give the O/P I want to see.

I inserted the values in order (I mean first inserted the row with id =1, then id=2 ...).

I was thinking if there was any way for it to show in correct id ascending order without the "order by id" clause in the select statement.
Top Expert 2011

Commented:
- can you further explain on the "correct id ascending order?" is it based on the sequence when you insert the data?

Author

Commented:
No. I did not use sequence.
Just inserted the number values for ID column. As it is anyway a small table.

By correct order means .. just it looks awkward if select * and see the IDs not in order (when I inserted in order).
I know tables don't store records in order.

Otherwise, well maybe then there is no other way...
Top Expert 2011
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
CERTIFIED EXPERT
Most Valuable Expert 2012
Distinguished Expert 2019
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
according to u ur table is TAB1   and u  create table name of    CREATE TABLE LCTB_REPORT_SRVC
.... than u


 fetech a data from TAB1....
 thst is ur ist mistake ....


and ur 2 mistake is  U create a table table name TAB1 thst is reserve word in oracle 11g....
awking00Information Technology Specialist
CERTIFIED EXPERT

Commented:
Since when did TAB1 become a reserved word?
Top Expert 2011

Commented:
- i'm wondering the same too.
- BTW toooki already corrected that his table name is MYTAB1 if you read the whole posting here :)

Author

Commented:
Thank you all.
I see some post there http://tkyte.blogspot.com/2005/08/order-in-court.html as slightwv mentioned.
Well it is not a huge issue for me. I asked just to see if there was an easy way for it.
Thanks!
 
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.