Skip to main content
Inspiring
August 13, 2009
Question

Length for the char data type

  • August 13, 2009
  • 3 replies
  • 1210 views

I'm calling a store procedure from my ColdFusion 8 and passing xml document as a long string using toString() to a store procedure in Sybase

I'm not sure when setting the parameter in the store procedure what length should I use since the xml string passed to this store procedure will be different every time. Some may be very very long but sometimes it may be quite short.

Here is my codes:

<cfxml

variable="MyXML"> ........xml document structure here ......... </cfxml>

<!--- then call str. proc. passing the xml doc as string to Sybase --->

<cfstoredproc procedure="sp_XML_To_SQL" datasource="ADV">

    <cfprocparam type="In" cfsqltype="CF_SQL_CHAR" dbvarname="@myxmlstring" value="#toString(MyXML)#">

</cfstoredproc>

<!--- Below is the str. Proc. I have in Sybase  --->

Create Procedure dbo.sp_XML_To_SQL

@myxmlstring char (8000) ????? <------------------------ This may be the maximum length for char datatype. Can this number be flexible?

AS

    BEGIN

           INSERT NewTable values (@xmlstring)

    END

This topic has been closed for replies.

3 replies

Inspiring
August 14, 2009

For an XML string you should probably use an "unlimited text-field" data type.  This depends upon your underlying database.

I'm not familiar with Sybase, but I do know about its close-cousin MS SQL Server, which (in the 2005 edition) offers three good choices:

  • VARCHAR(n) and NVARCHAR(n) allow up to 8,000 characters.
  • VARCHAR(MAX) and NVARCHAR(MAX) allow up to 2 gigabytes.
  • TEXT, a deprecated field type equivalent to the above, also allows that amount.

(Yes, I'm glossing-over a few details ...)

In all cases, the lengths are measured in characters, each of which might occupy one or more bytes, depending on both the field-types and the characters themselves.  (In most cases, to paraphrase George Orwell's Animal Farm, "all characters are equal, but some are more equal than others.")

Look at your existing data and determine what lengths typically occur, measured in characters.  Then choose an appropriate field type.  Since you will not be "indexing" the strings, one of the practically-unlimited-size field types would be best.

BKBK
Community Expert
Community Expert
August 13, 2009

Isn't len(toString(myXML)) sufficient?

Inspiring
August 13, 2009

Field lengths for char and varchar columns in database tables have a maximum length.  There is also an upper limit on what that maximum length can be.  Details vary with db software.