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
SQL Interview Questions Are you preparing for a SQL interview? SQL is a standard database language used for accessing and manipulating data in databases. It stands for Structured Query Language and was developed by IBM in the 1970's, SQL allows us to create, read, update, and delete data with simple yet effective commands.
15+ min read
SQL Tutorial SQL is a Structured query language used to access and manipulate data in databases. SQL stands for Structured Query Language. We can create, update, delete, and retrieve data in databases like MySQL, Oracle, PostgreSQL, etc. Overall, SQL is a query language that communicates with databases.In this S
11 min read
SQL Commands | DDL, DQL, DML, DCL and TCL Commands SQL commands are crucial for managing databases effectively. These commands are divided into categories such as Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), Data Query Language (DQL), and Transaction Control Language (TCL). In this article, we will e
7 min read
Introduction of ER Model The Entity-Relationship Model (ER Model) is a conceptual model for designing a databases. This model represents the logical structure of a database, including entities, their attributes and relationships between them. Entity: An objects that is stored as data such as Student, Course or Company.Attri
10 min read
DBMS Tutorial â Learn Database Management System Database Management System (DBMS) is a software used to manage data from a database. A database is a structured collection of data that is stored in an electronic device. The data can be text, video, image or any other format.A relational database stores data in the form of tables and a NoSQL databa
7 min read
SQL Joins (Inner, Left, Right and Full Join) SQL joins are fundamental tools for combining data from multiple tables in relational databases. Joins allow efficient data retrieval, which is essential for generating meaningful observations and solving complex business queries. Understanding SQL join types, such as INNER JOIN, LEFT JOIN, RIGHT JO
6 min read
Normal Forms in DBMS In the world of database management, Normal Forms are important for ensuring that data is structured logically, reducing redundancy, and maintaining data integrity. When working with databases, especially relational databases, it is critical to follow normalization techniques that help to eliminate
7 min read
ACID Properties in DBMS In the world of DBMS, transactions are fundamental operations that allow us to modify and retrieve data. However, to ensure the integrity of a database, it is important that these transactions are executed in a way that maintains consistency, correctness, and reliability. This is where the ACID prop
8 min read
Introduction of DBMS (Database Management System) A Database Management System (DBMS) is a software solution designed to efficiently manage, organize, and retrieve data in a structured manner. It serves as a critical component in modern computing, enabling organizations to store, manipulate, and secure their data effectively. From small application
8 min read
SQL Query Interview Questions SQL or Structured Query Language, is the standard language for managing and manipulating relational databases such as MySQL, Oracle, and PostgreSQL. It serves as a powerful tool for efficiently handling data whether retrieving specific data points, performing complex analysis, or modifying database
15 min read