All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
Delphi菜单动态合并实例
sql,server,2005中新增的bulk功能_[SQL,Server教程]
js也可以有自定义事件,注入就是这么爽_.net资料_编程技术
ASP.NET2.0,WebRource,开发微调按钮控件_[Asp.Net教程]
ASP.NET实现图象处理详解_[Asp.Net教程]
ASP.NET中为DataGrid添加单选框_[Asp.Net教程]
来!把我的Blog数据转移到X-Space里_php资料_编程技术
php,函数GetImageSize_php资料_编程技术
预载入和javascript,Image()对象_JavaScript技术_编程技术
ASP.NET,2.0中客户端脚本使用总结_.net资料_编程技术
Reading number is top 10 pictures
NeedWallpaper6
The service WaLiangGe Chinese aircraft carrier1
到南昌西站了3
The money of more than 100 countries and regions9
银行20年后可能消失
Female model behind the bitterness, often being overcharged1
2012 national geographic daily picture7
张家界的玻璃桥
The real super beauty8
Black and white also sexy--YanLiu2
Download software ranking
VC++6.0简体中文版
传奇私服架设教程
尖东毒玫瑰B
中国结婚习俗实录
Tram sex maniac 2 (H) rar bag4
Unix video tutorial8
I'm come from Beijing2
The Bermuda triangle2
传奇私服架设教程
apache-tomcat-6.0.33
delv published in(发表于) 2013/12/30 4:40:13 Edit(编辑)
SQL语法总结_mssql学习_编程技术

SQL语法总结_mssql学习_编程技术

SQL语法总结_mssql学习_编程技术-你的首页-uuhomepage.com
SQL语法总结
1.按条件读取字段, 定义某个字段只取规定的几个值,或一个值
select os.* from blis_order o,blis_orderservice os where o.orderid=os.orderid and o.ordertypeid not in (4, 8, 10, 11) and o.status in ('New','Accepted','Pending-approval','Pending-effective','Pending-correction') and snp.status='Active' and b.entityid=1
2.去掉重复(互异)的字段distinct
select distinct op.name,op. from blis_chargeactivation ca,blis_orderparameter op where op.mastertype='charge' and ca.chargeactivationid=op.masterid and ca.parentcode like '%NBR Storage Charge%'
3.某个字段不可为null
select os.orderserviceid,os.orderofferid,o.ordertypeid,o.status from Blis_Order o, Blis_Orderservice os where o.orderid=os.orderid and os.orderofferid is not null
4.删除满足某个条件的记录
delete from blis_bstoffermigplan bsf where bsf.keyid='110206'
5.取name_a字段,放入字段别名name_b
select bsf.keyid subcode,bsf.bstoffermigplanid from blis_bstoffermigplan bsf
这里取的是keyid字段, 显示的为subcode字段。
6.connection rollback commit
rollback 就是把在内存中做的行为取消,不持久化到数据库中,commit就是把内存中做的行为持久化到数据库中。
7. 在Oracle中使用Dual, Dual是Oracle一个特有的虚拟表, Oracle中很多系统的sequence(序列),sequence一般和表建立了一一对应关系,但是要编程插入的话,必须手工指定,比如增加条account数据,相应的值插入SEQ_ACCOUNT.nextval,变量和函数都可以通过Dual中获得
S: select getdate();
O: select sysdate from dual;
select SEQ_INTEGRATIONTASK.NEXTVAL from DUAL
8.(PK)主键(PK) (for database)
9.排序(数字,字母由大到小)
select bsf.* from blis_bstoffermigplan bsf order by bsf.ordertypeid 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_bstoffermigplan.nextval, ?, ?, ?, ?, ?,?, ?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?,sysdate, ?, sysdate)
11,更新一条记录
update offermigplan.db_table_name 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(acc.lastmodifieddate,'YYYYMMDD')>'20050101'
select * from blis_account acc where acc.lastmodifieddate>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 having 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(ob.bookingvalue,0) bookingvalue from blis_order o, blis_orderbooking ob where o.orderid=ob.orderid and o.orderid =125034 and ob.bookingtypeid = 215 and ob.status = 'Active'
这里关心nvl的用法,nvl(arg,value)代表如果前面的arg的值为null那么返回的值为后面的value
16.知道一个column的名字,但不清楚它属于哪张table时,可以使用
select * from user_col_comments ucc where ucc.column_name = 'column_name'
比如: select * from user_col_comments ucc where ucc.column_name = ‘ORDERID’ 就会查出一系列有ORDERID字段的表。
17.遍历两字段排列
select (pf.offername || ' '|| cur.name) offercode from blis_packageoffer pf,blis_currency cur where cur.status='Active' and pf.status='Active'
结果如下:
offercode
a1 b1
a1 b2
a2 b1
a2 b2
18.条件判断
case when pc.provisioningby = 'BPS' then 'True'
else 'False' end
select sos.Sosorderserviceid, st.sosprovisionticketid,
(case when pc.provisioningby = 'BPS' then 'True'
else 'False' end) isConnector
from blis_sosprovisionticket st, blis_sosorderform sof,
blis_sosorderservice sos, blis_packagecomponent pc
where sof.sosorderformid = sos.sosorderformid
and sos.sosorderserviceid = st.sosorderserviceid
and sos.status = 'Active' and st.status = 'Active'
and pc.tagname(+) = st.servicetag and pc.provisioningby
and sof.sosorderformid = 104789
19. pc.tagname(+) =st.servicetag
当pc.tagname存在值,st.servicetag不存在值的话,记录也可以检索出来。
20.让表可以手工编辑
select rowid,st.* from blis_sosprovisionticket st where st.sosprovisionticketid=102508
用classes12.zip 还是会抛出classNotFoundException:oracle.jdbc.driver.OracleDriver,换用class12.jar就正常了,classes12.zip 或class12.jar是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=d:1.dmp
连接ORACLE数据库的字符串格式是
jdbc:oracle:thin:@主机:端口:SID
注意是SID 而不是数据库名
SID不对的话会抛出异常:java.sql.SQLException: Io 异常: Connection refused(DEION=(TMP=)(VSNNUM=153092352)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))




添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.