连接列并在oracle中显示

时间:2014-01-05 11:56:29

标签: oracle plsql

我有一个包含两列(名字和姓氏)的表我需要一个查询或PL / Sql脚本,它连接这两个字符串并以initcap()的形式显示输出 例如,First_name Last_name    Ramesh Pawar

输出应该是 Rameshpawar (p应该是小例)

2 个答案:

答案 0 :(得分:1)

SQL Fiddle

Oracle 11g R2架构设置

CREATE TABLE table_name ( First_Name, Last_Name ) AS
          SELECT 'Ramesh', 'Pawar' FROM DUAL
UNION ALL SELECT 'BOB', 'SmItH-JoNeS' FROM DUAL
UNION ALL SELECT 'liam', 'O''Brien' FROM DUAL;

查询1

如果名称中没有非字母数字字符,那么您可以使用INITCAP

SELECT INITCAP( First_Name || Last_Name ) AS Name
FROM   table_name

<强> Results

|           NAME |
|----------------|
|    Rameshpawar |
| Bobsmith-Jones |
|    Liamo'Brien |

查询2

但是,从上面的结果中,您可以看到,如果您有一个双管名称它不起作用;在这种情况下,你需要做这样的事情:

SELECT UPPER( SUBSTR( First_Name || Last_Name, 1, 1 ) ) || LOWER( SUBSTR( First_Name || Last_Name, 2 ) ) AS Name
FROM   table_name

<强> Results

|           NAME |
|----------------|
|    Rameshpawar |
| Bobsmith-jones |
|    Liamo'brien |

查询3

如果First_Name列不为null,则可以将其简化为:

SELECT UPPER( SUBSTR( First_Name, 1, 1 ) ) || LOWER( SUBSTR( First_Name || Last_Name, 2 ) ) AS Name
FROM   table_name

<强> Results

|           NAME |
|----------------|
|    Rameshpawar |
| Bobsmith-jones |
|    Liamo'brien |

答案 1 :(得分:0)

你的意思是你想要这样的东西?

select First_name || Lower(Last_name) from table_name;