# xs:long

Converts $string-var (a string) to a long value.

If the value of $string-var is greater than 9,223,372,036,854,775,807 or less than -9,223,372,036,854,775,808, the following error message is displayed:

    Error occurred while executing XQuery: Could not cast "9223372036854775809" to type [long@http://www.w3.org/2001/XMLSchema]

Note: The value $string-var must be specified without commas as shown in the following example invocation:

xs:long("999999999")

If $string-var is the empty sequence, the empty sequence is returned.

The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

To learn more about using fault codes, see Getting the TransformException Fault Code Programmatically.

### Signatures

xs:long(xs:string $string-var) —> xs:long

### Arguments

Data Type | Argument | Description
--- | --- | ---
xs:string | $string-var | Represents the string to convert to a long value.

### Returns

Returns the long value of $string-var.

### Examples

#### Simple

Invoking long("10403")returns the integer value 10403 as shown in the following example query:

    <long>{xs:long("10403")}</long>

The preceding query generates the following result:

    <long>10403</long>

#### Error—Decimal Point Not Allowed

Invoking long("104.0") outputs an error because 104.0 is not a valid integer (decimal point is not allowed.)

For example, the following example query:

    <long>{xs:long("104.0")}</long>

    Produces the following error:

    Error occurred while executing XQuery: Could not cast "104.0" to type [long@http://www.w3.org/2001/XMLSchema]

#### Error—Not a Number

Invoking long("foo") outputs an error because "foo" is not a number.

For example, the following example query:

    <long>{xs:long("foo")}</long>

Produces the following error:

    Error occurred while executing XQuery: Could not cast "foo" to type [long@http://www.w3.org/2001/XMLSchema]

#### Null

Invoking long(()) returns an empty sequence. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

For example, the following example query:

    <long>{xs:long(())}</long>

The preceding query generates the following result:

    <long/>

Related Topics

W3C long data type description

Getting the TransformException Fault Code Programmatically