Skip to content
Advertisement

Select list as column in Oracle SQL

I would like to append a few rows to an already existing table (15 rows to be precise). What is the quickest way to do this?

This works, but it seems redundant.

I was wondering if there’s a solution along the lines of:

Please note that I want to preserve the leading zeros for each element in my list. This post is almost what I’m looking for, but it converts each element to integers and drops the leading zeros.

Advertisement

Answer

You can use a system-provided collection type; you select from it using the TABLE operator (even that is no longer necessary since Oracle 12, as I demonstrate below). Note that the column name is COLUMN_NAME – that is the name Oracle chose when they created the system-provided type.

Let’s create a small table for testing:

Then, here is how you can do what you wanted:

Do a Google search for SYS.ODCIVARCHAR2LIST (and similar SYS.ODCINUMBERLIST) if you are not familiar with it; it’s quite useful.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement