Concatenation of strings in PL/SQL

Prerequisite PL/SQL Introduction

In PL/SQL code groups of commands are arranged within a block. A block group related declarations or statements. In declare part, we declare variables and between begin and end part, we perform the operations.

Given two strings and the task is to concatenate them and store it in another string.

Examples:

Input: str1 = ' RAMESH', str2 = 'SURESH'
Output: RAMESH SURESH

Input: str1 = ' Ramesh is a good boy', str3 = 'and',
       str2 = 'Suresh is a brilliant student'.
Output: Ramesh is a good boy and Suresh is a brilliant student

Approach is to use the concatenation operator i.e. || .

Below is the required implementation:

filter_none

edit
close

play_arrow

link
brightness_4
code

DECLARE
    --Here variables are str, str1, str2 and v
    str  VARCHAR2(40) := 'Ramesh is a good boy';
    str1 VARCHAR2(40) := 'Suresh is a brilliant student';
    str2 VARCHAR2(40) := 'and';
    v    VARCHAR2(100);
BEGIN
    v := str
         ||' '
         || str2
         ||' '
         ||str1;
  
    dbms_output.Put_line(v);
END;
-- Program End  

chevron_right


Output:

Ramesh is a good boy and Suresh is a brilliant student


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.