Concat function is not working - invalid number of arguments

前端 未结 4 1895
粉色の甜心
粉色の甜心 2020-12-10 16:49

I have a table with two columns(Name, Occupation). I want to output the value in a format something like this.

Jane(A) 
Jenny(D) 
Julia(A)

相关标签:
4条回答
  • 2020-12-10 17:04

    This happens to be one reason why I prefer replace() over concat():

    SELECT REPLACE(REPLACE('{Name} ({Occ})', '{Name}', Name'
                          ), '{Occ}', SUBSTR(Occupation, 1, 1)
                  )
    

    You can readily see the format of the string being created and easily change it. Also, REPLACE() converts arguments to the appropriate type (which Oracle does with string concatenation anyway).

    0 讨论(0)
  • 2020-12-10 17:06

    You can use just || for concatenating

    select c1  ||   c2 ||   c3 || c4   as  col from mytable
    
    0 讨论(0)
  • 2020-12-10 17:09
    SELECT CONCAT(Name,"(",SUBSTR(Occupation,1,1),")") FROM OCCUPATIONS;
    

    First, the double quotes " are used to enclose identifiers. use single quote ' to wrap a string.

    Second, CONCAT accepts two params.

    You could nest bunch of concats, but it's easier and cleaner to use concatenation operation ||:

    SELECT Name || '('  || SUBSTR(Occupation,1,1) || ')' FROM OCCUPATIONS;
    
    0 讨论(0)
  • 2020-12-10 17:21

    you may try this

    select CONCAT(CONCAT(FIRST_NAME,' '),LAST_NAME) from employees;
    

    By using this you have to give number of nested CONCAT functions equals to the number of arguments

    Results

    CONCAT(CONCAT(FIRST_NAME,''),LAST_NAME)
    
    • Neena kochhar
    • steven king
    • Alexander Hunold
    0 讨论(0)
提交回复
热议问题