Connecting Tech Pros Worldwide Forums | Help | Site Map

newb question about sql+ script for appending to end of table

Newbie
 
Join Date: Jul 2009
Posts: 8
#1: Jul 9 '09
Is there a statement that will allow appending to the end of table when inserting new data? I use multiple "insert into table1(timestamp1,area1,value1,value2...)" to insert different area data with the same timestamp into the same table. When I look at the data in the table sometimes the rows are placed randomly into the table. When I queue a php script to display the data for a particular day the order changes because the order in the table changes. I know there are ways to correct this when pulling the data from the oracle table but I am no PHP expert. This code was written by someone else and for me to change it may cause more harm than good. I can add a column and a qualifier (areanumber) to order them that way in the php file but thought if there was a way to add the data to the bottom which would keep them in the same order, I hope, or even some way of keeping the inserted rows order the same it would solve my issue. I hope this is clear enough. Thanks for your help.

amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#2: Jul 9 '09

re: newb question about sql+ script for appending to end of table


You can use ORDER BY ROWID to order the data in ascending order in which the data is inserted in the table.
Newbie
 
Join Date: Jul 2009
Posts: 8
#3: Jul 10 '09

re: newb question about sql+ script for appending to end of table


Quote:

Originally Posted by amitpatel66 View Post

You can use ORDER BY ROWID to order the data in ascending order in which the data is inserted in the table.

It appears as though it is the ROWID that is out of order. I looked at the ROWIDs and for some reason the first insert statement is getting an ID that is not in order with the rest. Sometimes the ID is an earlier one sometimes it is a later one. Here is the script I am using, shortened for display:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO "TABLE1" (DATE1, SHOPS, KILN_DAY, DAY_OF_YEAR)
  2. VALUES (LOCAL.DATE1, 'COAL',"HISTORIAN DATA",LOCAL.DAYOFTHEYEAR);
  3.  
  4. INSERT INTO "TABLE1" (DATE1, SHOPS, KILN_DAY, DAY_OF_YEAR)
  5. VALUES (LOCAL.DATE1, 'COAL BTU',"HISTORIAN DATA",LOCAL.DAYOFTHEYEAR);
  6.  
  7. INSERT INTO "TABLE1" (DATE1, SHOPS, KILN_DAY, DAY_OF_YEAR)
  8. VALUES (LOCAL.DATE1, 'COAL BTU/TON',"HISTORIAN DATA",LOCAL.DAYOFTHEYEAR);
  9.  
This code is written in SQL+ but it is a version used by the historian "Aspen IP21" not Oracle. We were unable to get the link set up so I am pushing the data to Oracle rather than pulling it. The Historian data is a select statment to pull unique data for that shop. Hope this sheds more light on my issue.

Thanks again for the help.
Newbie
 
Join Date: Dec 2008
Posts: 9
#4: Jul 11 '09

re: newb question about sql+ script for appending to end of table


according to my search results ,

if the SELECT statement does not have a specific ORDER BY , then there's no way you can determine exactly in which order data will come .


try it yourself on any table and select from that table once witout an order by , and else with order by rowid , and you will see yourslelf ..

the best way is to add an order by in the program you are using

you can at least order by ROWID
Newbie
 
Join Date: Jul 2009
Posts: 8
#5: Jul 13 '09

re: newb question about sql+ script for appending to end of table


I just added a column to all the tables that I placed an numeric value and ordered by that column. ROWID didn't work because the order created is not the same as when you order by ROWID. The ID created uses + ,\ , "A", "a", and #'s 0-9 in the ID that order. When you order by ROWID ASC the + is at the top then the \, followed by 0 through 9, then "A" and lastly "a". If the ROWID of the values crosses from letters to numbers the order will be wrong.
amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#6: Jul 13 '09

re: newb question about sql+ script for appending to end of table


Are you looking at orderding the data based on the ASCII value of each rows data for a particular column?..When you use ROWID, it will order the records based on when the record is inserted in the table. in ASC order, records inserted latest will be listed at last.
Newbie
 
Join Date: Jul 2009
Posts: 8
#7: Jul 13 '09

re: newb question about sql+ script for appending to end of table


I am trying to order by inserted in the table. ROWID ASC(ascending order) doesn't match when it was inserted. I tested with inserting 9 rows at one timestamp 10 times and when sorted by ROWID ASC(ascending order) the timestamp rows don't always allign. I don't understand why exactly. It maybe the ASPEN IP21 version of SQL+.

I did fix my issue another way though.
Newbie
 
Join Date: Jul 2009
Posts: 8
#8: Jul 13 '09

re: newb question about sql+ script for appending to end of table


Thanks for all the help.
amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#9: Jul 14 '09

re: newb question about sql+ script for appending to end of table


Good to hear that your issue is resolved. It would be great if you can post the solution of how did you solve your problem so that in case any other user faces similar issue they can refer to this thread for help.
Newbie
 
Join Date: Jul 2009
Posts: 8
#10: Jul 14 '09

re: newb question about sql+ script for appending to end of table


To fix my issue I added another column called "order1" to all the oracle tables I am using. When the data was pushed into oracle I also pushed the order I wanted displayed on the PHP page into the column "order1". In the script for PHP I used order by "order1" asc. Which ordered the data correctly. Thanks again for the help.
Reply