devxlogo

Filling a Field with Data

Filling a Field with Data

Question:
How can I fill a numeric field with a sequence of numbers using SQL?

For example, I want a field named NUMBER to contain the numbers 1 for the first row, 3 for the second row, 5 for the third row, etc.

Answer:
There are several ways to approach this. The easiest would be to make the field a serial field type. Then you’d just do an “INSERT into table_name (fieldname) values (0)”. The value inserted will be the next one in the sequence.

You could also enable ROWIDS and do some type of manipulation on that value. It depends on what you mean by first row. None of the methods will actually set the physical position of the row in the database, but that’s academic. You could do a SELECT/ORDER BY on the numeric field to bring the data back in the order you wish.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist