Concat 函数不起作用 - 参数数量无效 [英] Concat function is not working - invalid number of arguments
问题描述
我有一个包含两列(姓名、职业)的表格.我想以这样的格式输出值.
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)
Hear 第一个是名字,括号里的值是他们职业的第一个字母.
Hear First one is the name and the value in brackets is the first letter of their occupation.
到目前为止我所做的是
SELECT CONCAT(Name,SUBSTR(Occupation,1,1)) FROM OCCUPATIONS;
像这样的输出值
JaneS
JennyS
JuliaD
为了获得所需的格式,我试过这个
to get the required format I tried this
SELECT CONCAT(Name,"(",SUBSTR(Occupation,1,1),")") FROM OCCUPATIONS;
然后它会抛出类似这样的错误.
then it's throwing an error something like this.
SELECT CONCAT(Name,'(',SUBSTR(Occupation,1,1),')') FROM OCCUPATIONS* 第 1 行错误:ORA-00909:参数数量无效
SELECT CONCAT(Name,'(',SUBSTR(Occupation,1,1),')') FROM OCCUPATIONS * ERROR at line 1: ORA-00909: invalid number of arguments
我犯了什么错误,我应该怎么做才能改正.
What is the mistake that I have done and what should I do to fix it.
推荐答案
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.
其次,CONCAT
接受两个参数.
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;
这篇关于Concat 函数不起作用 - 参数数量无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!