Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I print output in new line in PL/SQL?

Tags:

sql

oracle

plsql

How do I print a new line in PL/SQL? I'm after something similar to '\n' in the C language.

Example:

begin      dbms_output.put_line('Hi, good morning friends');  end; 

I need the output is like this:

hi, good  morning friends 
like image 334
user1252398 Avatar asked Jul 04 '12 13:07

user1252398


People also ask

How do you add a new line character in PL SQL?

There is a function chr() that will take the ascii code and return the character. So, if you: myString := 'Some Text' || chr(10) || 'Some more Text....'; that'll build a string that has a newline (line feed) in it.

How do I print a new line character in Oracle?

Chr(Number) should work for you. Remember different platforms expect different new line characters: CHR(10) => LF, line feed (unix) CHR(13) => CR, carriage return (windows, together with LF)

How do you display output in PL SQL?

In the DBMS Output window, choose the "plus" icon and select the connection that you want to write data to the DBMS Output window. Then run the PL/SQL block in the SQL Worksheet window using the right arrow (Ctrl+Enter in Windows). You'll see the output appear in the DBMS Output window.


1 Answers

You can concatenate the CR and LF:

chr(13)||chr(10) 

(on windows)

or just:

chr(10) 

(otherwise)

dbms_output.put_line('Hi,'||chr(13)||chr(10) ||'good' || chr(13)||chr(10)|| 'morning' ||chr(13)||chr(10) || 'friends'); 
like image 154
A.B.Cade Avatar answered Sep 23 '22 13:09

A.B.Cade