欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

MySQL使用LOAD_FILE()函數(shù)方法總結(jié)

 更新時(shí)間:2019年03月28日 08:33:36   投稿:laozhang  
在本篇文章里小編給大家分享了關(guān)于MySQL使用LOAD_FILE()函數(shù)方法和相關(guān)知識(shí)點(diǎn),需要的朋友們學(xué)習(xí)下。

在MySQL中,LOAD_FILE()函數(shù)讀取一個(gè)文件并將其內(nèi)容作為字符串返回。

語(yǔ)法

LOAD_FILE(file_name)

其中file_name是文件的完整路徑。

下面是我從一個(gè)文件中選擇內(nèi)容的示例:

SELECT LOAD_FILE('/data/test.txt') AS Result;

結(jié)果:

+------------------------------------------+

| Result |

+------------------------------------------+

| This text is all that the file contains! |

+------------------------------------------+

一個(gè)數(shù)據(jù)庫(kù)的例子

下面是一個(gè)將文件內(nèi)容插入數(shù)據(jù)庫(kù)時(shí)查詢的示例:

INSERT INTO MyTable (FileId, UserId, MyBlobColumn)

VALUES (1, 20, LOAD_FILE('/data/test.txt'));

在本例中,列MyBlobColumn有一個(gè)BLOB數(shù)據(jù)類型(允許它存儲(chǔ)二進(jìn)制數(shù)據(jù))。

現(xiàn)在它在數(shù)據(jù)庫(kù)中,我們可以選擇它:

SELECT MyBlobColumn

FROM MyTable

WHERE UserId = 20;

結(jié)果:

+------------------------------------------+

| MyBlobColumn |

+------------------------------------------+

| This text is all that the file contains! |

+------------------------------------------+

如果文件不存在,返回NULL:

SELECT LOAD_FILE('/data/oops.txt') AS Result;

結(jié)果:

+--------+

| Result |

+--------+

| NULL |

+--------+

相關(guān)文章

最新評(píng)論