SQL语法总结

发布 2021-05-11 05:13:28 阅读 3028

1.按条件读取字段, 定义某个字段只取规定的几个值,或一个值。

select os.* from blis_order o,blis_orderservice os where and not in (4, 8, 10, 11) and in (‘new','accepted','pending-approval','pending-effective','pending-correction’) and 'active' and

2.去掉重复(互异)的字段distinct

select distinct from blis_chargeactivation ca,blis_orderparameter op where 'charge' and and like '%nbr storage charge%'

3.某个字段不可为null

select from blis_order o, blis_orderservice os where and is not null

4.删除满足某个条件的记录。

delete from blis_bstoffermigplan bsf where '110206'

5.取name_a字段,放入字段别名name_b

select subcode, from blis_bstoffermigplan bsf

这里取的是keyid字段, 显示的为subcode字段。

rollback commit

rollback 就是把在内存中做的行为取消,不持久化到数据库中,commit就是把内存中做的行为持久化到数据库中。

7. 在oracle中使用dual。dual是oracle一个特有的虚拟表, oracle中很多系统的sequence(序列),sequence一般和表建立了一一对应关系,但是要编程插入的话,必须手工指定,比如增加条account数据,相应的值插入seq_变量和函数都可以通过dual中获得。

s: select getdate();

o: select sysdate from dual;

select seq_ from dual

8.(pk)主键(pk) (for database)

9.排序(数字,字母由大到小)

select bsf.* from blis_bstoffermigplan bsf order by desc

10.插入一条记录。

insert into blis_bstoffermigplan (bstoffermigplanid, entityid, keyid, subioncode, ordertypeid, type, templatecode, currencycode, exceptioncount, lastexception, att1, att2, att3,att4,att5,offercode, status, createdby, creationdate, lastmodifiedby, lastmodifieddate) values (seq_ ?sysdate)

11,更新一条记录。

update set entityid=?,keyid=?,subioncode=?

,ordertypeid=?,type=?,templatecode=?

,currencycode=?,exceptioncount=?,lastexception=?

,att1=?,att2=?,att3=?

,att4=?,att5=?,offercode=?

,status=?,createdby=?,lastmodifiedby=?

,lastmodifieddate=sysdate where bstoffermigplanid=?

12.插入数据量比较大的类型clob

13.查询日期。

下列两条语句功能相同。

select * from blis_account acc where to_char('yyyymmdd‘)>20050101'

select * from blis_account acc where >to_date('2005-01-01','yyyy-mm-dd’)

14.找出根据某个字段中的值重复的记录。

比如找出chargeactivationid 有相同值的blis_usageaccess记录。

select * from blis_usageaccess where chargeactivationid in (select chargeactivationid from blis_usageaccess group by chargeactivationid h**ing count(*)1)

usageaccessid chargeactivationid serviceaccesscode

292518 148701 audio-broadcast@

292517 148701 voip@

292516 148701 callin-did@

292515 148701 callback-intl@

292512 148701 callin@

292513 148701 callin-tollfree@

292514 148701 callback@

292478 147945 audio-broadcast@

292477 147945 voip@

292475 147945 callback-intl@

292476 147945 callin-did@

292472 147945 callin@

15.通过查询获得某个字段的合计值,如果这个值位null将给出一个预设的默认值。

select nvl( bookin**alue from blis_order o, blis_orderbooking ob where and =125034 and = 215 and = active'

这里关心nvl的用法,nvl(arg,value)代表如果前面的arg的值为null那么返回的值为后面的value

16.知道一个column的名字,但不清楚它属于哪张table时,可以使用。

select * from user_col_comments ucc where = column_name'

比如: select * from user_col_comments ucc where = orderid' 就会查出一系列有orderid字段的表。

17.遍历两字段排列。

select ( offercode from blis_packageoffer pf,blis_currency cur where 'active' and 'active'

结果如下:offercode

a1 b1a1 b2

a2 b1a2 b2

18.条件判断。

case when = bps' then 'true'

else 'false' end

select

case when = bps' then 'true'

else 'false' end) isconnector

from blis_sosprovisionticket st, blis_sosorderform sof,blis_sosorderservice sos, blis_packagecomponent pc

where =

and =

and = active' and = active'

and = and

and = 104789

当存在值,不存在值的话,记录也可以检索出来。

20.让表可以手工编辑。

select rowid,st.* from blis_sosprovisionticket st where

用 还是会抛出classnotfoundexception:换用就正常了, 或是jdbc oracle驱动类。

创建数据库:

查看所有表: select * from dba_all_tables

查看所有用户: select * from all_users

查看所有dba用户:select * from dba_users

创建role :create role blis_admin_role;

创建新用户:create user username identified by password

授予表空间使用权:grant resource to username

授予创建表权限:grant create table to username

授予连接数据库的权限:grant create session to username

查看所有表空间: select * from dba_tablespaces

把任何表授予某用户: grant create any table to blis_admin_role;

授予某用户检索功能:grant create any index to blis_admin_role;

授予某用户对某表有检索,插入,更新,删除功能:grant select, insert, update, delete on blis_accagencycommission to blis_admin_role;

导出数据库:比如: exp blis/blis@dbls full=y file=

连接oracle数据库的字符串格式是。

jdb cracle:thin主机:端口:sid

注意是sid 而不是数据库名。

sid不对的话会抛出异常: io 异常: connection refused(deion=(tmp=)(vsnnum=153092352)(err=12505)(error_stack=(error=(code=12505)

sql语法

知识要点 1 transact sql运算符 1 算术运算符。注 null与任何值运算结果为null。运算可用于datetime型数据。2 字符串运算符。3 比较运算符。逻辑常量 ture false。4 逻辑运算符。not 非 and 与 or 或 between 指定范围 like 模糊匹配 5...

SQL语法

distinct 输出唯一值。select distinct from where between and 介于某一范围的数据。where 某行 between and in 属于某一子集合的数据。where 某行 in substring expression 开始位 长度 选取字符串。selec...

SQL语法

一 create table 数据表是数据库中储存数据的基本架构。举例来说,如果我们有一个记载顾客数据的数据表,那字段包括姓名 地址 城市 国家 生日 等等。当我们对数据表下定义时,我们需要注明字段名称,以及那个字段的类型。字段类型可能是一个整数 例如 1 一个实数 例如 0.55 一个字符串 例如...