ORA-00911: 无效字符 ORA-01006: 赋值变量不存在

ORA-00911: 无效字符 :

别加 ; 号

 

sb.append("sql语句;");

改为:

sb.append("sql语句");

 

 

 ORA-01006: 赋值变量不存在:

 

String query= "select * from DM_MAP_"+mapIndex+ " t where t.viewName='"+vName+ "'";
System.out.println(query);
PreparedStatement pst=con.prepareStatement(query);
rs = pst.executeQuery();

执行是正确的。
使用绑定变量看看

String query= "select * from DM_MAP_2 where VIEWNAME='?' ";
PreparedStatement pst=con.prepareStatement(query);
pst.setString(1, "T_2_2");
rs = pst.executeQuery();

将会报错!:java.sql.SQLException: ORA-01006: 赋值变量不存在
要改成

String query= "select * from DM_MAP_2 where VIEWNAME=? ";
PreparedStatement pst=con.prepareStatement(query);
pst.setString(1, "T_2_2");
rs = pst.executeQuery();

将会正确执行!

你可能感兴趣的:(ORACLE,query,string,sql)