l qsqlquery:isnull const 函数后加const怎么用

您所在的位置: &
SQL中的ISNULL函数介绍
SQL中的ISNULL函数介绍
如果您是才接触SQL不久的新手,SQL中各种函数式您一定要掌握的,下面将为您介绍其中的ISNULL函数,包括其语法、注释、返回类型等,供您参考。
中有多种多样的函数,下面将为您介绍SQL中的ISNULL函数,包括其语法、注释、返回类型等,供您参考,希望对您学习SQL能够有所帮助。
使用指定的替换值替换 NULL。
ISNULL ( check_expression , replacement_value )
check_expression
将被检查是否为 NULL的表达式。check_expression 可以是任何类型的。
replacement_value
在 check_expression 为 NULL时将返回的表达式。replacement_value 必须与 check_expresssion 具有相同的类型。
返回与 check_expression 相同的类型。
如果 check_expression 不为 NULL,那么返回该表达式的值;否则返回 replacement_value。
A. 将 ISNULL 与 AVG 一起使用
下面的示例查找所有书的平均价格,用值 $10.00 替换 titles 表的 price 列中的所有 NULL 条目。
SELECT AVG(ISNULL(price, $10.00))
FROM titles
下面是结果集:
--------------------------
(1 row(s) affected)
B. 使用 ISNULL
下面的示例为 titles 表中的所有书选择书名、类型及价格。如果一个书名的价格是 NULL,那么在结果集中显示的价格为 0.00。
SELECT SUBSTRING(title, 1, 15) AS Title, type AS Type,
ISNULL(price, 0.00) AS Price
FROM titles
下面是结果集:
Title Type Price
--------------- ------------ --------------------------
The Busy Execut business 19.99
Cooking with Co business 11.95
You Can Combat business 2.99
Straight Talk A business 19.99
Silicon Valley mod_cook 19.99
The Gourmet Mic mod_cook 2.99
The Psychology UNDECIDED
【编辑推荐】
【责任编辑: TEL:(010)】
关于&&的更多文章
在过去的近十年的时间里,面向对象编程大行其道。以至于在大学的
数据库产品
数据库综合
数据库新闻
维基百科将切换到另外一款开源数据库MariaDB
你的SQL Server代码安全吗?请你与我一起跟随作者来探
为什么会发生死锁?如何利用SQL Server Profiler分析
Oracle集群,也称Oracle RAC,称为“真正应用集群”。
本书是在《网管员必读―网络安全》第1版的基础上修改而成的。新版在保留第1版实用内容的基础上增加了大量新的实用内容,同时删除
51CTO旗下网站QSqlQuery Class
QSqlQuery Class Reference[]
The QSqlQuery class provides a means of executing and
manipulating SQL statements.
#include &&
Inherited by .
Public Members
( QSqlResult&*&r )
( const&QString&&&query = QString::null, QSqlDatabase&*&db = 0 )
( const&QSqlQuery&&&other )
QSqlQuery &
( const&QSqlQuery&&&other )
( int&field ) const
const QSqlDriver *
const QSqlResult *
( bool&forward )
virtual bool
( const&QString&&&query )
virtual QVariant
( int&i ) const
virtual bool
( int&i, bool&relative = FALSE )
virtual bool
virtual bool
virtual bool
virtual bool
( const&QString&&&query )
( const&QString&&&placeholder, const&QVariant&&&val )
( int&pos, const&QVariant&&&val )
( const&QVariant&&&val )
Protected Members
virtual void
virtual void
Detailed Description
The QSqlQuery class provides a means of executing and
manipulating SQL statements.
QSqlQuery encapsulates the functionality involved in creating,
navigating and retrieving data from SQL queries which are executed
on a . It can be used to execute DML (data
manipulation language) statements, e.g. SELECT, INSERT, UPDATE and DELETE, and also DDL (data definition language)
statements, e.g. CREATE TABLE. It can also be used to
execute database-specific commands which are not standard SQL
(e.g. SET DATESTYLE=ISO for PostgreSQL).
Successfully executed SQL statements set the query's state to
active (() returns TRUE); otherwise the query's state is
set to inactive. In either case, when executing a new SQL
statement, the query is positioned
query must be navigated to a valid record (so that ()
returns TRUE) before values can be retrieved.
Navigating records is performed with the following functions:
These functions allow the programmer to move forward, backward or
arbitrarily through the records returned by the query. Once an
active query is positioned on a valid record, data can be
retrieved using (). All data is transferred from the SQL
backend using QVariants.
For example:
QSqlQuery query( "SELECT name FROM customer" );
while ( query.() ) {
name = query.(0).toString();
doSomething( name );
To access the data returned by a query, use the value() method.
Each field in the data returned by a SELECT statement is accessed
by passing the field's position in the statement, starting from 0.
For the sake of efficiency there are no methods to access a field
by name. (The
class provides a higher level
interface for that generates SQL automatically and through which
fields are accessed by name.)
QSqlQuery supports prepared query execution and binding of
parameter values to placeholders. Note that only input values may
be bound. Be aware that not all databases support these
features. Currently only the Oracle and ODBC drivers have proper
prepared query support, but the rest of the drivers support this
by emulating the missing features (the placeholders are simply
replaced with the actual value when the query is executed). It is
also important to know that different databases use different
placeholder marks for value binding. Oracle uses a : character
followed by a placeholder name, while ODBC only uses a ?
character to identify a placeholder. In an attempt to make this
database independant we substitute the markers if you try to use
ODBC markers in a query to an Oracle database and vice versa. Note
that you can't mix the different bind styles by binding some
values using named placeholders and some using positional
placeholders.
// Named binding using named placeholders
q.( "insert into mytable (id, name, lastname) values (:id, :name, :lname)" );
q.( ":id", 0 );
q.( ":name", "Testname" );
q.( ":lname", "Lastname" );
// Positional binding using named placeholders
q.( "insert into mytable (id, name, lastname) values (:id, :name, :lname)" );
q.( 0, 0 );
q.( 1, "Testname" );
q.( 2, "Lastname" );
// Binding values using positional placeholders
q.( "insert into mytable (id, name, lastname) values (?, ?, ?)" );
q.( 0, 0 );
q.( 1, "Testname" );
q.( 2, "Lastname" );
// or alternatively
q.( "insert into mytable (id, name, lastname) values (?, ?, ?)" );
q.( "Testname" );
q.( "Lastname" );
See also , , , and .
Member Function Documentation
QSqlQuery::QSqlQuery ( &*&r )
Creates a QSqlQuery object which uses the
communicate with a database.
QSqlQuery::QSqlQuery ( const&&&&query = QString::null, &*&db = 0 )
Creates a QSqlQuery object using the SQL query and the database
db. If db is 0, (the default), the application's default
database is used.
See also .
QSqlQuery::QSqlQuery ( const&&&&other )
Constructs a copy of other.
QSqlQuery::~QSqlQuery () [virtual]
Destroys the object and frees any allocated resources.
void QSqlQuery::addBindValue ( const&&&&val )
Adds the value val to the list of values when using positional
value binding. The order of the () calls determines
which placeholder a value will be bound to in the prepared query.
Placeholder values are cleared after the query has been executed.
See also (), (), and ().
void QSqlQuery::afterSeek () [virtual protected]
Protected virtual function called after the internal record
pointer is moved to a new record. The default implementation does
int QSqlQuery::at () const
Returns the current internal position of the query. The first
record is at position zero. If the position is invalid, a
QSql::Location will be returned indicating the invalid position.
See also ().
Example: .
void QSqlQuery::beforeSeek () [virtual protected]
Protected virtual function called before the internal record
pointer is moved to a new record. The default implementation does
void QSqlQuery::bindValue ( const&&&&placeholder, const&&&&val )
Set the placeholder placeholder to be bound to value val in
the prepared statement. Note that the placeholder mark (e.g :)
should be included when specifying the placeholder name.
Placeholder values are cleared after the query has been executed.
See also (), (), and ().
void QSqlQuery::bindValue ( int&pos, const&&&&val )
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Set the placeholder in position pos to be bound to value val
in the prepared statement. Field numbering starts at 0.
Placeholder values are cleared after the query has been executed.
See also (), (), and ().
const&&* QSqlQuery::driver () const
Returns the database driver associated with the query.
bool QSqlQuery::exec ( const&&&&query ) [virtual]
Executes the SQL in query. Returns TRUE and sets the query
state to active if the
otherwise returns
FALSE and sets the query state to inactive. The query string
must use syntax appropriate for the SQL database being queried,
for example, standard SQL.
After the query is executed, the query is positioned on an invalid record, and must be navigated to a valid record before
data values can be retrieved, e.g. using ().
Note that the last error for this query is reset when () is
See also (), (), (), (), (), (), and ().
Examples: , , and .
bool QSqlQuery::exec ()
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Executes a previously prepared SQL query. Returns TRUE if the
query is e otherwise returns FALSE.
See also (), (), and ().
bool QSqlQuery::first () [virtual]
Retrieves the first record in the result, if available, and
positions the query on the retrieved record. Note that the result
must be in an active state and () must return TRUE before
calling this function or it will do nothing and return FALSE.
Returns TRUE if successful. If unsuccessful the query position is
set to an invalid position and FALSE is returned.
Example: .
bool QSqlQuery::isActive () const
Returns TRUE if the query otherwise returns
Examples: , , , , and .
bool QSqlQuery::isForwardOnly () const
Returns TRUE when you can only scroll forward through a result set
otherwise FALSE
bool QSqlQuery::isNull ( int&field ) const
Returns TRUE if the query is active and positioned on a valid
record and the field is NULL; otherwise returns FALSE. Note
that, for some drivers, () will not return accurate
information until after an attempt is made to retrieve data.
See also (), (), and ().
bool QSqlQuery::isSelect () const
Returns TRUE if the current query is a SELECT
otherwise returns FALSE.
bool QSqlQuery::isValid () const
Returns TRUE if the query is currently positioned on a valid
otherwise returns FALSE.
bool QSqlQuery::last () [virtual]
Retrieves the last record in the result, if available, and
positions the query on the retrieved record. Note that the result
must be in an active state and () must return TRUE before
calling this function or it will do nothing and return FALSE.
Returns TRUE if successful. If unsuccessful the query position is
set to an invalid position and FALSE is returned.
Example: .
QSqlQuery::lastError () const
Returns error information about the last error (if any) that
See also .
QSqlQuery::lastQuery () const
Returns the text of the current query being used, or
if there is no current query text.
bool QSqlQuery::next () [virtual]
Retrieves the next record in the result, if available, and
positions the query on the retrieved record. Note that the result
must be in an active state and () must return TRUE before
calling this function or it will do nothing and return FALSE.
The following rules apply:
If the result is currently located before the first
record, e.g. immediately after a query is executed, an attempt is
made to retrieve the first record.
If the result is currently located after the last record,
there is no change and FALSE is returned.
If the result is located somewhere in the middle, an attempt
is made to retrieve the next record.
If the record could not be retrieved, the result is positioned after
the last record and FALSE is returned. If the record is successfully
retrieved, TRUE is returned.
See also () and ().
Examples: , , , , , , and .
int QSqlQuery::numRowsAffected () const
Returns the number of rows affected by the result's SQL statement,
or -1 if it cannot be determined. Note that for SELECT statements,
this value will be the same as (). If the query is not active
(() returns FALSE), -1 is returned.
See also () and ().
&& QSqlQuery::operator= ( const&&&&other )
Assigns other to the query.
bool QSqlQuery::prepare ( const&&&&query )
Prepares the SQL query query for execution. The query may
contain placeholders for binding values. Note that placeholder
markers are usually database dependent.
See also (), (), and ().
bool QSqlQuery::prev () [virtual]
Retrieves the previous record in the result, if available, and
positions the query on the retrieved record. Note that the result
must be in an active state and () must return TRUE before
calling this function or it will do nothing and return FALSE.
The following rules apply:
If the result is currently located before the first record,
there is no change and FALSE is returned.
If the result is currently located after the last record, an
attempt is made to retrieve the last record.
If the result is somewhere in the middle, an attempt is made
to retrieve the previous record.
If the record could not be retrieved, the result is positioned
before the first record and FALSE is returned. If the record is
successfully retrieved, TRUE is returned.
See also ().
const&&* QSqlQuery::result () const
Returns the result associated with the query.
bool QSqlQuery::seek ( int&i, bool&relative = FALSE ) [virtual]
Retrieves the record at position (offset) i, if available, and
positions the query on the retrieved record. The first record is
at position 0. Note that the query must be in an active state and
() must return TRUE before calling this function.
If relative is FALSE (the default), the following rules apply:
If i is negative, the result is positioned before the
first record and FALSE is returned.
Otherwise, an attempt is made to move to the record at position
i. If the record at position i could not be retrieved, the
result is positioned after the last record and FALSE is returned. If
the record is successfully retrieved, TRUE is returned.
If relative is TRUE, the following rules apply:
If the result is currently positioned before the first
record or on the first record, and i is negative, there is no
change, and FALSE is returned.
If the result is currently located after the last record, and
i is positive, there is no change, and FALSE is returned.
If the result is currently located somewhere in the middle,
and the relative offset i moves the result below zero, the
result is positioned before the first record and FALSE is
Otherwise, an attempt is made to move to the record i
records ahead of the current record (or i records behind the
current record if i is negative). If the record at offset i
could not be retrieved, the result is positioned after the last
record if i >= 0, (or before the first record if i is
negative), and FALSE is returned. If the record is successfully
retrieved, TRUE is returned.
Example: .
void QSqlQuery::setForwardOnly ( bool&forward )
Sets forward only mode to forward. If forward is TRUE only () and
() with positive values are allowed for navigating the results.
Forward only mode needs far less memory since results do not have to be cached.
Forward only mode is off by default.
Note that it is not possible to use forward only mode with data aware widgets
since they need to be able to scroll backward.
See also () and ().
int QSqlQuery::size () const
Returns the size of the result, (number of rows returned), or -1
if the size cannot be determined or the database does not support
reporting information about query sizes. Note that for non-SELECT
statements (() returns FALSE), () will return -1. If
the query is not active (() returns FALSE), -1 is
To determine the number of rows affected by a non-SELECT
statement, use ().
See also (), (), and ().
Example: .
QSqlQuery::value ( int&i ) const [virtual]
Returns the value of the i-th field in the query (zero based).
The fields are numbered from left to right using the text of the
SELECT statement, e.g. in "SELECT forename, surname FROM
people", field 0 is forename and field 1 is surname. Using
SELECT * is not recommended because the order of the fields in
the query is undefined.
An invalid
is returned if field i does not exist, if
the query is inactive, or if the query is positioned on an invalid
See also (), (), (), (), (), (), and ().
Examples: , , , , , , and .
This file is part of the .
Copyright &
. All Rights Reserved.
Copyright & 2003
Qt version 3.1.2vb 中 isNull()这个函数怎么用阿?_百度知道
vb 中 isNull()这个函数怎么用阿?
提问者采纳
&quot。 MyVar = &quot。 Dim MyVar,判断参数对象是否为空(指出表达式是否不包含任何有效数据), MyCheck MyCheck = IsNull(MyVar) ' 返回 False,若是,返回true: 本示例使用 IsNull 函数检查变量值是否为 Null,否则返回false. 比如IsNull是一个内部函数。 MyVar = Null MyCheck = IsNull(MyVar) ' 返回 F MyCheck = IsNull(MyVar) ' 返回 True
提问者评价
其他类似问题
4人觉得有用
为您推荐:
其他1条回答
IsNull 函数
返回 Boolean 值,指出表达式是否不包含任何有效数据 (Null)。
IsNull(expression)
必要的 expression 参数是一个 Variant,其中包含数值表达式或字符串表达式。
如果 expression 为 Null,则 IsNull 返回 True;否则 IsNull 返回 False。如果 expression 由多个变量组成,则表达式的任何作为变量组成成分的 Null 都会使整个表达式返回 True。
Null 值指出 Variant 不包含有效数据。Null 与 Empty 不同,后者指出变量尚未初始化。Null 与长度为零的字符串 (““) 也不同,长度为零的字符串指的是空串。
重要 使用 IsNull 函数是为了确定表达式是否包含 Null 值的。在某些情况下,希望表达式取值为 True,比如希望 If Var = Null 和 If Var && Null 取值...
isnull的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁您所在的位置: &
SQL Server数据库ISNULL函数的应用实例
SQL Server数据库ISNULL函数的应用实例
本文我们主要介绍了SQL Server数据库ISNULL函数的应用实例,通过这些实例让我们来了解一下ISNULL函数的使用吧,希望能够对您有所收获!
SQL Server数据库ISNULL函数的使用是本文我们主要要介绍的内容,我们通过实例来说明ISNULL函数的使用,接下来我们就开始介绍这部分内容。
1.利用ISNULL函数干掉OR运算!
题目是查询表中VAL小于20的值,包括NULL值:
SELECT&*&FROM&T&WHERE&ISNULL(VAL,-1)&&&SELECT&*&FROM&T&WHERE&VAL&IS&NULL&OR&VAL&&&
两个SQL具有相同的输出结果
GRP_A&GRP_B&GRP_C&VAL &----
----- ----- ---&a1&b1&c1&10 &a1&b1&c2&10 &a2&b3&c3&NULL &a2&b3&c3&NULL &a2&b3&c3&NULL &(5&行受影响)&
GRP_A&GRP_B&GRP_C&VAL &----&------&----&&-- &a1&b1&c1&10 &a1&b1&c2&10 &a2&b3&c3&NULL &a2&b3&c3&NULL &a2&b3&c3&NULL &(5&行受影响)&
2.ISNULL非主流更新表存储过程示例
如某更新表存储过程如下:
CREATE&PROC&UpdateT( &@ID&INT, &@GRP_A&VARCHAR(10)&=&NULL, &@GRP_B&VARCHAR(10)&=&NULL, &@GRP_C&VARCHAR(10)&=&NULL, &@VAL&INT&=&0&)AS &BEGIN &UPDATE&T&SET& &GRP_A&=&@GRP_A, &GRP_B&=&@GRP_B, &GRP_C&=&@GRP_C, &VAL&=&@VAL &WHERE&ID&=&@ID &END&
当我们使用这个存储过程的时候,必须先得该行的所有记录,再把所有记录更新回去,可是这并不总是必须的。有时候手头只有两个数据:ID和VAL,我只想更新这个VAL,又有时候手头有另外两个数据:ID和GRP_A,这时候只更新GRP_A列即可。还有很多情况,如:
仅更新GRP_A,
仅更新GRP_A,GRP_B
仅更新GRP_A,GRP_B,GRP_C
仅更新GRP_A,GRP_B,GRP_C,VAL
这样的组合太多了,要想一劳永逸解决问题那就得更新任何字段前,先得到整行记录,再整行更新回去,于是多了一项工作:先查询,再更新,那没有办法不先查询直接更新某一列呢?而且列可以任意组合?
在给出答案前,先声明一句:这个方法算不上完美解决方案,仅仅是个思路罢了,虽然我一直认为没什么影响,但如果要在正式项目中使用,建议还是多听听DBA的意见!
非主流更新任意列存储过程:
CREATE&PROC&UpdateT( &@ID&INT, &@GRP_A&VARCHAR(10)&=&NULL, &@GRP_B&VARCHAR(10)&=&NULL, &@GRP_C&VARCHAR(10)&=&NULL, &@VAL&INT&=&0&)AS &BEGIN &UPDATE&T&SET& &GRP_A&=&ISNULL(@GRP_A,GRP_A), &GRP_B&=&ISNULL(@GRP_B,GRP_B), &GRP_C&=&ISNULL(@GRP_C,GRP_C), &VAL&=&ISNULL(@VAL,VAL) &WHERE&ID&=&@ID &END&
关于SQL Server数据库ISNULL函数的应用实例就介绍到这里了,如果您想了解更多SQL Server数据库的知识,可以看一下这里的文章:,希望本次的介绍能够对您有所收获!
【编辑推荐】
【责任编辑: TEL:(010)】
关于&&的更多文章
不管你有没有准备好,新版SQL Server来了!代号为Denali的下一个
数据库产品
数据库综合
数据库新闻
维基百科将切换到另外一款开源数据库MariaDB
生活中,有各种点滴的时间值得我们去记录,这个专题主
这一专题主要是讨论关于数据库设计的内容,包含数据库
本专题将带领大家走入MongoDB的世界,了解MongoDB是怎
公钥基础设施PKI(Public Key Infrastructure)是利用公钥概念和加密技术为网上通信提供的符合标准的一整套安全基础平台。公钥基
51CTO旗下网站

我要回帖

更多关于 函数后面加const 的文章

 

随机推荐