SQL 在oracle pl sql中连接名字和姓氏,中间有空格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40058572/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Concat firstname and lastname with space in between in oracle pl sql
提问by Ram
I have one requirement to concat user first_ name, and last_name with space in between in Oracle.
Ex: first_name is 'Hopkins'
and last_name is 'Joe'
.
我有一个要求在 Oracle 中连接用户 first_ name 和 last_name,中间有空格。例如: first_name 是'Hopkins'
last_name 是'Joe'
。
Full name should be printed as Hopkins Joe.
全名应打印为 Hopkins Joe。
I'm using Oracle 11g and it is working in SQL query, but not working in stored procedure.
我正在使用 Oracle 11g,它在 SQL 查询中工作,但在存储过程中不起作用。
回答by Jibin Balachandran
Try this:
尝试这个:
SELECT CONCAT(CONCAT(first_name, ' '),last_name)
OR
或者
SELECT first_name || ' ' || last_namefrom;
回答by JYoThI
Try this
尝试这个
select first_name || ' ' || last_name as full_name from table
Example:
例子:
SELECT 'Dave' || ' ' || 'Anderson' as full_name
FROM table;
Result: 'Dave Anderson'
回答by shanika yrs
No need to use CONCAT function twice. Concat with space will work in this way
无需两次使用 CONCAT 功能。Concat with space 将以这种方式工作
SELECT CONCAT(first_name,(' '||last_name)) AS full_name
回答by ejazazeem
use this:
用这个:
TRIM(FIRST_NAME || ' ' || LAST_NAME)
if any of first_name or last_name is blank or null the extra space we are adding will be trimmed.
如果 first_name 或 last_name 中的任何一个为空或空,我们添加的额外空间将被修剪。
回答by wieseman
This will work:
这将起作用:
select first_name||' '||last_name
from table_name
where first_name is not null -- "if the first_name can be null"
and last_name is not null -- "if the last_name can be null"
;