I’m writing a SQLPlus report in which the recurring header contains an address for a business, followed by several relevant rows regarding that business, followed by the address for the next business:
BOB'S GUITARS
123 SESAME STREET
NEW YORK, NY 10001
customer name last purchase date last purchase amount
------------- ------------------ --------------------
DAVE'S CIGARS
456 MOCKINGBIRD LANE
WASHINGTON, DC 12345
customer name last purchase date last purchase amount
------------- ------------------ --------------------
The problem is this:
Some of those businesses have multi-line addresses, while others do not.
I can handle the basic case with something like
TTITLE CENTER BUSINESSNAME SKIP 1 CENTER ADDR1 SKIP 1 CENTER CITY
(where “CITY” is a variable containing city, state, and zip)
But I’m having a hard time figuring out how to put “add the second address line if ADDR2 is not null” without risking a blank line between ADDR1 and CITY.
In other words, I don’t want
BOB'S GUITARS
123 SESAME STREET
NEW YORK, NY 10001
in order to support
DAVE'S CIGARS
456 MOCKINGBIRD LANE
SUITE 101
WASHINGTON, DC 12345
EDIT / ADDITION:
The suggestion of the combination of nvl and decode was the right first step, but now I’ve run into the problem that the two-line “line” in question exceeds the report’s LINEWIDTH, and therefore gets truncated to LINEWIDTH character. Here’s the code I’m using to generate that line. Remember that both lines must be centered:
SELECT RPAD(' ', (79 - length(trim(address)))/2)
|| trim(address)
|| decode(nvl(trim(address_2), '='), '=', '',
CHR(10)
|| RPAD(' ', (79 - length(trim(address_2)))/2, '-')
|| trim(address_2) || ' ') ADDR1 from business
After consideration of the docs and analysis, it appears that this can’t be done. The (non-technical) solution was to press the business owners to accept a formatting that SQL*Plus could actually generate. They are satisfied with that solution.