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));