MySQL的sql语句如何将一列数据
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),
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("com.mysql.jdbc.Driver");//加驱动
con=DriverManager.getConnection("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 {
st=con.createStatement();
st.executeUpdate("delete from kaoshi where id="+id);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
mysql update语句拼接的问题:写一个公用的update语句,根据传进来的值组合起来
money 是什么类型的,貌似只能存数值类型吧,你存how much进去会有问题的吧
mysql中sql语句的带参数拼接问题
是不是传过去的参数类型是String,如果是就改为Integer类型吧
mysql 字串号以逗号分隔,分隔后第个字符加单引号,然后再拼接起来,字符间用逗号
select replace(concat('''',channel,''''),',',''',''') from tb_user where id='1';
这样么
mysql存储过程能不能直接执行拼接的sql语句
prepare statement_name from 'sql_text'
execute statement_name using [ variable1,variable2]
deallocate prepare statement_name
mysql循环插入语句,如何使循环变量i与字符串拼接起来构成新字符串然后插入到表中?
这个可以使用mysql的concat 函数来完成字符串连接的处理。
使用 CAST 函数完成 数字到字符串的类型转换
mysql> SELECT CONCAT ( CAST(1 as char) , '2') AS test;
+------+
| test |
+------+
| 12 |
+------+
1 row in set (0.00 sec)
用MYSQL语句怎么实现字符串叠加
mysql 中的加号是运算符 字符串肯定无法使用的
不过可以用内置函数CONCAT(str1,str2,...,strN) 来完成你要的效果
update table set name=concat('ss:',name)
MySQL的sql语句如何将一列数据:等您坐沙发呢!