Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform string concatenation in PL/SQL?

I have a variable defined as

define dbs '&1'

Suppose I pass database1 as an argument. Then the statement is interpreted as

define dbs database1

I want to append single quotes around the string, ie I want it to be interpreted as

define dbs 'database1'

How should I do this?

like image 560
Moeb Avatar asked Oct 20 '10 04:10

Moeb


People also ask

How do you concatenate in PL SQL?

The CONCAT function allows you to concatenate two strings together. To CONCAT more than two values, we can nest multiple CONCAT function calls. Parameters Used: string1: It is used to specify the first string to concatenate.

How do you concatenate 2 strings?

Concatenation is the process of appending one string to the end of another string. You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs.

What is the use of || in Oracle?

The Oracle/PLSQL || operator allows you to concatenate 2 or more strings together.


1 Answers

Single quotes in strings need to be escaped with another single quote, so you would write (if I understand macro expansion correctly)

 '''&1'''

String concatenation is done with the || operator

 '''' || '&1' || ''''
like image 142
Thilo Avatar answered Oct 18 '22 08:10

Thilo