I use Unify SQL. I want to create an ascii delimited file with the results of my SQL. I want to hardcode a value...
in every record that is produced; for example, a value of "OFFENDER". The word offender is not in the database nor is there a field. Sample output:
"OFFENDER", "JOHN", "SMITH", "311 Elm" "OFFENDER", "BOB", "JOHNSON", "1 Main" "OFFENDER", "STAN", "WHITE", "2 Apple"
How can I do this? A statement like SELECT "OFFENDER", last, first, address from ... doesn't work.
I don't know the Unify product, but if
select "OFFENDER", last, first, etcetera
doesn't work, I would try single quotes --
select 'OFFENDER', last, first, etcetera
and if that doesn't work, I would definitely reach for my Unify documentation.
Uh oh, wait a second. I just realized what you were talking about. Maybe you meant that the output doesn't have the quotes and commas that you need for your "ascii delimited file."
Okay, assuming you can use single quotes for the literals, you would have to insert the double quotes yourself, so that they appear in the result. Also, you would probably want to generate one single output column consisting of all the fields you want all concatenated together. This is not really difficult, just messy-looking. Might as well strip the blanks too, if they are fixed-length columns.
select '"OFFENDER","' || trim(last) || '","' || trim(first) || '","' || trim(etcetera) || '"'
The literals are enclosed in single quotes, and they consist of a double quote, comma, double quote (except for the last one). Everything is concatenated into one column, containing the necessary embedded double quotes and commas that you want.
Dig Deeper on Oracle and SQL
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.