By Making the String Multiline

We can insert newline character directly into the string by pressing enter. The string which is broken down into two lines works fine and works as a string with newline character. See the following example.

Query:

INSERT INTO zoo VALUES (5, 'Kol', 'Peacock', 'A blue one.
With beautiful feathers.');
SELECT * FROM zoo;

Output:

Output

Explanation: As we can see the multiline string is allowed in PL/SQL. We can insert as many lines as we want without any problems.

How to insert a line break in a String PL/SQL

In PL/SQL, inserting line breaks into VARCHAR or NVARCHAR strings can be a good way to enhance the readability and presentation of our data. Whether we are formatting output for display or preparing text for storage, knowing how to insert line breaks is a helpful skill. In this guide, we’ll explore the various techniques and examples for inserting line breaks in PL/SQL VARCHAR/NVARCHAR strings.

Similar Reads

How to Insert a Line Break in a PL/SQL?

Inserting a line break in a PL/SQL statement can make our output more readable and organized. Below is the method which is used to insert a line break in a PL/SQL VARCHAR/NVARCHAR string as given below:...

1. By Making the String Multiline

We can insert newline character directly into the string by pressing enter. The string which is broken down into two lines works fine and works as a string with newline character. See the following example....

2. Use CHR(10)

We can insert newline into string using its ASCII value (i.e. 10). we can read about the CHR function here. Basically it forms the character from the given number. Let’s insert newline into our string using this. Here we will use the concatenation operator `||` to concatenate strings. See the following example....

Choosing CHR(10) Over String Multiline

Although the output of the Method 2 and 1 looks like the same, there is a slight difference in the results. Before understanding this let’s verify the claim. See the following example....

Conclusion

Overall in PLSQL we have learnt about how to insert a newline character into table. We cannot use the famous `\n` character to put newlines into strings in PLSQL. Instead, we need to use other methods to insert newlines into strings. The first is to use multiline strings and simple press enter to insert newline. The second being the use of CHR function and the concatenation operator to inject the character wherever we want. Although these two methods put similar output but there is a subtle difference in the results, the first method puts an extra space character before each newline....