mysql数据库删除数据语句怎么写_sql数据库基本语句-删除数
据库sql语句-数据库sq。。。
MySQL的sql语句如何将⼀列数据拼接成⼀个字符串?
select GROUP_CONCAT(dictinct insertdate) from table1;
mysql存储过程能不能直接执⾏拼接的sql语句
当然可以,就是在mysql存储过程中使⽤动态sql,就可以拼接sql,然后执⾏了。
给你复制⼀段,如果不满意,⾃⼰搜索 mysql?存储过程??动态sql?就可以了
DROP?PROCEDURE?IF?EXISTS?SearchByDoctor;
CREATE?PROCEDURE??SearchByDoctor(
IN?DoctorId?VARCHAR(50),
IN?deptId?VARCHAR(50),
IN?beginDate?VARCHAR(20),
IN?endDate?VARCHAR(20),
sql中delete用法IN?StandDeptId?VARCHAR(50),
IN?OperationFlag?VARCHAR(50),
IN?SsczflId??VARCHAR(50),
OUT?OperNum?INT,
OUT?AvgDangerIndex?DOUBLE,
OUT?OperGrCase?INT
)
BEGIN
DECLARE?cal1?VARCHAR(800);
DECLARE?cal2?VARCHAR(800);
SET?cal1="SELECT?COUNT(1),AVG(DANGER_INDEX)?INTO?@para1,@para2??FROM?yw_ssxxb?WHERE?1=1?";
SET?cal2="SELECT?COUNT(1)?INTO?@para3?FROM?gr_grbw?WHERE?OPE_RELID?IN?(SELECT?RELID?FROM?yw_ssxxb? WHERE?1=1";
#拼接医⽣id
SET?cal1=CONCAT(cal1,"?","AND?OPEDOC_ID?=?","'",DoctorId,"'");
SET?cal2=CONCAT(cal2,"?","AND?OPEDOC_ID?=?","'",DoctorId,"'");
#拼接科室id
IF?deptId?<>''?THEN
SET?cal1=CONCAT(cal1,"AND?DEPT_ID?=","'",deptId,"'");
END?IF;
#拼接开始结束⽇期
IF?beginDate<>''?AND?endDate?<>''?THEN
SET?cal1=CONCAT(cal1,"?","AND?OPER_AT?BETWEEN?","'",beginDate,"'","?AND?","'",endDate,"'");
END?IF;
#拼接标准科室
IF?StandDeptId<>''?THEN
SET?cal1=CONCAT(cal1,"?","AND?DEPT_ID?IN?(?SELECT?ID?FROM?department?WHERE?STAND_DEPT_ID? =?","'",StandDeptId,"'",")");
END?IF;
#拼接数据来源
IF?OperationFlag?<>''?THEN
SET?cal1=CONCAT(cal1,"?","AND?OPEPARTKINDID?IN?(SELECT?ID?FROM?zh_ssczfl?WHERE?
FLAG=?","'",OperationFlag,"'",")");
END?IF;
#拼接⼿术操作类别
IF?SsczflId?<>?''?THEN
SET?cal1=CONCAT(cal1,"?","AND?OPEPARTKINDID?=?","'",SsczflId,"'");
END?IF;
SET?cal2?=CONCAT(cal2,")");
SET?@sql1=cal1;
SET?@sql2=cal2;
PREPARE?stmt1?FROM?@sql1;
EXECUTE?stmt1;
DEALLOCATE?PREPARE?stmt1?;
PREPARE?stmt2?FROM?@sql2;
EXECUTE?stmt2;
DEALLOCATE?PREPARE?stmt2?;
SET?OperNum=@para1;
SET?AvgDangerIndex=@para2;
SET?OperGrCase=@para3;
END;
mysql语句与变量的拼接
concat(),具体⽤法百度下。mysql和其它SQL语⾔不⼀样。
怎⼳连接MYSQL数据库和执⾏SQL语句
⾸先创建连接
就创建个Cnnection对象,然后把驱动加上,还有帐号密码什⼳的!我没连过sql数据库,不知道驱动,你可以在⽹上搜⼀下。
给你⼀个我连接mysql数据库的例⼦
public Connection Getdata(){//这是连接数据库的⼀个⽅法,还可以配置连接池。
Connection con=null;
try {
Class.forName("空⽩.mysql.jdbc.Driver");//加驱动
Connection("jdbc:mysql://localhost:3306/data","root","qq");//数据库路径、端⼝、库名、数据库⽤户名和密码
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
public void delete(int id){//对数据库进⾏操作的⽅法,先调⽤上⾯写好的连接!
Connection con=Getdata();
Statement st;
try {
ateStatement();
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论