Mox
Mox

Reputation: 2463

Oracle DB: custom field delimiter for sql query

Query:

select * from tableA;

result:

column1 column2
------- -------
row1-1  row1-2
row2-1  row2-2
row3-1  row3-1

How can I turn the result above into something below.

column1|column2
------- -------
row1-1 | row1-2
row2-1 | row2-2
row3-1 | row3-1

The assumptions here is that the user will not know what are the columns in the table in advance. This means that using || to do string concatenation on the result set is not preferred.

select column1 ||,|| column2 from tableA <---- This is not what I am looking for.

Note: These tables are already created and I do not have the admin rights to modify the table schema.

Upvotes: 0

Views: 486

Answers (1)

ishando
ishando

Reputation: 316

If you are running your query in sqlplus, you can do

set colsep '|'

before your query and you should get the output as listed, though the header separator line will also have the same column separator -------|-------

This will apply to all subsequent queries

Upvotes: 2

Related Questions