Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
982 views
in Technique[技术] by (71.8m points)

sqlite - How to select all values and hide NULL values in SQL?

so in my database some rows have NULL values, and when I select * from table, that NULL values also shows as text "null". So I want to hide all NULL values. Does anyone have idea for query? Thanks!

this is my input in DB:

db.execSQL("CREATE TABLE IF NOT EXISTS table (name VARCHAR, kg VARCHAR,   pod                 VARCHAR,reps VARCHAR, time VARCHAR );");
  db.execSQL("INSERT INTO table VALUES('name 1',NULL,NULL , NULL , '"+s+"');");
 db.execSQL("INSERT INTO table VALUES(NULL,'S 1','"+ee5+"' , '"+ee+"' , '"+s+"');");
 db.execSQL("INSERT INTO table VALUES(NULL,'S 2','"+ee6+"' , '"+ee2+"', '"+s+"');");
 db.execSQL("INSERT INTO table VALUES(NULL,'S 3','"+ee7+"' , '"+ee3+"', '"+s+"');");
 db.execSQL("INSERT INTO table VALUES(NULL,'S 4','"+ee8+"' , '"+ee4+"', '"+s+"');");
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It depends on the data type of the column.

-- If the data type is integer:
SELECT COALESCE(the_column, 0)
FROM the_table;

-- or, if the column is a char or varchar type:
SELECT  COALESCE(the_column, 'some text here')
FROM the_table;

-- or, if it is a date:
SELECT  COALESCE(the_column, '1900-01-01')
FROM the_table;

BTW: some databases have the IFNULL() function which does the same thing.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...