Search code examples
oraclesqlplussql-loader

SQLPlus DBMS output not the same as in developer


I'm writing a script that will generate SQLLoader file based on table name. So far, I've managed to do so, but when I run the sql script in SQLPlus I'm not getting the same output as in developer. To be precise, there are new lines inserted when they're not invoked. What am I doing wrong?

Following code is just the beginning without rest of the code. When columns are included I get really messy output with multiple newlines here and there.

Note: I need it to run through SQLPlus as I intend to incorporate the code in Shell script.

SET SERVEROUTPUT ON
DECLARE
    lv_ctl VARCHAR2(32767);
    lv_tableName VARCHAR2(10) := 'MyTable';
BEGIN
    lv_ctl :=  'OPTIONS(SKIP=1)' || CHR(10)
            || 'LOAD DATA' || CHR(10)
            || 'APPEND' || CHR(10)
            || 'INTO TABLE ' || lv_tableName || CHR(10)
            || 'FIELDS TERMINATED BY ","' || CHR(10)
            || 'TRAILING NULLCOLS' || CHR(10)
            || '(' || CHR(10)
            ;   
    
    dbms_output.put_line(lv_ctl);
END;
/
SET SERVEROUTPUT OFF

When run through developer I get (which is the output I want):

OPTIONS(SKIP=1)
LOAD DATA
APPEND
INTO TABLE MyTable
FIELDS TERMINATED BY ","
TRAILING NULLCOLS
(

When run through SQLPlus:

OPTIONS(SKIP=1)
LOAD DATA
APPEND
INTO TABLE MyTable
FIELDS TERMINATED BY
","
TRAILING NULLCOLS
(

The problem is I get new lines randomly, can't find the reason behind it. As you see fifth line (FIELDS TERMINATED BY ",") is not inline.


Solution

  • Make sure SQLPlus isn't wrapping the output. Try "SET LINESIZE 100" before running your script.