Oracle常用命令
Oracle驱动:oracle.jdbc.driver.OracleDriver
Oracle连接:jdbc:oracle:thin:@10.23.55.123:1521:customer
用户名
密码 ------- jdbc的配置
2012-08-29 -- 新增Schema
ALTER SESSION SET CURRENT_SCHEMA = scott; --改变scott用户的缺省Schema
dba_tables --
******************************************************************
select * from dba_tablespaces; --查看所有表空间信息
select * from dba_temp_files; --查看临时文件信息
select * from dba_data_files; --查看数据文件信息
select * from dba_free_space; --查看剩余空间信息
select * from v$tempfile; --
select * from v$datafile;
select * from v$tablespace; --查看有哪些表空间
select * from v$datafile; --查看有哪些数据文件
select table_name ,tablespace_name from dba_tables where tablespace_name = 'USERS'; --查看指定表空间下的表和表空间名
-- 查看某个用户下的所有表
1、 select table_name from user_tables;
2、以system用户登录数据,执行select table_name from dba_tables where owner='A';
-- 角色是一组权限的集合
select * from role_sys_privs where role='角色名'; --查看角色所包含的权限
select * from v$locked_object; --查看被锁定的表
*******************************************************************
表空间 -->
数据库由若干表空间组成,表空间包括:
表段:存放表数据
索引段:存放索引数据
创建表空间
create tablespace MYSPACE datafile 'D:\oracle\oradata\myoracle\myspace.dbf' size 100M; --创建表空间
alter tablespace MYSPACE add datafile 'D:\oracle\oradata\myoracle\myspace2.dbf' size 100M; --更改表空间增加大小
alter database datafile 'D:\oracle\oradata\myoracle\myspace.dbf' resize 300M; --将表空间的大小改为300m
drop tablespace temp_space; --删除表空间
create user shaohan identified by aniu default tablespace MYSPACE temporary tablespace TEMP; --创建用户名为shaohan口令为aniu的用户
alter user shaohan identified by aniu1; --修改用户shaohan的密码
alter user shaohan default tablespace SYSTEM; --修改用户shaohan的默认表空间
alter user shaohan temporary tablespace temp; --修改shaohan的临时表空间
select default_tablespace from dba_users where username = 'SHAOHAN';
select * from dba_users; --查看用户信息
select * from session_roles;
select object_name from user_objects where status = 'invalid' and object_type = 'PROCEDURE';
show parameter sort;
show parameter; -- 显示数据库参数所有的
show user; --显示用户
select * from v$logfile;
select * from v$controlfile;
select * from v$datafile;
******************************************************************************
select value from v$parameter where name='undo_management'; --查询回退管理方式
select value from v$parameter where name='undo_tablespace'; --查询undo表空间
select segment_name,tablespace_name from dba_rollback_segs; --查询系统已经创建回退段
-- 建表语句
create table t_books(
book_id varchar2(32) not null primary key,
book_name varchar2(64),
book_author varchar2(64),
book_publish varchar2(128),
book_isbn varchar2(128),
book_page varchar2(128),
book_price varchar2(128),
book_content varchar2(128),
book_type_id number(32)
)
tablespace BLOG
pctfree 10
pctused 40
initrans 1
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
-- Add comments to the table
comment on table t_books is '书信息表';
-- Add comments to the column
comment on column book_id is '书id';
-- 建表完成后增加主键约束
ALTER TABLE t_books ADD CONSTRAINT PK_t_books PRIMARY KEY (book_id);
******************************************************************************
存储子程序的概念
存储在数据库中的一个命名的PL/SQL块
oracle中有三种类型的存储子程序:
存储过程
函数
包
1.存储过程和函数
有4部分组成
签名或头
关键字IS或AS
局部声明
BEGIN和END之间的过程体(含异常处理程序)
-- 过程过程的模型
CREATE [OR REPLACE] PROCEDURE procedure_name
[(parameter parameter_mode datatype, ...)]
{IS|AS}
[local declaratons]
BEGIN
execute statments
[exception]
END [procedure_name]
/
-- 函数的模型
CREATE [OR REPLACE] FUNCTION function_name
[(parameter parameter_mode datatype, ...)]
RETURN datatype
{IS|AS}
[local declaratons]
BEGIN
function body
END [function_name]
/
*区别;a.函数作为表达式的一部分调用,还可以从DML语句中进行调用,过程不行
b.函数必须定义返回值。
过程和函数的执行:
将其作为PL/SQL块的一个可执行语句或表达式的一部分.
在交互环境中,使用EXECUTE命令.
使用CALL语句.
参数模式(parameter_mode)
IN:默认模式.只读模式,被调用形参的值在子程序的内部不能改变.
OUT[NOCOPY]:写模式,允许在子程序的内部对其赋值.可以为调用环境返回值.
IN OUT[NOCOPY]:读写模式,允许从实参中将值读出,也允许将修改后的值返回到调用环境.