本人刚接触ORACLE数据库,总结一些实用语法及解决方案:
ORACLE SELECT语句使用注意点:
1、字段的合并显示
通常SQL SERVER字段显示合并,我们使用的是'+',例如:
SELECT a+'-'+bas ab FROM TABLE
而ORACLE的字段合并显示,使用的就不是'+',而是'||',例如:
SELECT a||'-'||as ab FROM TABLE
2、数据库的导出(备份):
cmd:
exp USER/password@databaeServername owner=USER direct=y file=存放路径.dmp //导出
--USER当前连接DB的身份
--password连线密码
--databaeServername连线数据库
--owner表示导出该身份的所有Table
导出 EXP USER/PASSWORD@databaeServername FILE=存放路径.DMP ROWS=N //不保存数据;
导出 EXP USER/PASSWORD@databaeServername FILE=存放路径.DMP //保存数据;
导出 EXP USER/PASSWORD@databaeServername FILE=存放路径.DMP full=y //全部导出;
导出数据库中部分Table的语法
将数据库中的表Table1、Table_2导出
exp user/password@databaeServername file=存放路径.dmp tables=(Table1,Table_2)
将数据库中的表table1中的字段filed1以"00"打头的数据导出
exp system/manager@TEST file=存放路径.dmp tables=(table1) query=\" where filed1 like '00%'\"
3、数据库导入(还原):
cmd:
imp newtype/newtype@esmt fromuser=flowuser touser=newtype file=d:\flow.dmp ignore=y
4、from dual用法
ORACLE: select sysdate from dual----获取系统时间
SQL SERVER:select getdate()
oracle中一定加from dual这个代码
序列:
(1).可以为表中的列自动产生值.
(2).由用户创建数据库对象,并可由多个用户共享.
(3).一般用于主键或唯一列.
例子:
createsequence my_seq ---创建序列名
start with1 ---从1开始
increment by1 ---每次增长1
maxvalue999999999 ---最大值
minvalue1 ---最小值
cycle ---循环
cache ---缓存
order
从1开始,每次增长1,最大值为999999999,之后又循环从1开始.
SQL语句:
insert intomytable values(my_seq,'aaa')
insert intomytable values(my_seq,'bbb')
结果为:
1 aaa
2 bbb
调用:
selectmy_seq.nextval from mytable ---新值
selectmy_seq.currval from mytable ---当前值
********************************************************************
第一步:创建SEQUENCE
create sequence s_country_id increment by 1 start with 1 maxvalue 999999999;
第二步:创建一个基于该表的before insert 触发器,在触发器中使用该SEQUENCE
create or replace trigger bef_ins_t_country_define
before insert on t_country_define
referencing old as old new as new for each row
begin
select s_country_id.nextval into :new.country_id from dual;
end;
(insert 时就不用关心自动增长列了)
5.发现监听器没有启动的解决办法:
cmd:
执行:lsnrctl
然后:start