简体   繁体   中英

Insert contents of a text file into the Oracle CLOB

I'm trying to insert whole text contents of file.txt into a CLOB column!

Connection^ DB = gcnew Connection();
OracleConnection^ Ocnn=DB->getOracleConnectionObject();
int number = 0;

try {
    // here >>
    OracleCommand^ c = gcnew OracleCommand("INSERT INTO PANDA.PAGE(SITE_ID, URL, SOURCE) VALUES('40', 'www.site.com', Read_Whole_File('C://Users/farmehr/Desktop/', 'file.txt'))", Ocnn);
    number = c->ExecuteNonQuery();

}
catch (Exception^ eOra) {
    Console::WriteLine(eOra->Message + "Exception Caught");
    throw eOra;
}

I want to know is there any way to insert file directly to the data base? ( A function like Read_Whole_File() in the code )

In order to be able to insert a file into a clob first I had to make a procedure in SQLPLUS! SOURCE is my clob file and TEMP_CLOB is a predefined directory.

在此处输入图片说明

Next in my code I had to run this procedure:

在此处输入图片说明

Using code:

在此处输入图片说明

Result:

在此处输入图片说明

-Keep this in mind that for making and running procedures you have to login AS SYSDBA.( Change oracleClient.dll to OracleManagedAcess.dll if you're using C or .NET)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM