如何在查詢語句中把空值(null),輸出為

時間 2021-08-30 09:30:39

1樓:娛樂小八卦啊

mysql可用:

select cource.c_id,cource.c_name,cource.

c_num,ifnull(student.count_c_id,'lattice') from cource

left join

(select c_id,count(s_id) as count_c_id from cource_student group by c_id) as student

on cource.c_id=student.c_id;

在遇到多張表查詢時,很可能查一個關聯數值時,並沒有這條關聯記錄,所以查詢到的結果是null,通常需要把這個結果處理成0或者其他。這時候就用isnull(欄位,0)。

擴充套件資料

sql null 值

null 值是遺漏的未知資料。預設地,表的列可以存放 null 值。

null 值的處理方式與其他值不同。

null 用作未知的或不適用的值的佔位符。

註釋:無法比較 null 和 0;它們是不等價的。

sql之null、空字串、0的區別:

1、'' 表示空字串,判斷'' 用  ='' 或 <>'' ,

2、null表示空值,數值未知,沒有兩個相等的空值,判斷用 is null 或 is not null

例如:tran_heating_id_!=5 想篩選出所有tran_heating_id_不是5的客戶資訊,但是這樣並不能篩出tran_heating_id_為null的客戶資訊

(因為null是值不確定的情況),需要用is null篩選。

3、0表示值為『0』。

2樓:賓士

利用null函式:

sqlserver: isnull(欄位,0)oracle: nvl(欄位,0)access:

iif(isnull(欄位),0,欄位)mysql: ifnull(欄位,0);

---以上,希望對你有所幫助。

3樓:我tm不管

select isnull(a,0) from table

4樓:

isnull(a,0)

或者case a when null then 0 else a end

5樓:匿名使用者

不可能的,null與0不同。

sql語句中 查詢結果 把0 替換為 空,怎麼弄?

6樓:匿名使用者

如果兩個指定的表示式相等,則返回空值 nullif查詢結果 把0 替換為 空, 也就是 nullif ( 查詢結果列, 0 )

例如:sql> select

2 nullif(0,0) as "0",3 nullif(1,0) as "1",4 nullif(2,0) as "2",5 nullif(3,0) as "3"

6 from

7 dual;

0 1 2 3---------- ---------- ---------- ----------

1 2 3sql>

7樓:匿名使用者

參考replace 語法,或者update 更新

8樓:匿名使用者

select replace(column,0,'null') from [table]

sql 語句 把一個值為0的欄位改為空('null')

9樓:匿名使用者

a=''表示將a設定為''字串,並非null

寫成a=null試試看!

10樓:匿名使用者

update a set a=null

11樓:丿

update a set a is null where a='0'

12樓:運動的使命

update 表 set 欄位= null where 欄位='0'

sql查詢欄位是空的語句並且空值用0代替怎麼寫?

13樓:sql的藝術

--列是字元型別的

select isnull(列名,'0') as 列名 from 表名

--列是數字型別的

select isnull(列名,0) as 列名 from 表名

14樓:匿名使用者

oracle資料庫用nvl(column,'為空時的值')qlserver資料庫用isnull() 用法同上示例:表名value,其中有的欄位是value3update value set value3=nvl(value3,0);

我的絕對正確,還有問題hi我!

15樓:

select isnull(欄位,0)from 表

如果查詢多列,在前面加入列名

16樓:匿名使用者

用isnull函式:

select isnull(欄位,0) from table

17樓:秋梵高明

sqlserver

select isnull(欄位,0) from tableoracle

select decode(欄位,null,0,欄位) from table

18樓:

select xx = 0 from table where xx is null

19樓:

select iif(欄位="",0,欄位) as 欄位 from table

如何把資料庫中null值設定為0

20樓:鯉魚

sql中,設定語句 if 欄位名 is null set 欄位名=0

設定表欄位 update tablename set 欄位名=0 where 欄位名 is null

21樓:匿名使用者

update 表 set 欄位 ='0' where 欄位 is null

22樓:

表中對應欄位預設值設定成0 就好了

23樓:匿名使用者

直接用update tablename a set a.name='0' where a.name is null

也可以用函式來實現 假設a表

比如 case when a.name is null then 0 else a.name

decode 也可以實現

24樓:匿名使用者

1、如果還沒有匯入資料,通用的做法是將表的這個欄位設定預設值為0,所以當新增的時候如果該欄位沒有給值就會預設0這個值

2、如果已經匯入資料,則可以使用修改語句修改update 表名 set 表欄位='0' where ..... --這條是將表中某個欄位符合where條件的值設定為0

3、針對第一點

a、oracle 的修改語句是alter table 表名 modify 欄位名 default(0);

b、sqlserver需要刪除原有表的約束alter table 表名 drop constraint 約束名字

新增新約束並賦予預設值alter table 表名 add constraint 約束名字 default 預設值 for 欄位名稱

25樓:匿名使用者

nvl(null,0)

怎樣將資料庫中int型別的null值在程式中也能按照null值輸出,而不是0. 但是,int預設空值為0.

26樓:卷人

int? i=null;

可空型別nullable

這樣寫試試

27樓:

將int型別轉字串

更新SQL語句中,子查詢返回多行值無法執行。如何解決

把子查詢前面的 換成 in 試試?update study set received code taiycg1 where received code in select study.received code from study,series where study.studyinstanceu...

oracle查詢語句中判斷列表中的值和當前日期相差的天數是否

假設表t,欄位s time是你需要的列 1 若s time為date型別,計算相差天數的sql語句 select trunc sysdate trunc s time from t where 你需要的條件 2 若s time為varchar2型別,計算相差天數的sql語句 select trunc...

如何把sql語句查詢到的值賦值給變數

馮益斌 多行 system.data.sqlclient.sqlconnection conn new system.data.sqlclient.sqlconnection server database 你的資料庫的名字 uid sa pwd sa的密碼 system.data.sqlclien...