哪个是在oracle中存储超过1mb txt文件的最佳方法

时间:2014-02-21 09:22:27

标签: php sql oracle

在varchar中存储txt文件是否足够?或者我是否需要使用blob?我有一个纯txt文件。如何使用普通的php存储从oracle数据库中的html文件字段读取的txt文件( BLOB TYPE)。如何检索它。我应该使用任何转换技术来存储和检索BLOB吗?

1 个答案:

答案 0 :(得分:2)

最大oracle表列大小为4000字节(4k),因此1MB不适合。

所以是的..你可以使用BLOB ..但是CLOB可能是更好的选择。 如果您的列是纯文本文件,CLOB列将允许您对内容进行文本搜索。

在非Oracle环境中,您可以访问其他更合适的类型。即在MySQL中你得到TINYTEXT,TEXT,MEDIUMTEXT和LONGTEXT

例如

CREATE TABLE file_store(ID NUMBER, filename VARCHAR2(255), file_contents CLOB);

INSERT INTO file_store VALUES (1, 'testfile.txt', 'sample text that would normally be imported');

INSERT INTO file_store VALUES (2, 'testfile2.txt', 'sample IMPORTANT text that would normally be imported');

SELECT * FROM file_store;

ID FILENAME FILE_CONTENTS 1 testfile.txt sample text that would normally be imported 2 testfile2.txt sample IMPORTANT text that would normally be imported

SELECT * FROM file_store where file_contents like '%IMPORTANT%';

ID FILENAME FILE_CONTENTS 2 testfile2.txt sample IMPORTANT text that would normally be imported