# 22. Virtuoso Functions Guide - let

Chapter Contents | Prev | Next
Keyword Search:
www.openlinksw.com
docs.openlinksw.com
Book Home
Contents
Preface
Virtuoso Functions Guide
Administration
Aggregate Functions
Array Manipulation
BPEL APIs
Backup
Compression
Cursor
Date & Time Manipulation
Debug
Dictionary Manipulation
Encoding & Decoding
File Manipulation
Free Text
Hashing / Cryptographic
LDAP
Locale
Mail
Miscellaneous
Number
Remote SQL Data Source
Replication
SOAP
SQL
String
Transaction
Type Mapping
UDDI
User Defined Types & The CLR
Virtuoso Java PL API
Virtuoso Server Extension Interface (VSEI)
Web Server & Internet
XML
XPATH & XQUERY
and
append
assign
avg
boolean
ceiling
concat
contains
count
create-attribute
create-comment
create-element
create-pi
current
distinct
doc
document
document-literal
empty
ends-with
every
except
false
filter
floor
fn:collection
for
format-number
function-available
generate-id
id
if
intersect
is_after()
is_before()
key
lang
last
let
list()
local-name
max
min
name
namespace-uri
normalize-space
not
number
or
position
processxquery
processxslt
processxsql
progn()
replace()
round
serialize
shallow
some
starts-with
string
string-length
substring
substring-after
substring-before
sum
system-property
text_contains()
translate
true
tuple()
union
unordered
unparsed-entity-uri
urlify
xmlview
Functions Index

## let

Creates temporary variables and calculates an expression that uses these variables
any let ( var1name string, var1value sequence, var2name string, var2value sequence, ... , varNname string, varNvalue sequence, retval any);
Description

For every pair of arguments, the function calculates values of these arguments and then creates a new temporary local variable whose name is the string value of the first argument in pair and the value assigned is the value of the second argument in pair. Obviously, the argument for variable name is usually a constant string of alphanumeric characters. The expression for a value of variable number I may refer to variables created during steps 1 to I-1. When all pairs of arguments are turned into temporary variables, the last argument is calculated and its value is returned as the value of the whole expression.

Temporary variables are destroyed on return.

This function is used in the implementation of "LET" control operator in XQUERY, so you will probably use that operator in XQUERY expessions, not the function. This function may be useful in XPATH expressions and in XSLT stylesheets. It is not a part of library of standard XQUERY 1.0 functions.

Parameters
varIname – Expression for the name for the I-th temporary variable
varIvalue – Expression for the value for the I-th temporary variable
retval – Expression for the value to be returned
Return Types

Any, depending on the type of retval expression.

Errors

SQLState | Error Code | Error Text | Description
--- | --- | --- | ---
42000 | XPF02 | Wrong number of arguments for XPATH function let(), maybe internal XQuery error | The function should have odd number of arguments: even number of arguments that describe veriables plus one for the returned expression.

Examples

These two expressions are equivalent, but first may be used in any XPATH while second is written in XQUERY syntax

    let('baseprice', /item/price, 'discount', 0.20, $baseprice * (1.0 - $discount))
    LET  $baseprice := /item/price, $discount := 0.20 RETURN $baseprice * (1.0 - $discount)

See Also

for()