创建测试表
SQL>create table alice.user_stats(
2 id number primary key,
3 username varchar2(4000),
4 app blob)
5 partition by range(id)
6 (partition part01 values less than(50),
7 partition part02 values less than(maxvalue))
8 /
创建directory
SQL>create directory bfile as '/oracle'
Directory created.
SQL>grant read,write on directory bfile to alice
Grant succeeded.
存储blob
SQL>declare sfile bfile:=bfilename('BFILE','dotnetfx.exe')
2 length_file int :=dbms_lob.getlength(sfile)--得到文件长度
3 dfile blob blob指针
4 begin
5 insert into alice.user_stats(id,app) values(10,empty_blob())
6 select app into dfile from alice.user_stats--记录blob指针
7 dbms_lob.fileopen(sfile,dbms_lob.file_readonly)--以只读方式打开bfile模式的文件如果你对php有兴趣的话,可以向我一样在后盾人平台多看看自己学习学习,时间长了自己就慢慢明白了,希望能帮到你,给个采纳吧谢谢(⁄ ⁄•⁄ω⁄•⁄ ⁄)
MySQL中,BLOB是个类型系列,包括:TinyBlob、Blob、MediumBlob、LongBlob,这几个类型之间的唯一区别是在存储文件的最大大小上不同。MySQL的四种BLOB类型
TinyBlob: 最大 255字节
Blob: 最大 65K
MediumBlob:最大 16M
LongBlob: 最大 4G
注意:如果你存储的文件过大,数据库的性能会下降很多。
2、PHP *** 作BLOB案例
<?php
mysql_connect( "localhost", "root", "password")//连接数据库
mysql_select_db( "database")//选定数据库
//数据插入:
$CONTENT="测试内容" //$CONTENT为新闻内容
$COMPRESS_CONTENT = bin2hex(gzcompress($CONTENT))
$result=mysql_query( "insert into news (content) value ('$COMPRESS_CONTENT')")//数据插入到数据库news表中
//展示:
$query = "select data from testtable where filename=$filename"
$result = mysql_query($query)
$COMPRESS_CONTENT=@gzuncompress($result["COMPRESS_CONTENT"])
echo $COMPRESS_CONTENT
?>
[2]存储图片
<?php
mysql_connect( "localhost", "root", "password")//连接数据库
mysql_select_db( "database")//选定数据库
//存储:
$filename="" //这里填入图片路径
$COMPRESS_CONTENT = addslashes(fread(fopen($filename, "r"), filesize($filename)))//打开文件并规范化数据存入变量$data中
$result=mysql_query( "insert into news (content) value ('$COMPRESS_CONTENT')")//数据插入到数据库test表中
//展示:
ob_end_clean()
Header( "Content-type: image/gif")
$query = "select data from testtable where filename=$filename"
$result = mysql_query($query)
echo $result["COMPRESS_CONTENT"]
?>
// 连接字符串 data source=d:\test.db3password=1234SQLiteConnectionStringBuilder connStr = new SQLiteConnectionStringBuilder()
connStr.DataSource = @"d:\test.db3"
connStr.Password = "1234"
conn = new SQLiteConnection(connStr.ToString())
conn.Open()
// 插入数据
string SQL = "INSERT INTO test(k) VALUES(:k)"
SQLiteCommand cmd = conn.CreateCommand()
cmd.CommandText = SQL
// 取图标,准备插入到数据库BLOB字段
FileStream picStream = File.OpenRead(@"d:\1.bmp")
byte[] bArray = new byte[picStream.Length]
picStream.Read(bArray, 0, bArray.Length)
picStream.Close()
cmd.Parameters.Add("k", DbType.Binary).Value = bArray // BLOB
cmd.ExecuteNonQuery()
//取出数据
cmd.CommandText = "SELECT k FROM test"
System.Data.SQLite.SQLiteDataReader reader = cmd.ExecuteReader()
while (reader.Read())
{
MemoryStream streamImage = new MemoryStream(reader["k"] as byte[])
pictureBox1.Image = Image.FromStream(streamImage)
streamImage.Close()// 关闭流
}
reader.close()
conn.close()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)