一、Select
字段列表
From
数据表
例:1、select
id,gsmc,add,tel
from
haf
(*
表示数据表中所有字段)
2、select
单价,数量,单价*数量
as
合计金额
from
haf
(As
设置字段的别名)
二、Select
…
from
…
Where
筛选条件式
例
筛选条件式:
1、字符串数据:
select
*
from
Where
姓名='李明'
2、万用字符:
select
*
from
成绩单
Where
姓名
like
'李%'
select
*
from
成绩单
Where
姓名
like
'%李%'
select
*
from
成绩单
Where
姓名
like
'%李_'
3、特殊的条件式:1.=
/
>
/
<
/
<>
/
>=
/
<=
2.AND逻辑与
OR逻辑或
NOT逻辑非
3.Where
字段名称
in(值一,值二)
4.Where
字段名称
Is
Null
/
Where
字段名称
Is
Not
Null
通过使用select count(*) 的方式判断当前表是否存在,返回1则代表存在,0则代表不存在,例如:SELECT COUNT(*) FROM User_Tables WHERE table_name = 'CODE_BMDM'(在SQL中使用这种方法亦可)
需要注意的是:表名(或者其他对象名)必须全部大写,有特殊字符的除外(表名之间有空格等特殊字符),否则查询不到。
其中的 User_Tables(用户下的所有表) 也可以换成dba_tables(管理员权限下的所有表) 或者all_tables(所有表)
1.直接对数据库表进行 *** 作,如查询 *** 作,数据库表不存在则会抛出异常。如果收到异常则可以进行后续的建表 *** 作了。2.读取数据库中表名列表,看表是否在其中,代码如下:
//java获取数据库中所有表名,判断某个表是否在数据库中存在
connection = DriverManager.getConnection(mySqlDbUrl, "", "") DatabaseMetaData meta = (DatabaseMetaData)connection.getMetaData() ResultSet rs = meta.getTables(null, null, "table", null)//table为表名 if(rs.next()){ System.err.println(true) }else{ System.err.println(false) } rs.close() connection.close()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)