Tuesday, July 10, 2007

SQLPLUS CHR(n) function - generate linefeed

Problem:
========
Want to create sql statement with the format as follows:

UPDATE cf_contact_function_type
SET description = 'DFT30'
WHERE contact_function_type_code = 'DCF'
/


Solution:
=========
Using CHR(10) to provide linefeed character

select
'UPDATE cf_contact_function_type' chr(10)
' SET description = ''' description '''' chr(10)
' WHERE contact_function_type_code = ''' contact_function_type_code
'''' chr(10)
'/'
from cf_contact_function_type;

Example output:


repadmin@GENQB> select
2 'UPDATE cf_contact_function_type' chr(10)
3 ' SET description = ''' description '''' chr(10)
4 ' WHERE contact_function_type_code = '''
contact_function_type_code ''''
5 '/'
6 from cf_contact_function_type;

'UPDATECF_CONTACT_FUNCTION_TYPE'CHR(10)'SETDESCRIPTION='''DESCRIPT
ION''''CHR

------------------------------------------------------------------------
--------------

UPDATE cf_contact_function_type
SET description = 'Accounts Payable'
WHERE contact_function_type_code = 'ATP'
/

UPDATE cf_contact_function_type
SET description = 'After Hours'
WHERE contact_function_type_code = 'AFH'
/

UPDATE cf_contact_function_type
SET description = 'Billing'
WHERE contact_function_type_code = 'BLG'
/

UPDATE cf_contact_function_type
SET description = 'Bookkeeper'
WHERE contact_function_type_code = 'BKE'
/

UPDATE cf_contact_function_type
SET description = 'Controller'
WHERE contact_function_type_code = 'CON'
/

UPDATE cf_contact_function_type
SET description = 'Legal'
WHERE contact_function_type_code = 'LEG'
/

UPDATE cf_contact_function_type
SET description = 'Manager'
WHERE contact_function_type_code = 'MGR'
/

No comments: