1、 时间查询语句
select * from table where date= to_date('20xx-01-27','yyyy-mm-dd')
2、 单引号、双引号
数字不需要
字符串用单引号
双引号一般是用来转义的,如果alias里面有空格或其它保留符号,必须使用双引号。 而单引号是用来特制的,比如字符串的引用,日期字符串的引用,都必须包括在单引号中,可以参与运算或其它表达式中。两者不可混用,其中,两个单引号可以作为单引号的转义使用,意思就是一个真正的、没有特殊功能的单引号。例如 select substr('I''am a pig',1,4)。
3、 UPDATE
UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值
业务受理子系统BSS中,
--客户资料表
create table customers
(
customer_id number(8) not null, -- 客户标示
city_name varchar2(10) not null, -- 所在城市
customer_type char(2) not null, -- 客户类型
...
)
create unique index PK_customers on customers (customer_id)
由于某些原因,客户所在城市这个信息并不准确,但是在
客户服务部的CRM子系统中,通过主动服务获取了部分客户20%的所在
城市等准确信息,于是你将该部分信息提取至一张临时表中:
create table tmp_cust_city
(
customer_id number(8) not null,
citye_name varchar2(10) not null,
customer_type char(2) not null
)
1) 最简单的形式
--经确认customers表中所有customer_id小于1000均为'北京'
--1000以内的均是公司走向全国之前的本城市的老客户:)
update customers
set city_name='北京'
where customer_id<1000
2) 两表(多表)关联update -- 仅在where字句中的连接
--这次更新的数据都是VIP,且包括新增的,所以顺便更新客户类别
update customers a -- 使用别名
set customer_type='01' --01 为vip,00为普通
where exists (select 1
from tmp_cust_city b
where b.customer_id=a.customer_id
)
3) 两表(多表)关联update -- 被修改值由另一个表运算而来
update customers a -- 使用别名
set city_name = (select b.city_name from tmp_cust_city b
b.customer_id=a.customer_id)
where exists (select 1
from tmp_cust_city b
where b.customer_id=a.customer_id
)
4、插入insert into
insert into table-name (字段名1,字段名2) values (‘字段值1’,‘字段值2’) 4、 delete
① DELETE FROM COURSES WHERE COURSE_DESIGNATER = 'Java110' where
② DELETE FROM CLASSCONVENINGS WHERE CLASSES_NUM_FK > 4 AN
D CLASS_CONVENE_DATE = TO_DATE('20xx-02-15 00:00:00','YYYY-MM-DD HH24:MI:SS') AND CLASS_LOCATION_FK = 'Seattle-Training Room 1'
5、删除这些具有重复字段的数据记录:
delete from tableName a where 字段1,字段2 in (select 字段1,字段2,count(*) from tableName group by 字段1,字段2 having count(*) > 1)
6、 修改表列名等信息
alter table [table_name] rename column [column_name] to [new_column_name]
ALTER TABLE SCOTT.TEST RENAME TO TEST1--修改表名
ALTER TABLE SCOTT.TEST RENAME COLUMN NAME TO NAME1 --修改表列名
ALTER TABLE SCOTT.TEST MODIFY NAME1 NUMBER(20) --修改字段类型
ALTER TABLE SCOTT.TEST ADD ADDRESS VARCHAR2(40) --添加表列
ALTER TABLE SCOTT.TEST DROP NAME CASCADECONSTRAINTS --删除表列
第二篇:Oracle语句总结
1£¬¸ù¾ÝÒ»¸ö±íµÄÁУ¬¸üÐÂÁíÒ»¸ö±íµÄÁÐ
update orderplan_plan_items a
set (a.itemcode,a.itemname)=(select b.code,b.name from corp_productitems b where a.itemid=b.id)
where a.orderplanid=(select id from orderplan_order_plans where code = '2010060814')
2£¬µ¼³öÖ¸¶¨µÄ±í¶¨Òå¼°Êý¾Ý
exp newsboard/newsboard@IMPORT file=d:\newsboard.dmp tables=(aa, app_user, bb, category, contract, news, news_review, payment, plan_table, project, requestdetail, requesttable, student, studentbak, test, testgroup, testuser, typeuser, usergroup)
3£¬½«Ò»¸öÓû§ËùÊôµÄÊý¾Ýµ¼ÈëÁíÒ»¸öÓû§
imp system/bidlink@IMPORT file=d:\newsboard.dmp log=d:\newsboard.log fromuser=newsboard touser=jpetstore
4£¬É¾³ýÒ»¸ö±íµÄËùÓмǼ
truncate table tableXX
2£¬
Oracle expÃüÁî³£ÓÃÓ÷¨
1 ½«Êý¾Ý¿âTESTÍêÈ«µ¼³ö,Óû§Ãûsystem ÃÜÂëmanager µ¼³öµ½D:\daochu.dmpÖÐ
exp system/manager@TEST file=d:\daochu.dmp full=y
2 ½«Êý¾Ý¿âÖÐsystemÓû§ÓësysÓû§µÄ±íµ¼³ö
exp system/manager@TEST file=d:\daochu.dmp owner=(system,sys)
3 ½«Êý¾Ý¿âÖеıíinner_notify¡¢notify_staff_relatµ¼³ö
exp aichannel/aichannel@TESTDB2 file= d:\data\newsmgnt.dmp tables=inner_notify,notify_staff_relat)
4 ½«Êý¾Ý¿âÖеıítable1ÖеÄ×Ö¶Îfiled1ÒÔ"00"´òÍ·µÄÊý¾Ýµ¼³ö
exp system/manager@TEST file=d:\daochu.dmp tables=(table1) query=\" where filed1 like '00%'\"
oracleÖÐimpÃüÁîÏê½â
1. »ñÈ¡°ïÖú
imp help=y
2. µ¼ÈëÒ»¸öÍêÕûÊý¾Ý¿â
imp system/manager file=bible_db log=dible_db full=y ignore=y
3. µ¼ÈëÒ»¸ö»òÒ»×éÖ¸¶¨Óû§ËùÊôµÄÈ«²¿±í¡¢Ë÷ÒýºÍÆäËû¶ÔÏó
imp system/manager file=seapark log=seapark fromuser=seapark imp system/manager file=seapark log=seapark fromuser=(seapark,amy,amyc,harold)
4. ½«Ò»¸öÓû§ËùÊôµÄÊý¾Ýµ¼ÈëÁíÒ»¸öÓû§
imp system/manager file=tank log=tank fromuser=seapark touser=seapark_copy imp system/manager file=tank log=tank fromuser=(seapark,amy) touser=(seapark1, amy1)
5. µ¼ÈëÒ»¸ö±í
imp system/manager file=tank log=tank fromuser=seapark TABLES=(a,b)
6. ´Ó¶à¸öÎļþµ¼Èë
imp system/manager file=(paycheck_1,paycheck_2,paycheck_3,paycheck_4) log=paycheck, filesize=1G full=y
7. ʹÓòÎÊýÎļþ
imp system/manager parfile=bible_tables.parbible_tables.par²ÎÊýÎļþ£º
#Import the sample tables used for the Oracle8i Database Administrator's Bible. fromuser=seapark touser=seapark_copy file=seapark log=seapark_import
8. ÔöÁ¿µ¼Èë
imp system./manager inctype= RECTORE FULL=Y FILE=A