与oracle相关的一些命令
1.登陆系统用户
sqlplus 然后输入系统用户名和密码
登陆别的用户
conn 用户名/密码;
2.创建表空间
create tablespace 空间名
datafile 'c:\空间名' size 15M --表空间的存放路径,初始值为15M
autoExtend on next 10M --空间的自动增长的值是10M
permanent online; --永久使用
3.创建用户
create user shi --创建用户名为shi
identified by scj --创建密码为scj
default tablespace 表空间名 --默认表空间名
temporary tablespace temp --临时表空间为temp
profile default --受profile文件的限制
quota unlimited on 表空间名; --在表空间下面建表不受限制
4.创建角色
create role 角色名 identified by 密码;
5.给角色授权
grant create session to 角色名;--给角色授予创建会话的权限
grant 角色名 to 用户名; --把角色授予用户
6.给用户授予权限
grant create session,resource to shi;--给shi用户授予所有权限
grant create table to shi; --给shi用户授予创建表的权限
7.select table_name from user_tables; 察看当前用户下的所有表
8.select tablespace_name from user_tablespaces; 察看当前用户下的 表空间
9.select username from dba_users;察看所有用户名称命令 必须用sys as sysdba登陆
10.创建表
create table 表名
(
id int not null,
name varchar2(20) not null
)tablespace 表空间名 --所属的表空间
storage
(
initial 64K --表的初始值
minextents 1 --最小扩展值
maxextents unlimited --最大扩展值
);
11.--为usrs表添加主键和索引
alter table users
add constraint pk primary key (ID);
12.为已经创建users表添加外键
alter table users
add constraint fk_roleid foreign key (roleid)
references role(role_id) on delete cascad; --下边写主表的列
on delete cascad是创建级联
13.把两个列连接起来
select concat(name,id) from 表名; --把name和id连接起来
14.截取字符串
select column(name,'李') from 表名; --把name中的‘李’去掉
15.运行事务之前必须写
set serveroutput on; --打开输入输出(不写的话,打印不出信息)
16.while的应用
declare --声明部分
ccc number:=1; --复职
a number:=0;
begin --事务的开始
while ccc
相关文档:
对日常工作中用到的感觉有用的sql语句做个归纳,用于今后温故知新。
*复制表:
create table tablename as select * from table_src;
create table tablename as select * from table_src where 1 <> 1; --只复制表结构 ......
Oracle使用标准、可变长度的内部格式来存储数字。这个内部格式精度可以高达38位。
NUMBER数据类型可以有两个限定符,如:
column NUMBER ( precision, scale)
precision表示数字中的有效位。如果没有指定precision的话,Oracle将使用38作为精度。
&nb ......
SELECT max(SYS_CONNECT_BY_PATH(COLUMN_NAME, ','))
from (SELECT A.COLUMN_NAME, ROWNUM AS ROWNO
from USER_TAB_COLUMNS A
WHERE TABLE_NAME = 'A_USER'
  ......
create user 用户名 identified by 密码 default tablespace 缺省表空间 Temporary tablespace 临时表空间;
grant connect,resource,dba to 用户名;
revoke unlimited tablespace from 用户名;
alter user 用户名 quota 0 on Users;
alter user 用户名 quot ......
IN条件
用IN条件在指定的一组值中进行测试。IN条件也就是 成员条件。
在幻灯片的例子中显示所有经理号为100、101或201的雇员的employee numbers, last names, salaries和经理的employee numbers。
在IN条件中可以使用任何数据类型。下面的例子从EMPLOYEES表返回雇员信息行,这些雇员的名字包括在WHERE子句的名字列 ......