oracle中字符串連接符||使用
oracle字符串連接符||
1、oracle和mysql都遵循sql99標(biāo)準(zhǔn)(ANSI制定的,在1999年)
- oracle中 select 后面必須要有from關(guān)鍵字
- 在mysql中select concat('hello',' world');正確,但是在oracle中錯(cuò)誤
- hadoop中hive(蜂巢)數(shù)據(jù)庫(kù)支持sql92標(biāo)準(zhǔn)
2、dual:偽表
select concat('hello',' world') from emp;這語(yǔ)句,emp中有幾條記錄,hello world就輸出幾次 select concat('hello',' wordl') from dual;這句就只輸出一次
3、字符串連接符:||
select 'hello'||' world' 字符串 from dual; select ename||'的薪水是'||sal 信息 from emp;
4、字符串
- 單引號(hào)表示日期或字符串
- 雙引號(hào)表示別名
oracle字符拼接(||、concat)
準(zhǔn)備數(shù)據(jù)
創(chuàng)建GradesTable 表
CREATE TABLE GradesTable (Name VARCHAR2(6), Languages VARCHAR2(6),Mathematics VARCHAR2(6), English VARCHAR2(6) ); insert into GradesTable (Name,Languages,Mathematics,English) values('李明','88','67','98'); insert into GradesTable (Name,Languages,Mathematics,English) values('阿珂','88','67','98'); insert into GradesTable (Name,Languages,Mathematics,English) values('唐三','88','67','98');
1、||
可以無(wú)限拼接,類似于拼接字符串時(shí)候的 +,可以拼接字符串或表字段。
select name||'-'||languages from GradesTable where name='李明'; 執(zhí)行結(jié)果:李明-88
2、concat
oracle中的函數(shù),CONCAT(char1 , char2),也可以拼接字符串或表字段。
select concat(name,languages) from GradesTable where name='李明'; 執(zhí)行結(jié)果:李明88
需要注意:
- 在Oracle中,CONCAT函數(shù)將只允許將兩個(gè)值連在一起。
- 如果需要連接多個(gè)值,需要嵌套多個(gè)CONCAT函數(shù)。
如下:
select concat(concat(Name,'-'),Languages) from GradesTable where name='李明'; 執(zhí)行結(jié)果:李明-88
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
隨機(jī)獲取oracle數(shù)據(jù)庫(kù)中的任意一行數(shù)據(jù)(rownum)示例介紹
對(duì)于rownum來(lái)說(shuō)它是oracle系統(tǒng)順序分配為從查詢返回的行的編號(hào),返回的第一行分配的是1,第二行是2,依此類推,這個(gè)偽字段可以用于限制查詢返回的總行數(shù),且rownum不能以任何表的名稱作為前綴2014-07-07oracle自動(dòng)清理archivelog文件的具體方法
這篇文章介紹了oracle自動(dòng)清理archivelog文件的具體方法,有需要的朋友可以參考一下2013-09-09oracle ORA-01114、ORA-27067錯(cuò)誤解決方法
本文章總結(jié)了關(guān)于ORA-01114、ORA-27067錯(cuò)誤解決方法,有需要學(xué)習(xí)的朋友可參考一下下哦2012-10-10Oracle插入數(shù)據(jù)時(shí)出現(xiàn)ORA-00001:unique?constraint問(wèn)題
這篇文章主要介紹了Oracle插入數(shù)據(jù)時(shí)出現(xiàn)ORA-00001:unique?constraint問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03Oracle數(shù)據(jù)庫(kù)遷移所有文件到新掛載磁盤路徑
根據(jù)實(shí)際須要,有時(shí)安裝了oracle以后須要擴(kuò)展磁盤空間時(shí),每每是新增一個(gè)單獨(dú)的文件路徑并掛載存儲(chǔ),這時(shí)便須要總體遷移數(shù)據(jù)庫(kù)文件數(shù)據(jù)庫(kù),本文就來(lái)介紹一下Oracle數(shù)據(jù)庫(kù)遷移所有文件到新掛載磁盤路徑2024-01-01