# 22. Virtuoso Functions Guide - string_to_file

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

## string_to_file

writes a varchar to a file
string_to_file (in path varchar, in string varchar, in mode integer);
Parameters
path – varchar relative path.
string – varchar or string session to write to the file.
mode – integer mode.

- 0 - overwrite from start offset 0
- -1 - append to end of file
- -2 - overwrite and truncate.

Description

This function requires dba privileges.

string_to_file writes a varchar value or string session to a file. The path is relative to the server's working directory. The mode is an integer value interpreted as a position. A mode of 0 writes the content starting at offset 0. A mode of -1 appends to the end of the file. The append option is probably the most useful for producing application level logs, etc.

The string argument can also be a string output object. In this case the content is used as the string.

If the mode is -2, the new content supersedes the old. This is different from 0 in that the file will be truncated if the new content is shorter than the old.

The DirsAllowed and DirsDenied lists in Parameters section of the virtuoso configuration file (virtuoso.ini by default) are used to control disk access. An error 42000/FA024 is signalled if an attempt is made to write to a file in a directory to which disk access is not explicitly allowed.

Examples
Simple example

Write an entry to an application log

    SQL>string_to_file ('logs/applog.txt',
      concat (datestring(now()),'\t','Application started.\n'), -1);

    Done. -- 4 msec.
    SQL> quit;
    bash$ cat logs/applog.txt
    2001-03-19 15:15:12.000000	Application started.
    bash$

See Also

file_to_string