How to concat two column with '-' seperator in PL/SQL
Asked Answered
P

6

9

I just want to concat two columns with seperator '-'.

These are the two columns, want to concat.

enter image description here

I am using this query to concat them

select concat(amt,endamt)as amount from mstcatrule

and it is giving me result this

enter image description here

But I Want that data of 2 columns should be sepearted by '-'

RESULT I WANT IS :

AMOUNT
0-0
100-99999999999
100-500
Pragmatics answered 28/11, 2012 at 8:22 Comment(0)
V
19

Do it with two concats:

select concat(concat(amt, '-'), endamt) as amount from mstcatrule;

concat(amt,'-') concatenates the amt with the dash and the resulting string is concatenated with endamt.

Valladares answered 28/11, 2012 at 8:27 Comment(0)
V
28

Alternative:

select amt || '-' || endamt as amount from mstcatrule;
Villeneuve answered 28/11, 2012 at 9:45 Comment(1)
Can I use an underscore as delimiter? Doesn't seem to work for me.Pinup
V
19

Do it with two concats:

select concat(concat(amt, '-'), endamt) as amount from mstcatrule;

concat(amt,'-') concatenates the amt with the dash and the resulting string is concatenated with endamt.

Valladares answered 28/11, 2012 at 8:27 Comment(0)
S
1

In oracle this works for me! :D

select amt||'-'||endamt as amount from mstcatrule
Selfevident answered 2/2, 2023 at 18:47 Comment(0)
B
0

Another way is to use double pipe.

select amt || '-' || endamt as amount from mstcatrule;

You may have to convert amt and endamt to varchar

Blueberry answered 9/10, 2015 at 20:8 Comment(0)
E
-1

Alternative you can use under query

select concat(amt,'-',endamt) as amount from mstcatrule;
Eggcup answered 16/10, 2016 at 5:30 Comment(2)
You can use ||'-'|| between two coloumn.Eggcup
docs.oracle.com/cd/B28359_01/server.111/b28286/…Eggcup
A
-2

A generic format for the query

Select concat(column1,'-',column2) as concatedCols from table_Name

For Postgresql only

Arturoartus answered 19/3, 2020 at 7:50 Comment(1)
How is this Answer different from the answer by Md. Nasir Uddin? Since the Question is tagged pl/sql I'm assuming this should run on an Oracle database, but the Oracle documentation does not allow for 3 parameters to CONCAT, and trying this result in the error: ORA-00909: invalid number of argumentsGuildhall

© 2022 - 2024 — McMap. All rights reserved.