Today I noticed something interesting about the quote operator.
Here I'm running this code via SQL*Plus on a 12.1 database running on my Windows 10 laptop.
newline_CRLF.sql
set serveroutput on
declare
l_str1 varchar2(100 char);
l_str2 varchar2(100 char);
begin
l_str1 := q'{This is a
two lines string}';
l_str2 := 'This is a'||chr(13)||chr(10)||'two lines string';
dbms_output.put_line('STR1: length='||length(l_str1)||', lengthb='||lengthb(l_str1));
dbms_output.put_line('STR1: length='||length(l_str2)||', lengthb='||lengthb(l_str2));
end;
/
This code is in a file where the line terminator is CRLF as defaults in Windows.
SQL> @newline_CRLF
STR1: length=26, lengthb=26
STR1: length=27, lengthb=27
Procedura PL/SQL completata correttamente.
What I noticed here, is the line breake within the quote operator q'{}'
is parsed as a Unix-style line feed.
I converted the script to use Unix-style line breakes using Notepad++ EOL Conversion utility, and on the next run I got the same result.
This DOES absolutely MAKE SENSE because it guarantees any code base is treated the same way, being the PL/SQL language EOL agnostic: if it weren't like that, it would have been possible run into bugs.
This behaviour fits perfectly on Unix-like systems, but on Windows can be a little annoying and require to explicitly use string concatenation.
This is not an actual problem, it is just out of my curiosity to ask:
"Do anybody know whether this is a just take it situation or there is the possibility to set up a parameter to change the way it behaves?"
Considering I'm getting a LF on a Windows platform and I've found nothing on MOS so far, I hardly think it's possible, but you never know...