数据库select语句中可以使用变量吗

来源:百度知道 编辑:UC知道 时间:2024/06/04 12:47:38
如选出数据库中名字为变量a的记录应该怎么做?谢谢
在java中怎么具体怎么实现?从表t1中选出name为sun的记录
String nam="sun";
rs=sql.executeQuery("select * from t1 where .....");

DECLARE @a nvarchar(30)
set @a = 字符
select @a from 表

String nam="sun";
rs=sql.executeQuery("select * from t1 where name = '"+nam+"'");

可以

当然能用变量 要是不能用变量这数据库还有毛用

select * from 表名 where 字段='a'