String query1 = "SELECT * FROM table1 WHERE name LIKE 'a_'";
String query2 = "SELECT * FROM ( '" + query1 + "' ) WHERE age = '55'";
我试图将query1作为嵌套选择查询的变量,java中显示的错误是这个...... org.sqlite.SQLiteException:[SQLITE_ERROR] SQL错误或缺少数据库。 如何将query1指定为变量?
答案 0 :(得分:1)
您的代码query2
最终成为
SELECT * FROM ( 'SELECT * FROM table1 WHERE name LIKE 'a_'' ) WHERE age = '55'
如果你改变了
String query2 = "SELECT * FROM ( '" + query1 + "' ) WHERE age = '55'";
到
String query2 = "SELECT * FROM ( " + query1 + " ) WHERE age = '55'";
(请注意已删除的'
)结束:
SELECT * FROM ( SELECT * FROM table1 WHERE name LIKE 'a_' ) WHERE age = '55'
这应该是正确的SQLite语法。
我怀疑丢失数据库的错误来自于"混乱" SQLite可以通过修复语法来解决。否则请提供此更改的结果,最好是MCVE的形状。
顺便说一句,我没有得到那个查询的目的,它似乎有点迂回......