# 22. Virtuoso Functions Guide - sprintf

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
ascii
atoi
blob_to_string
blob_to_string_outpu...
chr
initcap
isblob
isstring
lcase
left
length
locate
ltrim
make_string
regexp_instr
regexp_like
regexp_match
regexp_parse
regexp_replace
regexp_substr
repeat
replace
right
rtrim
search_excerpt
serialize
space
split_and_decode
sprintf
strcasestr
strchr
string_output
string_output_flush
string_output_gz_com...
string_output_string
string_to_file
strrchr
strstr
subseq
substring
tmp_file_name
trim
ucase
upper
Transaction
Type Mapping
UDDI
User Defined Types & The CLR
Virtuoso Java PL API
Virtuoso Server Extension Interface (VSEI)
Web Server & Internet
XML
XPATH & XQUERY
Functions Index

## sprintf

returns a formatted string
sprintf ( format string, arg_1 any, ... , arg_x any);
Description

sprintf returns a new string formed by "printing" a variable number of arguments arg_1 - arg_x according to the format string format, that is, exactly the same way as with the sprintf function of C language. However the sprintf function enforces some additional limitations over the sprintf C function. It does not allow for single value output to take more than 2000 characters. It does support the following additional format characters:

diouxXeEfgcs - as in the C language printf

S - as 's' but escapes the single quotes by doubling them (as per SQL/92). This is suitable for constructing dynamic SQL statements with string literals inline.

        sprintf ('insert into testit (data) values ('%S')', 'Test ''Real'' data')
    	-> insert into testit (data) values ('Test ''Real'' data')

I - as 's' but escapes the string value to form a valid identifier name (will double the double quotes). This is suitable for constructing dynamic SQL statements with identifiers inline.

        sprintf ('select * from "%I"', 'Big "Table" Name')
    	-> select * from "Big ""Table"" Name"

U - as 's' but escapes the string value as an HTTP URL (same as http_url() function). Useful for making dynamic VSP content

        sprintf ('<a href="%U">', 'day & night')
    	-> <a href="day+%26+night">

V - as 's' but escapes the string value as an HTTP Value (same as http_value). Useful for making dynamic VSP content

        sprintf ('<INPUT name="test" value="%V">', 'day & night')
    	-> <INPUT name="test" value="day &amp; night">

Note that the sprintf format length and precision modifiers do not apply to the extension format characters

    sprintf('Int=%d/%o/%x, String=%s, Character=%c',
        42798,42798,42798,'la cadena',65)
     -> 'Int=42798/123456/a72e, String=la cadena, Character=A'