查询语句:select * from table_name where id='1'; 在jdbc中我们可以这样查询String sql = "select * from table_name where id=?";
PreparedStatement ps = conn.preparedStatement(sql);
ps.setString(1, "1");
ps.executeQuery();在存储过程中可以这么用
create or replace procedure(vId in char) as
....
begin
....
select name into ..from table_name where id=vId;
....
end;通过 ‘?’占位符传参数。
但是这样id的值只能有一个。如果我想批量查询,如:select * from table_name where id in ('1','2','3'.....);就是in里的数据个数不固定。在jdbc中该如何使用?
在存储过程中又怎么传递参数呢?(不要拼接字符串)求指点.
PreparedStatement ps = conn.preparedStatement(sql);
ps.setString(1, "1");
ps.executeQuery();在存储过程中可以这么用
create or replace procedure(vId in char) as
....
begin
....
select name into ..from table_name where id=vId;
....
end;通过 ‘?’占位符传参数。
但是这样id的值只能有一个。如果我想批量查询,如:select * from table_name where id in ('1','2','3'.....);就是in里的数据个数不固定。在jdbc中该如何使用?
在存储过程中又怎么传递参数呢?(不要拼接字符串)求指点.
v_ids='1,2,3';
如果表的数据量小,可以直接用LIKE查询:
select * from table_name where ','||v_ids||',' LIKE '%,'||id||',%' ;
如果数据量大,那么先把v_ids拆分出来插入到临时表中,再查询:
select * from table_name where id (select * from temp_tab)