readtext Usage

The readtext command provides a way to retrieve text, unitext, and image values and retrieve only a selected portion of a column’s data.

readtext requires the name of the table and column, the text pointer, a starting offset within the column, and the number of characters or bytes to retrieve. This example finds six characters in the copy column in the blurbs table:

declare @val binary(16) 
select @val = textptr(copy) from blurbs 
where au_id = "648-92-1872" 
readtext blurbs.copy @val 2 6 using chars

In the example, after the @val local variable has been declared, readtext displays characters 3 – 8 of the copy column, since the offset was 2.

Instead of storing potentially large text, unitext, and image data in the table, SAP ASE stores it in a special structure. A text pointer (textptr) which points to the page where the data is actually stored is assigned. When you retrieve data using readtext, you actually retrieve textptr, which is a 16-byte varbinary string. To avoid this, declare a local variable to hold textptr, and then use the variable with readtext, as in the example above.

Related concepts
Text and Image Functions