SandPiper
SandPiper

Reputation: 2906

How do I set LINESIZE and PAGESIZE with a substitution variable?

I am trying to use a PL/SQL script in SQL*Plus to set the linesize and pagesize based on a developer input on whether a report should print in landscape or portrait orientation. If it is landscape, I want linesize 132 and pagesize 60. If it is portrait, I want 88 and 80 respectively.

I am trying to use substitution variables to do so like this:

DEFINE PRINT_ORIENTATION 'PORTRAIT'

COLUMN LINESIZE_VALUE NOPRINT new_value LINE
COLUMN PAGESIZE_VALUE NOPRINT new_value PAGE

SELECT DECODE('&PRINT_ORIENTATION', 'PORTRAIT', 88, 'LANDSCAPE', 132) AS LINE,
       DECODE('&PRINT_ORIENTATION', 'PORTRAIT', 80, 'LANDSCAPE', 60) AS PAGE
FROM DUAL
/

SET LINESIZE &LINE
SET PAGESIZE &PAGE

However, the system then just prompts me to manually enter values for line and page. What do I need to do to use a substitution variable in the SET command?

Upvotes: 1

Views: 7190

Answers (2)

J. Chomel
J. Chomel

Reputation: 8395

With a "shell" substitution variable: What we do here to handle a similar issue, is we generate the correct sizing settings in a temporary sql file.

Not sure it'll help, but here's a hint on how to set the number of columns from the size of your terminal, with this in @$HOME/sqlmlogin.sql:

def_editor=emacs
set null °
set arraysize 1
set pagesize 0
set serveroutput on
host > $HOME/sqltmp_size.sql ; tty -s && ( eval $( resize ) ; echo "set lines $COLUMNS\n set pages 0" >> $HOME/sql/tmp_size.sql )
-- then call the temp script
@$HOME/sqltmp_size.sql
-- remove afterwards
host rm -f $HOME/sqltmp_size.sql

And call sqlplus like this:

sqlplus / @$HOME/sqlmlogin.sql

So you can also generate the static values you want for your users from a script like that.

Upvotes: 0

Alex Poole
Alex Poole

Reputation: 191425

With the column .. new_value ... syntax:

COLUMN Q_LINE NEW_VALUE LINE
COLUMN Q_PAGE NEW_VALUE PAGE

SELECT DECODE('&PRINT_ORIENTATION', 'PORTRAIT', 88, 'LANDSCAPE', 132) AS Q_LINE,
       DECODE('&PRINT_ORIENTATION', 'PORTRAIT', 80, 'LANDSCAPE', 60) AS Q_PAGE
FROM DUAL
/

SET LINESIZE &LINE
SET PAGESIZE &PAGE

That allows you to define a substitution value from a query result.

Upvotes: 2

Related Questions