I had the same issue when trying to use data from a (CSV) database for plotting single values with TikZ/PGFPlots or for printing values using siunitx.
With this post I found out how to store all values from the database as (expanded) LaTeX variable named after the respective key:
\documentclass[tikz]{standalone}
\usepackage{siunitx}
\usepackage{filecontents}
\begin{filecontents*}{mydb.csv}
key;value
mykey;1.0
\end{filecontents*}
% Relevant code below
\usepackage{datatool}
\DTLsetseparator{;}
\DTLloaddb{mydb}{mydb.csv}
\begin{document}
\DTLforeach{mydb}{\Key=key,\Value=value}
{%
\cslet{\Key}{\Value}%
}
\DTLfetch{mydb}{key}{mykey}{value} works\
% while $\num{\DTLfetch{mydb}{key}{mykey}{value}}$ fails
\mykey prints the value for mykey, $\num{\mykey}$ also works
\end{document}
However, loading multiple databases with similar keys would re-assign the same variables.
As a quick fix, I made DTLFetch assign the values to variables named after a concatenation of database name and key and wrote a function to parse the latter:
\documentclass[tikz]{standalone}
\usepackage{siunitx}
\usepackage{filecontents}
\begin{filecontents*}{mydb.csv}
key;value
mykey;1.0
\end{filecontents*}
% Relevant code below
\usepackage{datatool}
\DTLsetseparator{;}
\DTLloaddb{mydb}{mydb.csv}
\newcommand{\getval}[2]{\csname#1#2\endcsname}
\begin{document}
\DTLforeach{mydb}{\Key=key,\Value=value}
{%
\cslet{mydb\Key}{\Value}%
}
\getval{mydb}{mykey} prints the value for mykey, $\num{\getval{mydb}{mykey}}$ also works
\end{document}