Search code examples
sqlconcatenationapostrophe

concat apostrophe to oracle sql query


Hi all I am looking for some pointers on how I can add an apostrophe to my query results on my first column.

My current query:

set verify off
set colsep "',"
set pagesize 2000
ALTER SESSION SET NLS_DATE_FORMAT='DD-MON-YY-HH24:MI:SS';
spool /home/user/out.txt

select '[' || table1.collectdatetime as "['Date-Time",table1.cycletime as "'Time'" from table1 where interfacename='somename' and collectdatetime > (CURRENT_DATE - 1)
order by collectdatetime ASC;

Which results:

['Date-Time        ','InCycleTime'
-------------------',-------------
[02-MAR-13-17:56:16',           29

What I am struglling with is getting the results to return and add an apostrophe after the [

['Date-Time        ','InCycleTime'
-------------------',-------------
['02-MAR-13-17:56:16',           29

This is for an oracle 11.1.0.7 build. The data is being queried and parsed but I need to get that apostrophe issue worked out.


Solution

  • use this:

    select '[''' || table1.collectdatetime as "['Date-Time",table1.cycletime as "'Time'" from table1 where interfacename='somename' and collectdatetime > (CURRENT_DATE - 1)
    order by collectdatetime ASC;