1

My code currently that I am running in the Command Window in PL/SQL Developer:

SET MARKUP CSV ON DELIMITER | QUOTE OFF
SET FEEDBACK OFF

SPOOL C:\Users\Desktop\SpoolTest.csv

select *
from Vendor_data t 
where rownum < 20
;

SPOOL OFF;

My output:

222339           |067   |001 

306811           |045   |001 

024253           |067   |001             

I need to remove the trailing spaces:

222339|067|001 

306811|045|001
 
024253|067|001                                  

I am getting Cannot SET MARKUP. I have to run my spooling in a command window in PL/SQL Developer. Is there a way to do this? This is a snippet of code which is actually quite long.

Littlefoot
  • 131,892
  • 15
  • 35
  • 57
J. Colborn
  • 11
  • 1
  • 4

2 Answers2

1

The PL/SQL Developer's command-line tool is a different product than Oracle SQL*Plus command-line utility, and it has a different set of supported commands. PL/SQL Developer's command line mimics a real SQL*Plus functionality but does it only partially. For example, it doesn't support the SET MARKUP CSV command. You can find the full list of supported commands in the PL/SQL Developer's Manual (Help -> User's Guide).

In your case, trailing spaces appear because you are printing headers of columns. Apparently, PL/SQL Developer tries to align rows by the maximum length of the column:

spool file.txt

select ao.object_name, ao.object_id, ao.created, ao.status
  from all_objects ao
 where rownum <= 3;

OBJECT_NAME                                                                       OBJECT_ID CREATED     STATUS
-------------------------------------------------------------------------------- ---------- ----------- -------
TS$                                                                                      16 26.01.2017  VALID
ICOL$                                                                                    20 26.01.2017  VALID

Keeping in mind that PL/SQL Developer's supports of SET commands is very limited, we can achieve the CSV like spooling by simply not printing headers and setting colwidth to 1:

spool file.txt

set colsep |
set heading off
set colwidth 1

select ao.object_name, ao.object_id, ao.created, ao.status
  from all_objects ao
 where rownum <= 3;

spool off

it saves this to the spool file:

TS$|16|26.01.2017 13:52:45|VALID
ICOL$|20|26.01.2017 13:52:45|VALID
C_FILE#_BLOCK#|8|26.01.2017 13:52:45|VALID

If you must print the headers, you can add an additional select from dual before the main sql just to print headers.

Dmitry.M
  • 2,833
  • 1
  • 17
  • 30
0

SET commands belong to Oracle's command line tool, SQL*Plus.

I don't use PL/SQL Developer (and quick Google doesn't return anything useful), so - does PL/SQL Developer support SET commands at all? If not, you're out of luck, but you could install Oracle Client (if you already don't have it) and run your script directly in SQL*Plus.

On the other hand & unless I'm wrong, SET MARKUP CSV is valid for Oracle 18c and above; in lower versions, it is SET MARKUP HTML you can use (i.e. no CSV option).

Littlefoot
  • 131,892
  • 15
  • 35
  • 57