Inbuilt Concat Function in PLSQL
Last Updated :
03 Aug, 2021
Prerequisite : PLSQL BASICS
Introduction :
PLSQL stands for "Procedural Language extensions to SQL" and is used to transform, update and query data in a database. It is grouped into blocks that contain the declaration and statements. And it is integrated with the oracle database (since version 7). And the main idea behind PLSQL is that it adds some programming constraints that are not available in SQL.
1. Concat Function :
Concatenation means joining various strings to form a new string or we can also say that to link something together in the series or in a chain. So in PLSQL, we can use concat() function to join various strings into a single string. So concat() function takes two inputs as a parameter and then it returns the appended string. And we can also use it to concatenate more than two strings and we can see its implementation in the below example.
This function is Supported in Oracle 12c, Oracle 11g, Oracle 10g, Oracle 9i, Oracle 8i.
Example -
INPUT: STR1='PL' , STR2='SQL'
OUTPUT:PL SQL
INPUT: STR1='KASHYAP' , STR2='SINGH'
OUTPUT:KASHYAP SINGH
INPUT: STR1='GEEKS' , STR2='FOR' , STR3='GEEKS'
OUTPUT:GEEKS FOR GEEKS
Syntax -
concat(source1,source2);
Parameter used -
Here source1 is the first string and source2 is the second string.
The above function will return the appended string.
Example 1 -
DECLARE
str1 varchar2(25);
str2 varchar2(25);
res varchar2(25);
BEGIN
str1:='KASHYAP';
str2:='SINGH';
res:=concat(str1,str2);
dbms_output.put_line('FIRST STRING:'||str1);
dbms_output.put_line('SECOND STRING:'||str2);
dbms_output.put_line('RESULT:'||res);
END;
Output -
Example 2 -
DECLARE
str1 varchar2(25);
str2 varchar2(25);
str3 varchar2(25);
res varchar2(25);
BEGIN
str1:='GEEKS';
str2:='FOR';
str3:='GEEKS';
res:=concat(str1,concat(str2,str3);
dbms_output.put_line('FIRST STRING:'||str1);
dbms_output.put_line('SECOND STRING:'||str2);
dbms_output.put_line('THIRD STRING:'||str3);
dbms_output.put_line('RESULT:'||res);
END;
Output 2 -
2. Compose Function :
- In PLSQL the String is actually the sequence of characters with an optional size specification and the character could be a letter, blank, number, special character, or a combination of all. The Compose function basically returns a Unicode string.
- Unicode is a standard for working with a wide range of characters. Each symbol has a code point (a number), and these code points can be encoded (converted to a sequence of bytes) using a variety of encodings.
- UTF-8 is one such encoding. The low code points are encoded using a single byte, and higher code points are encoded as sequences of bytes.
The unistring values that can be combined with other characters in the compose function are:
- unistr(‘\0302’) – circumflex ( ^ )
- unistr(‘\0300’) – grave accent ( ` )
- unistr(‘\0308’) – umlaut ( ¨ )
- unistr(‘\0301’) – acute accent ( ´ )
- unistr(‘\0303’) – tilde ( ~ )
Example -
INPUT-COMPOSE('o' || unistr('\0308') )
OUTPUT-ö
INPUT-COMPOSE('a' || unistr('\0302') )
OUTPUT-â
Syntax -
COMPOSE(STRING)
Parameter Used -
String - It is the input String whose Unicode string needs to be generated.
The above Function will return the Unicode String.
Example 1 -
DECLARE
Var1 char:='g';
Var2 char:='f';
Var3 char:='s';
BEGIN
dbms_output.put_line(COMPOSE(Var1 || unistr('\0308' )));
dbms_output.put_line(COMPOSE(Var2 || unistr('\0301' )));
dbms_output.put_line(COMPOSE(Var3 || unistr('\0303' )));
END;
Output -
Example 2 -
DECLARE
Var1 char:='g';
BEGIN
dbms_output.put_line(COMPOSE(Var1 || unistr('\0301' )));
dbms_output.put_line(COMPOSE(Var1 || unistr('\0302' )));
dbms_output.put_line(COMPOSE(Var1 || unistr('\0303' )));
END;
Output -
Similar Reads
PLSQL | CONCAT Function
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 CONCAT function allows you to concatenate two strings together. To CONCAT more than two values, we can nest
1 min read
CONCAT() function in MySQL
CONCAT() function in MySQL is used to concatenating the given arguments. It may have one or more arguments. If all arguments are nonbinary strings, the result is a nonbinary string. If the arguments include any binary strings, the result is a binary string. If a numeric argument is given then it is
2 min read
CONCAT_WS() Function in MySQL
CONCAT_WS() : This function in MySQL helps in joining two or more strings along with a separator. The separator must be specified by the user and it can also be a string. If the separator is NULL, then the result will also be NULL. Syntax : CONCAT_WS(separator, string1, string2, ...) Parameters : se
2 min read
CONCAT_WS() Function in SQL Server
CONCAT_WS() : This function concatenates two or more strings together with a separator. Syntax : CONCAT_WS(separator, input_string1, input_string2, [...input_stringN]); Parameter : This method accepts two-parameters as mentioned above and described below as follows. separator - It is an expression o
1 min read
MySQL | Group_CONCAT() Function
The GROUP_CONCAT() function in MySQL is an aggregation function that combines data from multiple rows into a single string. It is particularly useful for aggregating summaries, such as combining related information into a single field for better readability or reporting. In this article, we will exp
4 min read
PLSQL | CONVERT Function
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 CONVERT function in PLSQL is used to convert a string from one character set to another. Generally, the dest
2 min read
PLSQL | INITCAP Function
The INITCAP function in PLSQl is used for setting the first character in each word to uppercase and the rest to lowercase. Words are delimited by white space or characters that are not alphanumeric. The INITCAP function in PLSQL can accept char can of any of the datatypes such as CHAR, VARCHAR2, NCH
1 min read
PLSQL | INSTR Function
The PLSQL INSTR function is used for returning the location of a substring in a string. The PLSQL INSTR function searches a string for a substring specified by the user using characters and returns the position in the string that is the first character of a specified occurrence of the substring. The
2 min read
PLSQL | INSTRC Function
The PLSQL INSTRC function is used for returning the location of a substring in a string, Unicode complete characters. The PLSQL INSTRC function searches a string for a substring specified by the user using characters and returns the position in the string that is the first character of a specified o
2 min read
PLSQL | INSTRB Function
The PLSQL INSTRB function is used for returning the location of a substring in a string, using bytes instead of characters. The PLSQL INSTRB function searches a string for a substring specified by the user using characters and returns the position in the string that is the first character of a speci
2 min read