1

I need to display text with line breaks in email. The source database column has datatype varchar2(1000).

However in sql workshop, when i update it using CHR(10), it does not introduce line breaks and the output comes in single line. Even in application/email body, its showing as single line.

update text set text_content='Life' 
||CHR(10)
||CHR(10)
'The very essence';

The output is simply: Life The very essence.

Instead of: Life

The very essence.

How can i introduce line breaks?

Apex version : 20.1

Velocity
  • 433
  • 5
  • 32
  • emails are usually sent in html - it's safer to user ```
    ``` to display line breaks
    – Koen Lostrie Dec 14 '20 at 14:35
  • i need to save the text in db table and fetch from there. So basically in db i need to push it with line breaks. And there neither chr(10), nor
    is working.
    – Velocity Dec 14 '20 at 15:06

1 Answers1

1

SQL Workshop is not a good way to determine the line break is there. It is an invisible character and in SQL Workshop you can't see it. Run the following code

WITH mydata (c)
AS 
(
    SELECT 'Hello'||chr(10)||'world' FROM DUAL
)
SELECT 
  c,
  REPLACE(c,chr(10),'X')
  FROM mydata;

That shows that the line break is there. To make it visible in email, the best way is to replace the chr(10) with a <br> tag since email is usually sent in html. You can also use css classes as explained in this question

Koen Lostrie
  • 14,938
  • 2
  • 13
  • 19
  • If the text in html is directly coming from database column how can we format it using br tag if its dynamic? – Velocity Dec 16 '20 at 04:40
  • I don't know what you mean by "how can we format it using br tag if its dynamic". What is "its" in that sentence ? Have you tried ```REPLACE(text,chr(10),'
    ')```. Please describe exactly what you are trying and what fails
    – Koen Lostrie Dec 16 '20 at 07:53