how to concatenate more than two columns in plsql developer? [duplicate] - sql

This question already has answers here:
Oracle SQL, concatenate multiple columns + add text
(6 answers)
Closed 7 years ago.
when I run the below query
select concat(column1,column2,column3) as concatcolumn from table
I get an error "ORA-00909:INVALID NUMBER OF ARGUMENTS"

Concat only takes two arguments.
See: http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions026.htm
Use the concatenation operator:
select column1 || column2 || column3 ...

select ([column1]+','+[column2]+','+[column3]) as concatcolumn from table
Try above the query.it may changes on different type of column data type.

Related

SQL Select AS not being recognized as column [duplicate]

This question already has answers here:
Referring to a Column Alias in a WHERE Clause
(9 answers)
Closed 1 year ago.
I am using a simple select statement and creating a column using a CONCAT function and labeling the column as Filter.
Why is the new column not being recognized?
Error message states
Invalid Column Name - Filter
You can't refer to column aliases in the where clause as the where is processed before the alias is materialised.
There are several workarounds, and assuming SQL Server you can do
select *
from table t
cross apply (values(concat(columna,columnb)))c([filter])
where [filter]='something'
Also note that the performance won't be great on large data sets since this criteria is non-sargable

How can I search a string in more than ten columns in SQL [duplicate]

This question already has answers here:
Checking if a string is found in one of multiple columns in mySQL
(6 answers)
Closed 1 year ago.
I want search a string in all 10 columns in a SQL table. How can I do it in SQL?
For example :
I have to search “Computer” word in all ten columns or all the columns in a single table .
You should use "OR" operator.
For Example:
SELECT * FROM Table
WHERE (col1 LIKE '%searchstring%') OR (col2 LIKE '%searchstring%') OR (col3 LIKE '%searchstring%')

How to Combine multiple column in a table and create separate Column in SQL [duplicate]

This question already has answers here:
CONCAT_WS() for SQL Server
(6 answers)
Simulating group_concat MySQL function in Microsoft SQL Server 2005?
(12 answers)
Closed 4 years ago.
How to Combine multiple column in a table and create separate Column in SQL and insert a single pipe '|' between the data even though some column has empty field.
I have tried using concat but got multiple pipe if there is empty field
select top 4 concat(code2_1,'|',code2_2,'|',Code2_3,'|',code2_4) from
Sourcesql
enter image description here
above is a table
for example 4 th row i need PT01|PT02|PT04
I didnt get the answer even i find like below query then how can my above query is duplicate
SELECT
STUFF(
COALESCE('|' + code2_1, '') +COALESCE('|' +code2_2, '') +COALESCE('|'+
code2_3, '') +COALESCE('|'+ code2_4, ''),
1, 0, '') AS bar
FROM Sourcesql

Selecting rows with specific values in a column [duplicate]

This question already has answers here:
Select from any of multiple values from a Postgres field
(3 answers)
Closed 5 years ago.
I'm new to SQL. I've got my table with 3 columns. Given a list of values (lets say ints for example 1, 4, 3) I want to select rows in which the second columns value equals something that the given list contains.
Is it possible to pass a list as an argument in SQL?
select * from TABLE1 where ...
How do i finish this statement for it to work as i explained?
I'm using PostgreSQL 9.4
Try the following query:
SELECT *
FROM TABLE1
WHERE col2 IN (1, 4, 3);
Most flavors of SQL support the IN clause, which allows comparing a column against a sequence of values. In the query above, we compare col2 against a collection of numbers, but we can equally compare against string literals, etc.

comma separated value in sql [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Concat all column values in sql
I have a table
ID | Name
1 | X
2 | y
3 | z
I have to show values in column Name as comma separated i.e x,y,z.
One way I can do is looping the values of column "Name" and displaying as comma separated.
Is there is a other way to do it.Please help.
Even though this is a duplicate of several other questions, I'd like to give an answer, because the easiest way to do this has changed recently. Oracle has provided the very nifty LISTAGG function with the following syntax:
SELECT
LISTAGG(name, ',') WITHIN GROUP (ORDER BY name)
FROM
my_table;
LISTAGG is available since Oracle 11.2.