sql查询替换
Ⅰ sql查询替换姓名
看你什么数据库了
如果是MSSQL就用这个
update
this1..hisguests
set
firstname='李四'
where
firstname='张三'
oracle。MYSQL等
用
update
this1.hisguests
set
firstname='李四'
where
firstname='张三'
Ⅱ SQl 里 如何替换查询结果
--so easy
select case when sexy=1 then '男' else '女' end as '性别',*
from table
Ⅲ 动态实现sql查询条件替换
<select id="queryEmp" resultType="cn.test.entity.Emp">
select * from emp where 1=1
<if test="deptNo!=null">
and deptno=#{deptNO}
</if>
<if test="deptName!=null">
and deptno=#{deptName}
</if>
</select>
注:<if test="deptNo!=null">中 的deptNo是指实体类中的属性或字段;
choose:
<select id="queryEmp" resultType="cn.test.entity.Emp">
select * from emp where 1=1
<choose>
<when test="deptNo!=null">
and deptno=#{deptNo}
</when>
<when test="deptName!=null">
and deptname=#{deptName}
</when>
<otherwise>
and personnum>#{personNum}
</otherwise>
</choose>
</select>
Ⅳ SQL条件查询替换
update news set CONTEMT= REPLACE ( CONTEMT,'HTM', 'HTM1') where type=40
解释:
update 表名 set 字段名= REPLACE ( 字段名,'被替换的值', '替换成') where 条件
Ⅳ SQL语句查询替换问题
用一个子查询来搞定吧!
编写思路:
从原表(表A)中查询type=2的值,即查出所有的部门;
在子查询(表B)中,查出所有的公司的名称以及对应的ID;
建立原表和子查询表的关系,通过company_pid = 子查询的公司id;
SQL语句如下:
Select B.NAME "公司名称", A.NAME "部门名称"
From 原表 A, (Select T.ID, T.NAME FROM 原表 T) B
WHERE A.COMPANY_PID = B.ID (+)
AND A.TYPE=2
Ⅵ SQL查询结果替换
select * from 表 where 字段 like '%+%'
--查询某个字段里是否有结果包含'+'的
update 表 set 字段 = replace(字段,'+','') where 字段 like '%+%'
--更新上句查询出来了。若有多个字段,且你不确定'+'出现的字段,可每个字段分别执行这两句。
Ⅶ sql如何把查询到的NULL替换成空值
1、这要看你如何保存你查询的结果。只能是你把你查询的结果保存为0,查询不会改变原本存在的值。表名test,字段a=.null.(int型),字段b=1,字段c=2 :select * from test into tabel test1
update set a=0 where a=.null。
2、用 IsNull(字段名, '') 可以将NULL的字段转换为空值,这在多个字段连接时很有用,因为NULL值+任何字段都是NULL。
3、将NULL替换为空create procere fill_null@tablename varchar(100) --表名asdeclare @colname varchar(100)declare col_cur cursor for select c.name from syscolumns c,sysobjects o where c.id=o.id and o.name=@tablename open col_curfetch next from col_cur into @colnamewhile @@fetch_status!=-1beginexec ('update '+@tablename+' set '+@colname+'='''' where '+@colname+' is null' )fetch next from col_cur into @colnam endclose col_curdeallocate col_cur
Ⅷ 如何批量执行sql查找替换
在linux里面,有一个比较好的工具sed,sed -i "s#A#B#g" filename,比如:sed -i "s#linux#windows#g" a.txt,这样可以把a.txt文件中所有的linux替换成windows,“#”可以换成其他的字符,可以根据实际情况来定。如果替换的内容来自文件,可以用脚本遍历文件的方式实现。例如:
旧地址文件:A.txt,需要处理的sql文件:mysql.sql,替换后的新内容:newtext
#/bin/bash
for line in `cat .A.txt`;
do
sed -i "s#$line#newtext#g" mysql.sql
done
当然,也可以指定替换行的范围(例如50行到100行),具体的请参考linux下sed命令的用法
Ⅸ SQL批量查询和替换
1.把新的结果集在xls文件中做好,保存文件.
2.在数据库中新建一个存储新数据并用于替换的表.
用create
table,或者select
into
...where
1<>1克隆.
3.将xls文件数据批量导入数据库新表.
4.用联表更新语句,将新表数据更新到表中.
5.drop
table
语句删除临时用的存储表.
---------
此语句用于mssql批量导入,注意在导入时文件需处于关闭.
例:insert
into
TableName(Column1,Column2,Column3,Column4)
select
Column1,Column2,Column3,Column4
from
OpenDataSource
(
'Microsoft.Jet.OLEDB.4.0',
'Data
Source="Path\FileName.xls";User
ID=Admin;Password=;Extended
properties=Excel
5.0'
)...sheet1$
Ⅹ SQL语句 替换某个字段中的某个值
1、创建测试表,
create table test_replace(id number, value varchar2(20));