Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

New PL/SQL datatype to deal with strings larger than 32K

user4377404Nov 1 2018 — edited Nov 1 2018

Currently, when there's a need to deal with texts, which are longer than 32K, you must use the CLOB.

What I'd like to have is datatype, the same as VARCHAR2, but without max size limits (just like String in C++).

Why not just use CLOB? Because it's just so much slower than VARCHAR2 and (I believe) internally is converted to VARCHAR2 in a lot of cases.

- You would not be able to have it as a database type (there's CLOB for this already)

- You'd be able to assign varchar2/CLOB to it

- You'd be able to assign it to varchar2/CLOB (error about 32K varchar2 would be OK)

- If it becomes too big and session runs out of the memory, that's fine. We'll deal with it.

- Make sure that Replace, Instr, etc. would work with it without 32K varchar2 limits.

- There would be possibility to pre-allocate size for it - for the performace reasons.

- There would be possibility to access individual chars like in the array - for the performace reasons.

So in the code it would look like:

declare

  dummy STRING;

  v     VARCHAR2(100);

  c     CLOB;

begin 

  v := 'bla bla';

  c := 'bla bla';

  dummy := 'Hello world'; -- it would auto allocate itself

  dummy := dummy || v; -- this would work

  dummy := dummy || c; -- this would work as well

  dummy[1] := 'A'; -- change H to A

  set_size(dummy, 1024 * 1024, ' '); -- set it's size to 1M, pre-populate with spaces

  dummy[33333] := 'x'; -- set 33333rd element to x

  dummy[11133333] := 'x'; --  this would throw an out of bounds error

  c := dummy; -- this should always work

  v := dummy; -- this would throw error about 32K limit, which is fine

end;

-- this would work

type t_string_tab is table of STRING index by binary_integer;

-- this would work

type t_rec is record (

s1 string

s2 string);

-- this would work

type t_string_tab is table of t_rec index by binary_integer;

Comments
Post Details
Added on Nov 1 2018
6 comments
3,335 views