我正在尝试在ORACLE sql代码中创建一个条件语句。我有一个Java函数,它需要两个参数getchildren(child1,child2)。这个函数的参数用于创建查询语句。请注意,不要删除HTML标签。
public ResultSet getchildren(String Child1, String child2) throws SQLException
{
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
query ="select * from table1
if child1 is not null and child2 is null
{ where child1 = 1 }
else if child2 is not null AND child1 is null
{where child2 = 2}
else
{//some other where statment }
";
System.out.println("\nExecuting query: " + query);
rset = stmt.executeQuery(query);
return rset;
}
这显然是伪代码。 我需要帮助创建一个条件执行where子句,以便在其条件有效时执行每个"where"子句。 我已经尝试了类似于上面的内容,但没有成功。