PLSQL : || Operator

The string in PL/SQL is actually a sequence of characters with an optional size specification.
The characters could be numeric, letters, blank, special characters or a combination of all.
The || Operator in PLSQL is used to concatenate 2 or more strings together.
The result of concatenating two character strings is another character string.
The result has datatype CHAR and is limited to 2000 characters if both character strings are of datatype CHAR whereas if either string is of datatype VARCHAR2, the result has datatype VARCHAR2 and is limited to 4000 characters.
The CONCAT character function can also be used as an alternative to the vertical bar operator in PLSQL for concatenation of strings.

Syntax:

string1 || string2 [ || string_n ]

Parameters Used:



  1. string1 –
    It is used to specify the first string to concatenate.
  2. string2 –
    It is used to specify the second string to concatenate.
  3. string_n –
    It is used to specify the nth string to concatenate.

Return Type:
The || operator returns a string value.

Supported Versions of Oracle/PLSQL:

  1. Oracle 12c
  2. Oracle 11g
  3. Oracle 10g
  4. Oracle 9i
  5. Oracle 8i

Example-1:

DECLARE 
   Test_String string(10) := 'Hello ';
   Test_String2 string(10) := 'world!';
   
BEGIN 
   dbms_output.put_line((Test_String || Test_String2)); 
   
END; 

Output:

Hello world! 

Example-2:

DECLARE 
   Test_String string(10) := 'Geeks';
   Test_String2 string(10) := 'For';
   Test_String3 string(10) := 'Geeks';
   
BEGIN 
   dbms_output.put_line(Test_String || Test_String2 || Test_String3);   
END; 

Output:

GeeksForGeeks 


My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.