Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Variable Length

prabhu_s2
Active Contributor
0 Likes
1,855

Hi

what is the maximum length a string variable can hold? say i want a variable zname to hold a string of 10,000 characters is it posible? kindly advice. if not what is the other way of doing it?

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
864

You have plenty of room here, 10000 character no problem. Not sure that there is a limit, as I am working with really long strings right now in my assigment. I think the only limit would come from the memory cap of your session.

Regards,

Rich Heilman

3 REPLIES 3
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
865

You have plenty of room here, 10000 character no problem. Not sure that there is a limit, as I am working with really long strings right now in my assigment. I think the only limit would come from the memory cap of your session.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
864

Hi,

I do not think that there is a limit. But I am sure it will keep 10k chars b'coz I used it to keep 12k char of length.

Regards,

Subbu

Read only

Former Member
0 Likes
864

Hiii Prabhu,

though a string can generally store 256 char(Normally we use this .) still the following documents will clear ur doubt and show u the corect path,

Open SQL supports three different types to store varying length character strings: VARCHAR, LONGVARCHAR and CLOB. Only columns of the VARCHAR type, whose maximum size is limited to 1000 characters, are allowed to occur in comparison expressions, ORDER BY clauses, and so on.

From a functional point of view, LONGVARCHAR and CLOB columns behave the same, but the size restriction imposed on the LONGVARCHAR type allows this type to be mapped to an appropriate VARCHAR data type on each supported database platform. On most database platforms, this type is more efficient than the respective CLOB type.

To store character strings with more than 1,333 characters, the CLOB type must be used.

For portability reasons, Open SQL does not permit the storage of empty (zero-length) strings in any of these column types, because on some database platforms the empty string is always treated as a NULL value, which would lead to different query behavior on different database platforms. Furthermore, Open SQL forbids the storage of string values with trailing blanks in VARCHAR and LONGVARCHAR columns. This is because comparison semantics differs between blank-padded and non-padded semantics on the various database platforms. Blank-padded semantics compares two strings as equal if they differ in the number of trailing blanks only – that is, "ABC” equals “ABC “, whereas non-padded semantics compares two strings as equal only if they have equal length and no differing characters – that is, “ABC” is not equal to “ABC “.

If an application needs to represent something like an "initial" value in a VARCHAR or LONGVARCHAR column, it is recommended that you use the string " " (a String object consisting of one single space). Although this is, strictly speaking, also a blank-padded string, it is accepted by Open SQL and can be treated in a portable way across all supported database platforms. In the case of CLOB columns, an initial value can and should be represented as a NULL value explicitly.

Binary Strings

Open SQL for Java supports the following data types to store binary strings:

· BINARY

· LONGVARBINARY

· BLOB

Only columns of the fixed BINARY type are comparable, whereas LONGVARBINARY and BLOB columns are not.

From a functional point of view, LONGVARBINARY and BLOB columns behave the same, but the size restriction imposed on the LONGVARBINARY type allows this type to be mapped to an appropriate VARBINARY type on each supported database platform. On most database platforms, this type is more efficient than the respective BLOB type.

To store binary strings with more than 2,000 bytes, the BLOB type has to be used.

With Open SQL for Java you cannot store empty (zero-length) binary strings in any of these column types, because on some database platforms the empty string is always treated as a NULL value. If you need to represent a custom initial value, you should either use some outstanding value in accordance with your application or consider storing a NULL value explicitly. In the latter case, you should be aware of the NULL value handling in SQL comparisons.

char(size) Holds a fixed length string (can contain letters, numbers, and special characters). The fixed size is specified in parenthesis

varchar(size) Holds a variable length string (can contain letters, numbers, and special characters). The maximum size is specified in parenthesis

tinytext Holds a variable string with a maximum length of 255 characters

text

blob Holds a variable string with a maximum length of 65535 characters

mediumtext

mediumblob Holds a variable string with a maximum length of 16777215 characters

longtext

longblob Holds a variable string with a maximum length of 4294967295 characters