How to store unlimited characters in Oracle 11g?

依然范特西╮ 提交于 2019-11-30 08:56:32

If a blob is what you need convince your dba it's what you need. Those data types are there for a reason and any roll your own implementation will be worse than the built in type.

Also you might want to look at the CLOB type as it will meet your needs quite well.

You could follow the way Oracle stored their stored procedures in the information schema. Define a table called text columns:

CREATE TABLE MY_TEXT (
IDENTIFIER INT, 
LINE       INT,
TEXT       VARCHAR2 (4000),
PRIMARY KEY (INDENTIFIER, LINE));

The identifier column is the foreign key to the original table. The Line is a simple integer (not a sequence) to keep the text fields in order. This allows keeping larger chunks of data

Yes this is not as efficient as a blob, clob, or LONG (I would avoid LONG fields if at all possible). Yes, this requires more mainenance, buf if your DBAs are dead set against managing CLOB fields in the database, this is option two.

EDIT:

My_Table below is where you currently have the VARCHAR column you are looking to expand. I would keep it in the table for the short text fields.

CREATE TABLE MY_TABLE (
INDENTIFER INT,
OTHER_FIELD VARCHAR2(10),
REQUIRED_TEXT VARCHAR(4000),
PRIMERY KEY (IDENTFIER));

Then write the query to pull the data join the two tables, ordering by LINE in the MY_TEXT field. Your application will need to split the string into 2000 character chunks and insert them in line order.

I would do this in a PL/SQL procedure. Both insert and select. PL/SQL VARCHAR strings can be up to 32K characters. Which may or may not be large enough for your needs.

But like every other person answering this question, I would strongly suggest making a case to the DBA to make the column a CLOB. From the program perspective this will be a BLOB and therefore simple to manage.

You said no BLOB or LONG... but what about CLOB? 4GB character data.

BLOB is the best solution. Anything else will be less convenient and a bigger maintenance annoyance.

Is BFILE a viable alternative datatype for your DBAs?

I don't get it. A CLOB is the appropriate database datatype. If your weird programming language will deal with strings of 8000 (or whatever) characters, what stops it writing those to a CLOB.

More specifically, what error do you get (from Oracle or your programming language) when you try to insert an 8000 character string into a column defined as a CLOB.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!