[DB-SIG] RE: Re: [DB-SIG] oracledb and LONG

Alan Geller ageller@alumni.princeton.edu
Thu, 17 Sep 1998 15:39:25 -0400

The only way I know of to insert (or update) a LONG or LONG RAW column in Oracle is to use a bind variable. Oracle won't handle a string literal longer than 2000 characters, regardless of the column data type.

That is,

	sql = 'INSERT INTO TABLE_1 (COL_1) VALUES (:1)'
	cursor.execute(sql, (longVal, ))

or a similar construct (the exact syntax depends on the Oracle Python interface you're using -- there are two, and I don't remember which is which). Note that longVal needs to be dbi.dbiRaw(longVal) if it's a LONG RAW column, and if you're using the dbi-compliant Oracle interface.

As an aside, this is a good technique to use for data of any type; you can prepare the cursor once, and then execute it repeatedly with different data values. This avoids the (considerable) effort of repeatedly parsing the same SQL.

Alan Geller

-----Original Message-----
Sent: None

Message-Id: <199809170704.JAA04790@mail.infotek.no>
Date: Thu, 17 Sep 1998 09:05:53 +0200
To: db-sig@python.org
From: Geir Ove Gronmo <grove@infotek.no>
Subject: Re: [DB-SIG] oracledb and LONG
In-Reply-To: <36000320.62D9B01E@ariad.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 8bit

At 14:27 16.09.98 -0400, Lixin Zhou wrote:
>How can I pull out the value of a LONG field using oracledb?  What
>returns by cursor.fetchone or cursor.fetchall is always an empty
>string (not None).

I've got the opposite problem. How can I insert a string or the content of
a file (longer than 10Kb) into a LONG RAW field in the database using the
oracledb module (0.1.3)? I've tried to use an ordinary insert statement --
and hexencoding the string, but I get an error message back from Oracle
(ORA-1704 "string literal to long") when the document it longer than about
2000 characters.

Could someone please help me out with this?

All the best,
Geir O.

 ==================  Geir Ove Grønmo  ==================
|  STEP Infotek as, Gjerdrumsvei 12, 0486 Oslo, Norway  |
|        grove@infotek.no http://www.infotek.no/        |