Oracle入门

来源:互联网 发布:mac的itunes怎么用 编辑:程序博客网 时间:2024/06/06 20:27

安装

没碰啥问题,就96%的时候多等会。安装版本“ 12c 标准版 桌面类型”

启动连接

1、没用SQL plus,也不会用。直接SQL developer

2、连接名:orcl;用户名system;口令略。连接类型设成TNS;网络别名orcl,就可以连接了,/*为什么我也不知道*/

3、觉得在oracle工作表挺好的,为什么要有PL/SQL这么单调的插件呢?

_____________________________________________________________________________________________________

安装

最好还是安装11g……,12c玩不动。

oracle自带的developer是64位的,因为oracle 11gr2不支持64位的develper吧。

————————————————————————————————————

sid:系统标识符,可以理解为你所连接的一个数据库实例的名称。
tns:Transparance Network Substrate,透明网络底层。一般是用它提供的监听服务。

basic,他和tns可以ping。然后用basic连arcl

(可以sid orcl也可以服务名orcl)
你創建數據庫的過程中,它會提示你設置SID,端口等等:)
sid:
数据库实例标示,也就是数据库实例的名称,在控制面板-管理工具-服务,打开这个文 件,你可以看到一个OracleServicexxx,其中"xxx",就是你的数据库实例的名称 ,也就是sid.
tns:数据连接字符串,代表一个数据库的连接,配置好你的数据网络连接,就会有一个这样的串。这个串可以在你的oracle安装根目录ora92 etworkadmin nsnames.sql里面找到,你要可以在你的oracle安装目录下查找这个文件,

_______________________________________________________________
多种种方式访问
1、127.0.0.1:5560/isqlplus
2、192.168.0.99:5560/isqlplus 无需客户端
3、PL/SQL    客户环境
4、tod
5、devloper  公司环境
_____________________20160720________________________________
数据对象(表、试视图,序列,函数,过程,包,触发器)
sql语句调用DBMS
——————————————————————————
sys(超级管理员)
system(管理员)
scott(一般用户)权限大小 
sa账户设置权限有问题 密码都是sa。。。。
————————————————————————————————
解锁 alter user sa account unlock
————————————————————
3种编辑器
1、启动OracleDBConsole可以使用web版http://1158/em
database Object
______________________________
/conn  sa/sa
/disc
/exit
/show user
spool on ;选择;spool  off;
set linesize/pagesize;貌似没啥用
____________________________________
create user identified by sa
1、一百多种系统权限
grant connect to maibo
grant resource to maibo
grant create session to user
             table
             index
             view
             sequence
             trriger
2、对象(表)权限UIDC
revoke …… from
#当上出一个数据对象时,删除用户时要加(cascade);
否则freeze用户
——————————————————————
oracle一个数据库实例(方案schama),不同的用户看的是不一样的表
方案类似独立卫浴吧,SQL server是公共浴室
grant select[update|all]  on emp to sa;
查询药袋方案名
//with grant option
//with admin option
______________profile___________________
create profile muprofile failed_login_attempts 3
                         password_lock_time 2
                         password_life_time 10
                         password_grace _time 2; 
                         limit password_life_time 10
alter user maibo profile myprofile;
一般账户创建后默认profile为dufault?
select * from dba_profiles order by PROFILE;
——————————启动流程——————————————
lsnrctl start
oridim-startup-sid(实例)  终于弄懂了
net start oracleserviceorcl
SID : System Identifier for the Database Instance (Oracle)   系统标识符的数据库实例(甲骨文)
———————————特权用户———————————————
oracle有一个组,只要在组里面,就不要密码,而且再登录时不要用户名和密码。——这样安全吗??
修改sqlnet.ora文件可以特权用户也用验证
——————————找sys密码————————————————————
找pwd.ora备份,删掉
dos:orapwd file=D:\app\Mai_Bo\product\11.2.0\dbhome_1\database\PWDorcl.ora  password=sa entries=10
=========================二章。类与表的对应====20160724==================================
users.setId(1);
oracle的数值类型只有一个number?
select dump(name) from table1
char(2000);varchar2(4000)
clob(character large objcet)
blob(binary)
number(p,s) number(4,-2)
date的时间格式很特别
1、delete:可回滚savepoint aa→rollback aa;
2、truncate:不可回滚
只有‘’里的内容区分大小写
——————————————————————————
sal+nvl(comm,0)为空问题/以前是isnull
拼接select sal||comm from emp作为一列
锁用户,用其表
alter user scott account unlock
__________________复杂查询 20160725__________________________
select * from emp where to_char(hiredate,'yyyy-mm')='1981-09';
between and闭区间
ename like 'S%'
in (123,400,800)
聚合函数三件套
group by=“每一个”,前面要有聚合函数,having相当于where,一定要注意逻辑,where和group的对应性
select emp.deptno,emp.job,dept.loc,avg(sal) from emp,dept
                                            where emp.deptno=dept.deptno
                                            group by emp.deptno,emp,job,dept.loc
                                            having avg(sal)>1000 order by emp.job;
where 后面跟between的,蛮神奇的
sal>ALL()格式
sal>any()格式
多列子查询:应该很有用
select * from emp where (deptno,job)=(select deptno,job from emp where ename='smith')
from 子查询和where 子查询——临时表的概念
左外联,右边加(+)
小技巧:int a=(1==b?2:5)
表1 inner join 表1……on《==》表1,表2 where
完全外联full outer join
———————————分页查询————————————————————
rownum
sql server 是top not in
oracle是分3层,rownum有别名
蠕虫复制
————————————————
union/union all  并集
intersect  交集
minus 差集
————其它函数————
group by cube()
==========================java调用oracle====================================
创建数据实例    
2、数据库标识和数据库SID基本是一个概念
3、所有用户使用同一口令/也可以不同口令/
4、存储在Oracledata的位置
5、两个SID时,药用主机字符串登录
————————————
*DriverManager是是加载驱动书与JVM的任务,所以属于类,不属于接口
到PreparedStatement就是借口了,ReslutSet是接口
1、DDL-create table
2、DML-insert
3、DQL-select
4、DTL-commit,rollback
_______————————___java的其他知识————————————_____________
1、commit函数?
2、public class必须在自己的文件中*/
3、para参数的意思
4、setString()函数的意思
5、参数.length不是数值怎么弄?
to_date函数等67个函数都要掌握
_____________________ODBC总结___________________________________
1、SqlHelper有select,执行select时有while,但RUD不在helper里切不用while
2、SqlHelper在一个类,其他都一函数的形式做
3、注意close十几,以及=null
4、getString其实是有问题的
5、CUD可以在主函数里写
———————JDBC-ODBC方法———————————
系统工具-设置,后面就不用用户名了
===============函数=========================================
concat(ename,'是好人')
initcap(第一个大写,其他小写)
instr(c1,c2,i,j)(搜索位置)
Lpad(‘page 1’,15,'*.')(左填充)
select trim(0 from 0000119222011111) from dual;
exp(3)(e的3次方根)
mod(5,2)取模
round(28.3)四舍五入
trunc(55.5,-1)截取
Add_months(date, months)
to_char(9/0/,/./$/L/C/G/D)
decode(deptno ,10, '10号')
avg(all|deitinct sal) from
_____________7个系统函数__________________
select sys_context('userenv','db_name') from dual;
____________________________________________
有时间研究研究驱动
============事务=============
脏读,每次刷出来的票都一样,
不可重复读,每次刷出来的票不一样,
幻读,因为insert,每次刷出来的票不一样
===============约束==========
5种
unique可以多个空?
primary key会 自动创建索引?
______________sequence____________
--多列添加?
--modify not null
--如何查询约束?
--多列修改?
--修改属性?
--如何多列定位插入?
_____________index__权限角色________________
HASH算法,做索引值
在经常引用,最有意义的列上键索引
系统权限166种(其实是208(166+42?)种、、、)  对象权限
grant any  privelege(with any option)
1、系统权限revoke不是级联回收,撤省长不撤市长
2、对象权限是级连回收
select* from dba_roles(connect/resouce/dba这三个roles常用)
select * from dba_sys_privs where grantee='CONNECT'  只有一种connect
system=dba+admin+mgmt
1、role_sys_privs
2、
===================PL/SQL==过程====================================
在PL/SQL和早oracle中建procedure不一样?
java中有callableStatement
exec和set serveroutput on;都不能再developer里输出,只能在plus里
--块改成过程
create or replace  procedure myi(in_empno number) is
v_ename varchar2(8);
begin
  select ename into v_ename from emp where empno=in_empno;   --&弹出框框
  dbms_output.put_line('雇员名是:'||v_ename);
end;
_________________异常_________________________
declare
v_ename varchar2(36);
begin
  select ename into v_ename from emp where empno=&empno;
  dbms_output.put_line('雇员名'||v_ename);
exception
  when no_data_found
  then dbms_output.put_line('输入有误!!!!!!!!!!!!!!!!!!!!!!!');
  insert into emp(empno,ename) values(1,'cuole');
end;
show error
—————————函数—————————————-
call一般调用函数
create or replace function myfu(v_ename varchar2)
return number is
v_annual_sal number;
begin
  select (sal+nvl(comm,0))*13 into v_annual_sal from emp where ename=v_ename;
  return v_annual_sal;
end;
————————包——————————————
管理自己写的函数和过程
先建包-再建包体;
call 方案名.包名.函数名
exec 方案名.包名.过程名
_________________循环__________________
set serveroutput on;
1、--有out无序需再return
2、--as  ;end pro
________________分页____________________
1、做一个package包游标类,让过程的out参数去调用
2、做完游标不要关闭,让java调用
3、输出参数register
4、execute完,用cs的object接受传给rs,rs某种意义上就是游标
5、返回的不是多行,就不用游标
6、输出oracleType
—————————视图———————————
不占磁盘
不能添加索引
有安全性
————————触发器————————
1、for each row
2、raise_applacation_error(-20000~_20999,'')
3、case  when then
4、if :new.sal<:old.sal then(行级触发器)

++++++++++++++ddl++++++++++++++++++++++++++
1、insert into countris select 5,"eeewrw",15 from dual;
2、update jobs set job_title='sdf';
2、alter table test add id number
2、alter table test rename column id to id4
2、alter table test modify id varchar2(100);
2、rename test to test1;最好索引重建
2、truncate table不记日志,删除内容、不删除定义,走缓存,高水位线复位(抽水填坑)
   drop table /最干净,删除内容,删除定义,释放空间
   delete table记日志表,删除内容,不删除定义,不释放空间,(抽水) 
2、
3、comment on table test is 'test'--注备
4、comment on column test.id is 'id';
+++++++++++++DCL+++++++++++++++


//数据仓库oracle的config tool SQLserver的intagrate
//BI data miner










0 0
原创粉丝点击