Greetings!
I am using SQLite. I want to declare variable, but it gives me a syntax error. Please help me to find a solution:
Select * from t2 where value= ? This is my query. Now how can I pass values to ? ?
Thanks in advance, Jennie
Greetings!
I am using SQLite. I want to declare variable, but it gives me a syntax error. Please help me to find a solution:
Select * from t2 where value= ? This is my query. Now how can I pass values to ? ?
Thanks in advance, Jennie
As far as I know SQLite doesn't support anything like that.
The syntax is standard for libraries that implement bound parameters (and prepared statements that use them), but you would need to do that in a programming language that queries the database, and not in the database itself.
The specifics, of course, depend on the programming language and the library.
In Perl, for example you could:
my $sth = $dbh->prepare("Select * from t2 where value=?"); foreach my $value (@values) { $sth->execute($value); $row = $sth->fetchrow_hashref; [...] } Bobby Tables has some more examples in a variety of languages.
sqlite shell). Moreover, ? is just the syntax for positional bound parameters; SQLite also supports named bound parameters via :someName.You can support variables in sqlite using an in-memory temp table. See my answer at https://stackoverflow.com/a/14574227/1435110
The only way to use variables like that is by using the binding functions. In many cases, constructing a query string in the language you are using is easier.