sqloracleoracle-sqldeveloperbi-publisher

SQL Query to enclose column with quotes when it has |


A table has the following details

Course_Number                   Description

10                             Lean Six Sigma - White Belt 2022 | Mar. 12-Abr
12                             Gold Six Sigma || Got it
13                             Diamond Six Sigma || Black Belt
13                             Six Lean Sigma

Is there a way i can enclose the data with quotes " in case if the description column has "|".

So the output should be like

Course_Number                   Description

10                             "Lean Six Sigma - White Belt 2022 | Mar. 12-Abr"
12                             "Gold Six Sigma || Got it"
13                             "Diamond Six Sigma || Black Belt"
13                             Six Lean Sigma

Solution

  • If you're looking at this to make it easier for people to copy/paste and avoid delimiter issues, then I think transforming your data may be considered. If you are still looking for an answer to above, then you could create a case statement expression and use multiple concat() or use ||.

    select course_number, 
    case 
     when description like '%|%' then '"' || description || '"' 
     else description 
    end description
    from course_data