2.應(yīng)盡量避免在 where 子句中對(duì)字段進(jìn)行 null 值判斷,否則將導(dǎo)致引擎放棄使用索引而進(jìn)行全表掃描,如:
select id from t where num is null
最好不要給數(shù)據(jù)庫留NULL,盡可能的使用 NOT NULL填充數(shù)據(jù)庫.
備注、描述、評(píng)論之類的可以設(shè)置為 NULL,其他的,最好不要使用NULL。
不要以為 NULL 不需要空間,比如:char(100) 型,在字段建立時(shí),空間就固定了, 不管是否插入值(NULL也包含在內(nèi)),都是占用 100個(gè)字符的空間的,如果是varchar這樣的變長字段, null 不占用空間。
可以在num上設(shè)置默認(rèn)值0,確保表中num列沒有null值,然后這樣查詢:
select id from t where num = 0
3.應(yīng)盡量避免在 where 子句中使用 != 或 <> 操作符,否則將引擎放棄使用索引而進(jìn)行全表掃描。
4.應(yīng)盡量避免在 where 子句中使用 or 來連接條件,如果一個(gè)字段有索引,一個(gè)字段沒有索引,將導(dǎo)致引擎放棄使用索引而進(jìn)行全表掃描,如:
select id from t where num=10 or Name = 'admin'
可以這樣查詢:
select id from t where num = 10 union all select id from t where Name = 'admin'
5.in 和 not in 也要慎用,否則會(huì)導(dǎo)致全表掃描,如:
select id from t where num in(1,2,3)
對(duì)于連續(xù)的數(shù)值,能用 between 就不要用 in 了:
select id from t where num between 1 and 3
很多時(shí)候用 exists 代替 in 是一個(gè)好的選擇:
select num from a where num in(select num from b)
用下面的語句替換:
select num from a where exists(select 1 from b where num=a.num)
6.下面的查詢也將導(dǎo)致全表掃描:
select id from t where name like ‘%abc%’
若要提高效率,可以考慮全文檢索。
7.如果在 where 子句中使用參數(shù),也會(huì)導(dǎo)致全表掃描。因?yàn)镾QL只有在運(yùn)行時(shí)才會(huì)解析局部變量,但優(yōu)化程序不能將訪問計(jì)劃的選擇推遲到運(yùn)行時(shí);它必須在編譯時(shí)進(jìn)行選擇。然 而,如果在編譯時(shí)建立訪問計(jì)劃,變量的值還是未知的,因而無法作為索引選擇的輸入項(xiàng)。如下面語句將進(jìn)行全表掃描:
select id from t where num = @num
可以改為強(qiáng)制查詢使用索引:
select id from t with(index(索引名)) where num = @num
應(yīng)盡量避免在 where 子句中對(duì)字段進(jìn)行表達(dá)式操作,這將導(dǎo)致引擎放棄使用索引而進(jìn)行全表掃描。如:
select id from t where num/2 = 100
應(yīng)改為:
select id from t where num = 100*2
9.應(yīng)盡量避免在where子句中對(duì)字段進(jìn)行函數(shù)操作,這將導(dǎo)致引擎放棄使用索引而進(jìn)行全表掃描。如:
select id from t where substring(name,1,3) = ’abc’ -–name以abc開頭的id select id from t where datediff(day,createdate,’2005-11-30′) = 0 -–‘2005-11-30’ --生成的id
應(yīng)改為:
select id from t where name like 'abc%' select id from t where createdate >= '2005-11-30' and createdate < '2005-12-1'
10.不要在 where 子句中的“=”左邊進(jìn)行函數(shù)、算術(shù)運(yùn)算或其他表達(dá)式運(yùn)算,否則系統(tǒng)將可能無法正確使用索引。
11.在使用索引字段作為條件時(shí),如果該索引是復(fù)合索引,那么必須使用到該索引中的第一個(gè)字段作為條件時(shí)才能保證系統(tǒng)使用該索引,否則該索引將不會(huì)被使用,并且應(yīng)盡可能的讓字段順序與索引順序相一致。
12.不要寫一些沒有意義的查詢,如需要生成一個(gè)空表結(jié)構(gòu):
select col1,col2 into #t from t where 1=0
這類代碼不會(huì)返回任何結(jié)果集,但是會(huì)消耗系統(tǒng)資源的,應(yīng)改成這樣:
create table #t(…)
13.Update 語句,如果只更改1、2個(gè)字段,不要Update全部字段,否則頻繁調(diào)用會(huì)引起明顯的性能消耗,同時(shí)帶來大量日志。
14.對(duì)于多張大數(shù)據(jù)量(這里幾百條就算大了)的表JOIN,要先分頁再JOIN,否則邏輯讀會(huì)很高,性能很差。
15.select count(*) from table;這樣不帶任何條件的count會(huì)引起全表掃描,并且沒有任何業(yè)務(wù)意義,是一定要杜絕的。
16.索引并不是越多越好,索引固然可以提高相應(yīng)的 select 的效率,但同時(shí)也降低了 insert 及 update 的效率,因?yàn)?insert 或 update 時(shí)有可能會(huì)重建索引,所以怎樣建索引需要慎重考慮,視具體情況而定。一個(gè)表的索引數(shù)最好不要超過6個(gè),若太多則應(yīng)考慮一些不常使用到的列上建的索引是否有 必要。
17.應(yīng)盡可能的避免更新 clustered 索引數(shù)據(jù)列,因?yàn)?clustered 索引數(shù)據(jù)列的順序就是表記錄的物理存儲(chǔ)順序,一旦該列值改變將導(dǎo)致整個(gè)表記錄的順序的調(diào)整,會(huì)耗費(fèi)相當(dāng)大的資源。若應(yīng)用系統(tǒng)需要頻繁更新 clustered 索引數(shù)據(jù)列,那么需要考慮是否應(yīng)將該索引建為 clustered 索引。
18.盡量使用數(shù)字型字段,若只含數(shù)值信息的字段盡量不要設(shè)計(jì)為字符型,這會(huì)降低查詢和連接的性能,并會(huì)增加存儲(chǔ)開銷。這是因?yàn)橐嬖谔幚聿樵兒瓦B 接時(shí)會(huì)逐個(gè)比較字符串中每一個(gè)字符,而對(duì)于數(shù)字型而言只需要比較一次就夠了。
19.盡可能的使用 varchar/nvarchar 代替 char/nchar ,因?yàn)槭紫茸冮L字段存儲(chǔ)空間小,可以節(jié)省存儲(chǔ)空間,其次對(duì)于查詢來說,在一個(gè)相對(duì)較小的字段內(nèi)搜索效率顯然要高些。
20.任何地方都不要使用 select * from t ,用具體的字段列表代替“*”,不要返回用不到的任何字段。
21.盡量使用表變量來代替臨時(shí)表。如果表變量包含大量數(shù)據(jù),請(qǐng)注意索引非常有限(只有主鍵索引)。
22. 避免頻繁創(chuàng)建和刪除臨時(shí)表,以減少系統(tǒng)表資源的消耗。臨時(shí)表并不是不可使用,適當(dāng)?shù)厥褂盟鼈兛梢允鼓承├谈行В纾?dāng)需要重復(fù)引用大型表或常用表中的某個(gè)數(shù)據(jù)集時(shí)。但是,對(duì)于一次性事件, 最好使用導(dǎo)出表。
23.在新建臨時(shí)表時(shí),如果一次性插入數(shù)據(jù)量很大,那么可以使用 select into 代替 create table,避免造成大量 log ,以提高速度;如果數(shù)據(jù)量不大,為了緩和系統(tǒng)表的資源,應(yīng)先create table,然后insert。
24.如果使用到了臨時(shí)表,在存儲(chǔ)過程的最后務(wù)必將所有的臨時(shí)表顯式刪除,先 truncate table ,然后 drop table ,這樣可以避免系統(tǒng)表的較長時(shí)間鎖定。
25.盡量避免使用游標(biāo),因?yàn)橛螛?biāo)的效率較差,如果游標(biāo)操作的數(shù)據(jù)超過1萬行,那么就應(yīng)該考慮改寫。
26.使用基于游標(biāo)的方法或臨時(shí)表方法之前,應(yīng)先尋找基于集的解決方案來解決問題,基于集的方法通常更有效。
27.與臨時(shí)表一樣,游標(biāo)并不是不可使用。對(duì)小型數(shù)據(jù)集使用 FAST_FORWARD 游標(biāo)通常要優(yōu)于其他逐行處理方法,尤其是在必須引用幾個(gè)表才能獲得所需的數(shù)據(jù)時(shí)。在結(jié)果集中包括“合計(jì)”的例程通常要比使用游標(biāo)執(zhí)行的速度快。如果開發(fā)時(shí) 間允許,基于游標(biāo)的方法和基于集的方法都可以嘗試一下,看哪一種方法的效果更好。
28.在所有的存儲(chǔ)過程和觸發(fā)器的開始處設(shè)置 SET NOCOUNT ON ,在結(jié)束時(shí)設(shè)置 SET NOCOUNT OFF 。無需在執(zhí)行存儲(chǔ)過程和觸發(fā)器的每個(gè)語句后向客戶端發(fā)送 DONE_IN_PROC 消息。
29.盡量避免大事務(wù)操作,提高系統(tǒng)并發(fā)能力。
30.盡量避免向客戶端返回大數(shù)據(jù)量,若數(shù)據(jù)量過大,應(yīng)該考慮相應(yīng)需求是否合理。
實(shí)際案例分析:拆分大的 DELETE 或INSERT 語句,批量提交SQL語句
如果你需要在一個(gè)在線的網(wǎng)站上去執(zhí)行一個(gè)大的 DELETE 或 INSERT 查詢,你需要非常小心,要避免你的操作讓你的整個(gè)網(wǎng)站停止相應(yīng)。因?yàn)檫@兩個(gè)操作是會(huì)鎖表的,表一鎖住了,別的操作都進(jìn)不來了。
Apache 會(huì)有很多的子進(jìn)程或線程。所以,其工作起來相當(dāng)有效率,而我們的服務(wù)器也不希望有太多的子進(jìn)程,線程和數(shù)據(jù)庫鏈接,這是極大的占服務(wù)器資源的事情,尤其是內(nèi)存。
如果你把你的表鎖上一段時(shí)間,比如30秒鐘,那么對(duì)于一個(gè)有很高訪問量的站點(diǎn)來說,這30秒所積累的訪問進(jìn)程/線程,數(shù)據(jù)庫鏈接,打開的文件數(shù),可能不僅僅會(huì)讓你的WEB服務(wù)崩潰,還可能會(huì)讓你的整臺(tái)服務(wù)器馬上掛了。
所以,如果你有一個(gè)大的處理,你一定把其拆分,使用 LIMIT oracle(rownum),sqlserver(top)條件是一個(gè)好的方法。下面是一個(gè)mysql示例:
while(1){ //每次只做1000條 mysql_query(“delete from logs where log_date <= ’2012-11-01’ limit 1000”); if(mysql_affected_rows() == 0){
//刪除完成,退出! break; } //每次暫停一段時(shí)間,釋放表讓其他進(jìn)程/線程訪問。 usleep(50000) }
--help
查看幫助或者直接通過google搜索學(xué)習(xí)。find / -name filename.txt
根據(jù)名稱查找/目錄下的filename.txt文件。
find . -name "*.xml"
遞歸查找所有的xml文件
find . -name "*.xml" |xargs grep "hello world"
遞歸查找所有文件內(nèi)容中包含hello world的xml文件
grep -H 'spring' *.xml
查找所以有的包含spring的xml文件
find ./ -size 0 | xargs rm -f &
刪除文件大小為零的文件
ls -l | grep '.jar'
查找當(dāng)前目錄中的所有jar文件
grep 'test' d*
顯示所有以d開頭的文件中包含test的行。
grep 'test' aa bb cc
顯示在aa,bb,cc文件中匹配test的行。
grep '[a-z]\{5\}' aa
顯示所有包含每個(gè)字符串至少有5個(gè)連續(xù)小寫字符的字符串的行。
ps –ef|grep tomcat
查看所有有關(guān)tomcat的進(jìn)程
kill -9 19979
終止線程號(hào)位19979的進(jìn)程
ls -al
pwd
cp source dest
復(fù)制文件
cp -r sourceFolder targetFolder
遞歸復(fù)制整個(gè)文件夾
scp sourecFile romoteUserName@remoteIp:remoteAddr
遠(yuǎn)程拷貝
mkdir newfolder
rmdir deleteEmptyFolder
刪除空目錄 rm -rf deleteFile
遞歸刪除目錄中所有內(nèi)容
mv /temp/movefile /targetFolder
mv oldNameFile newNameFile
su -username
chmod 777 file.java
//file.java的權(quán)限-rwxrwxrwx,r表示讀、w表示寫、x表示可執(zhí)行
tar -czf test.tar.gz /test1 /test2
tar -tzf test.tar.gz
tar -xvzf test.tar.gz
head -n 10 example.txt
tail -n 10 example.txt
tail -f exmaple.log
//這個(gè)命令會(huì)自動(dòng)顯示新增內(nèi)容,屏幕只顯示10行內(nèi)容的(可設(shè)置)。
sudo rm a.txt
使用管理員身份刪除文件
netstat -tln | grep 8080
查看端口8080的使用情況
lsof -i :8080
ps aux|grep java
查看java進(jìn)程
ps aux
查看所有進(jìn)程
tree a
ps:Mac下使用tree命令
wget http://file.tgz
mac下安裝wget命令
curl http://file.tgz
ping www.just-ping.com
ssh userName@ip
echo $JAVA_HOME
打印java home環(huán)境變量的值
java javac jps ,jstat ,jmap, jstack
svn git maven
使用者請(qǐng)直接看第一步,第二步和egit使用說明,
需要自己創(chuàng)建倉庫的可以看三四步
然后按步驟創(chuàng)建一個(gè)教程代碼庫
可以選擇下載SourceTree 和git SourceTree是一個(gè)客戶端,圖形界面,挺方便的
主界面有個(gè)教程,挺詳細(xì)的,可以看看
點(diǎn)右上角的小人圖標(biāo),然后點(diǎn)擊“Manage account”
在Account settings 里最下面有個(gè)選項(xiàng),Language,改成Chinese
創(chuàng)建完可以用SourceTree復(fù)制代碼進(jìn)去,點(diǎn)擊用SourceTree克隆
會(huì)彈出這個(gè)窗口,可以更改目標(biāo)路徑(必須是空文件夾,不存在的最好)
里面現(xiàn)在是空的,點(diǎn)擊在文件管理器中打開
把代碼復(fù)制到這個(gè)文件夾
然后查看SourceTree,里面就有未保存的文件(如果沒有,點(diǎn)擊下日志/歷史)點(diǎn)擊“未暫存的文件”
就會(huì)變成“已暫存的文件”
然后點(diǎn)擊工具欄的”提交”
輸入需要說明的文字,點(diǎn)擊提交
這時(shí)候你可以看到分支那里有了東西,不過這個(gè)時(shí)候還只是在你的本地
點(diǎn)擊推送,就會(huì)放到服務(wù)器上
點(diǎn)擊顯示完整輸出,可以看進(jìn)度,如果變綠,出現(xiàn)執(zhí)行成功,就行了,文件多會(huì)稍微慢點(diǎn)
然后去網(wǎng)站,刷新一下頁面,就會(huì)出來信息
源碼部分可以下載和查看源碼
提交部分可以查看提交記錄
點(diǎn)擊提交下面的藍(lán)字,可以查看這個(gè)版本修部分,每個(gè)變化文件都會(huì)顯示出來,紅色表示刪除代碼,綠表示添加代碼,十分方便查看這個(gè)版本更新了什么,
旁邊的通知圖標(biāo)可以留言評(píng)論
代碼更新的一般步驟:克隆代碼——修改——提交——推送
Eclipse可以用egit方便完成,Qt有git工具,Vs有git插件,其他情況可以用sourceTree完成
具體的,可以查詢其他資料,因?yàn)槲夷壳笆怯胘ava,我會(huì)再寫一個(gè)egit的使用方法
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
RegisterDAO registerDAO = (RegisterDAO)ac.getBean("RegisterDAO");
如果是兩個(gè)以上:
ApplicationContext ac = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml","dao.xml"});
或者用通配符:
ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:/*.xml");
二、ClassPathXmlApplicationContext[只能讀放在web-info/classes目錄下的配置文件]和FileSystemXmlApplicationContext的區(qū)別
classpath:前綴是不需要的,默認(rèn)就是指項(xiàng)目的classpath路徑下面;
如果要使用絕對(duì)路徑,需要加上file:前綴表示這是絕對(duì)路徑;
對(duì)于FileSystemXmlApplicationContext:
默認(rèn)表示的是兩種:
1.沒有盤符的是項(xiàng)目工作路徑,即項(xiàng)目的根目錄;
2.有盤符表示的是文件絕對(duì)路徑.
如果要使用classpath路徑,需要前綴classpath:
public class HelloClient {
protected static final Log log = LogFactory.getLog(HelloClient.class);
public static void main(String[] args) {
// Resource resource = new ClassPathResource("appcontext.xml");
// BeanFactory factory = new XmlBeanFactory(resource);
// 用classpath路徑
// ApplicationContext factory = new ClassPathXmlApplicationContext("classpath:appcontext.xml");
// ApplicationContext factory = new ClassPathXmlApplicationContext("appcontext.xml");
// ClassPathXmlApplicationContext使用了file前綴是可以使用絕對(duì)路徑的
// ApplicationContext factory = new ClassPathXmlApplicationContext("file:F:/workspace/example/src/appcontext.xml");
// 用文件系統(tǒng)的路徑,默認(rèn)指項(xiàng)目的根路徑
// ApplicationContext factory = new FileSystemXmlApplicationContext("src/appcontext.xml");
// ApplicationContext factory = new FileSystemXmlApplicationContext("webRoot/WEB-INF/appcontext.xml");
// 使用了classpath:前綴,這樣,FileSystemXmlApplicationContext也能夠讀取classpath下的相對(duì)路徑
// ApplicationContext factory = new FileSystemXmlApplicationContext("classpath:appcontext.xml");
// ApplicationContext factory = new FileSystemXmlApplicationContext("file:F:/workspace/example/src/appcontext.xml");
// 不加file前綴
ApplicationContext factory = new FileSystemXmlApplicationContext("F:/workspace/example/src/appcontext.xml");
IHelloWorld hw = (IHelloWorld)factory.getBean("helloworldbean");
log.info(hw.getContent("luoshifei"));
}
}
通過web方式提交索引和刪除索引
Solr 刪除全部索引:http://localhost:8080/solr/update/?stream.body=
wget http://www.atomicorp.com/installers/atomic #下載atomic yum源 sh ./atomic #安裝 yum check-update #更新yum軟件包
2、安裝nginx:
yum install nginx #安裝nginx,根據(jù)提示,輸入Y安裝即可成功安裝
#修改配置文件,這里省略,主要是將目錄指定到 /home/ngmsw-files
service nginx start #啟動(dòng)
chkconfig nginx on #設(shè)為開機(jī)啟動(dòng)
現(xiàn)在需要添加一個(gè)可以具有原創(chuàng)訪問的mysql賬號(hào)(需要進(jìn)入mysql命令行下):
GRANT ALL PRIVILEGES ON *.* TO remote@"%" IDENTIFIED BY '遠(yuǎn)程登錄的明文密碼' WITH GRANT OPTION;
執(zhí)行如下語句生效:
flush privileges;
創(chuàng)建安裝目錄,在/usr/java下建立安裝路徑,并將文件考到該路徑下:
# mkdir /usr/java
1、jdk-6u11-linux-i586.bin 這個(gè)是自解壓的文件,在linux上安裝如下:
# chmod 755 jdk-6u11-linux-i586.bin
# ./jdk-6u11-linux-i586.bin (注意,這個(gè)步驟一定要在jdk-6u11-linux-i586.bin所在目錄下)
在按提示輸入yes后,jdk被解壓。
出現(xiàn)一行字:Do you aggree to the above license terms? [yes or no]
安裝程序在問您是否愿意遵守剛才看過的許可協(xié)議。當(dāng)然要同意了,輸入"y" 或 "yes" 回車。
2、若是用jdk-6u11-linux-i586-rpm.bin 這個(gè)也是一個(gè)自解壓文件,不過解壓后的文件是jdk-6u11-linux-i586-rpm 包,執(zhí)行rpm命令裝到linux上就可以了。安裝如下:
#chmod 755 ./jdk-6u11-linux-i586-rpm
# ./jdk-6u11-linux-i586-rpm .bin
# rpm -ivh jdk-6u11-linux-i586-rpm
出現(xiàn)一行字:Do you aggree to the above license terms? [yes or no]
安裝程序在問您是否愿意遵守剛才看過的許可協(xié)議。當(dāng)然要同意了,輸入"y" 或 "yes" 回車。
安裝軟件會(huì)將JDK自動(dòng)安裝到 /usr/java/目錄下。
二、配置
#vi /etc/profile
在里面添加如下內(nèi)容
export JAVA_HOME=/usr/java/jdk1.6.0_27
export JAVA_BIN=/usr/java/jdk1.6.0_27/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH
讓/etc/profile文件修改后立即生效 ,可以使用如下命令:
# . /etc/profile
注意: . 和 /etc/profile 有空格.
重啟測(cè)試
java -version
屏幕輸出:
java version "jdk1.6.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build jdk1.6.0_02)
Java HotSpot(TM) Client VM (build jdk1.6.0_02, mixed mode)
delete from dianping_deal_business
where deal_id in (select deal_id from temp_dp_id_ent_info)
and id not in (select id from temp_dp_id_ent_info);
drop table temp_dp_id_ent_info;
drop table temp_dp_deal_id_ent_info;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class TestReadAndWrite {
public static void main(String[] args) throws IOException {
String path = "D:/dianping/gather/";
String fileName = "result";
String fileType = "xlsx";
writer(path, fileName, fileType);
read(path, fileName, fileType);
}
private static void writer(String path, String fileName, String fileType)
throws IOException {
InputStream stream = new FileInputStream(path + fileName + "."
+ fileType);
// 創(chuàng)建工作文檔對(duì)象
Workbook wb = null;
if (fileType.equals("xls")) {
wb = new HSSFWorkbook(stream);
} else if (fileType.equals("xlsx")) {
wb = new XSSFWorkbook(stream);
} else {
System.out.println("您的文檔格式不正確!");
}
// 創(chuàng)建sheet對(duì)象
Sheet sheet1 = (Sheet) wb.getSheetAt(0);
// 循環(huán)寫入行數(shù)據(jù)
int num = sheet1.getLastRowNum() + 1;
for (int i = 0; i < 5; i++) {
Row row = (Row) sheet1.createRow(num+i);
// 循環(huán)寫入列數(shù)據(jù)
for (int j = 0; j < 8; j++) {
Cell cell = row.createCell(j);
cell.setCellValue("測(cè)試" + j);
}
}
File file = new File(path + fileName + "." + fileType);
FileOutputStream fileOut = new FileOutputStream(file);
wb.write(fileOut);
fileOut.close();
stream.close();
}
public static void read(String path, String fileName, String fileType)
throws IOException {
InputStream stream = new FileInputStream(path + fileName + "."
+ fileType);
Workbook wb = null;
if (fileType.equals("xls")) {
wb = new HSSFWorkbook(stream);
} else if (fileType.equals("xlsx")) {
wb = new XSSFWorkbook(stream);
} else {
System.out.println("您輸入的excel格式不正確");
}
Sheet sheet1 = wb.getSheetAt(0);
for (Row row : sheet1) {
for (Cell cell : row) {
System.out.print(cell.getStringCellValue() + " ");
}
System.out.println();
}
}
}
concat(str "any" [, str "any" [, ...]]) Concatenate all but first arguments with separators. The first parameter is used as a separator. NULL arguments are ignored.b.實(shí)際例子:
postgres=# create table t_kenyon(id int,name varchar(10),remark text); CREATE TABLE postgres=# insert into t_kenyon values(1,'test','kenyon'),(2,'just','china'),(3,'iam','lovingU'); INSERT 0 3 postgres=# insert into t_kenyon values(4,'test',null); INSERT 0 1 postgres=# insert into t_kenyon values(5,null,'adele'); INSERT 0 1 postgres=# select * from t_kenyon; id | name | remark ----+------+--------- 1 | test | kenyon 2 | just | china 3 | iam | lovingU 4 | test | 5 | | adele (5 rows) postgres=# select concat(id,name,remark) from t_kenyon; concat ------------- 1testkenyon 2justchina 3iamlovingU 4test 5adele (5 rows)c.說明 concat函數(shù)純粹是一個(gè)拼接函數(shù),可以忽略null值拼接,拼接的值沒有分隔符,如果需要分割符,則需要用下面的函數(shù)concat_ws。
concat_ws(sep text, str "any" [, str "any" [,...] ]) Concatenate all but first arguments with separators. The first parameter is used as a separator. NULL arguments are ignored.b.實(shí)際應(yīng)用
postgres=# select concat_ws(',',id,name,remark) from t_kenyon; concat_ws --------------- 1,test,kenyon 2,just,china 3,iam,lovingU 4,test 5,adele (5 rows) postgres=# select concat_ws('_',id,name,remark) from t_kenyon; concat_ws --------------- 1_test_kenyon 2_just_china 3_iam_lovingU 4_test 5_adele (5 rows) postgres=# select concat_ws('',id,name,remark) from t_kenyon; concat_ws ------------- 1testkenyon 2justchina 3iamlovingU 4test 5adele (5 rows) postgres=# select concat_ws('^_*',id,name,remark) from t_kenyon; concat_ws ------------------- 1^_*test^_*kenyon 2^_*just^_*china 3^_*iam^_*lovingU 4^_*test 5^_*adele (5 rows)c.說明 concat_ws函數(shù)比concat函數(shù)多了分隔符的功能,其實(shí)就是concat的升級(jí)版,假如分隔符為'',則取出來的結(jié)果和concat是一樣的。其功能與mysql中的group_concat函數(shù)比較類似,但也有不同,pg中concat_ws分隔符還支持多個(gè)字符作為分隔符的,日常用得更多的可能是||。
split_part(string text, delimiter text, field int) Split string on delimiter and return the given field (counting from one)b.實(shí)際例子
postgres=# select split_part('abc~@~def~@~ghi','~@~', 2); split_part ------------ def (1 row) postgres=# select split_part('now|year|month','|',3); split_part ------------ month (1 row)c.說明 該函數(shù)對(duì)按分隔符去取某個(gè)特定位置上的值非常有效果
regexp_split_to_table(string text, pattern text [, flags text]) Split string using a POSIX regular expression as the delimiter.b.使用例子
postgres=# SELECT regexp_split_to_table('kenyon,love,,china,!',','); regexp_split_to_table ----------------------- kenyon love china ! (5 rows) --按分割符切割 postgres=# SELECT regexp_split_to_table('kenyon,china,loves',','); regexp_split_to_table ----------------------- kenyon china loves (3 rows) --按字母切割 postgres=# SELECT regexp_split_to_table('kenyon,,china',E'\\s*'); regexp_split_to_table ----------------------- k e n y o n , , c h i n a (13 rows)3.regexp_split_to_array
regexp_split_to_array(string text, pattern text [, flags text ]) Split string using a POSIX regular expression as the delimiter.b.實(shí)際例子
postgres=# SELECT regexp_split_to_array('kenyon,love,,china,!',','); regexp_split_to_array -------------------------- {kenyon,love,"",china,!} (1 row) postgres=# SELECT regexp_split_to_array('kenyon,love,,china!','s*'); regexp_split_to_array ----------------------------------------------- {k,e,n,y,o,n,",",l,o,v,e,",",",",c,h,i,n,a,!} (1 row)c.說明
mvn install:install-file -Dfile=d:/Downloads/apache-activemq-5.5.0/lib/activemq-core-5.5.0.jar -DgroupId=org.apache.activemq -DartifactId=activemq-core -Dversion=5.5.0 -Dpackaging=jar
解析:
mvn install:install-file -Dfile=外部包的路徑 /
-DgroupId=外部包的groupId /
-DartifactId=外部包的artifactId /
-Dversion=外部包的版本號(hào) /
-Dpackaging=jar