作用:
删除缓冲区的sql语句
例如:
del 2 删除缓冲区的第2行
注意:
list N后,第N行理解为当前行
再del * 5,即可删除当前行到第5行
典型用法:
l1 列出缓冲区第一行
input XXXXXX 在第一行后新增一行xxxxxx
典型用法:
l 行号,列出行的内容
append xxxx 把xxxx内容追加到当前行的后面
注意:使用时 需要配置在glogin.sql中添加DEFINE_EDITOR=vi
vim /oracle/ora11/product/sqlplus/admin/glogin.sql
DEFINE_EDITOR=vi
作用:
是把外部文件的内容读到缓冲器,但是不执行
经过试验:
这种方法总是报无效字符错误(实际没有任何问题)
作用: 把外部文件内容读到缓冲区(但不显示),并执行
作用:
读取外部文件内容,显示出来,并执行
经过试验:
该命令执行完后不报错,但实际根本没有做需要的操作
comment on table 表名is '内容';
comment on column 表名.字段名 is '内容';
1. 切换到管理员下
conn sys/sys as sysdba;
2. 执行语句
alter user 用户 account unlock;
create table cat (
cat_id number,
catname varchar2(30),
constraint plcat_id primary key(id)
);
create table goods (
goods_id number,
cat_id number,
goods_name varchar2(30),
constraint fkcatid foreign key(cat_id) references cat(cat_id)
);
create sequence increment by n -–步长
start with n -–开始的值
maxvalue n | nomaxvalue –-最大的值
minvalue n | nominvalue -–最小的值
cycle | nocycle -–是否循环
cache n | nocache -–缓存n个
Alter sequence 序列名
选项 新值
例子:
alter sequence 序列名
maxvalue 5
注意:
不能修改开始值
修改只影响新产生的值,不影响已产生的值
同义词就是别名,外号
给scott用户赋 create synonym权限
conn sys/sys as sysdba;
grant create synonym to scott;
conn scott/scott;
create synonym g for scott.goods;
create or replace view 视图名
as select 语句
with read only --是否只读
with check option –是否执行约束检查
例子
create view view_look as select t.attrid,t.attrval,t.createtime from bak t
with read only;
索引信息存放在
user_indexes
uer_ind_columns
declare
变量声明部分
begin
执行部分
exception
异常处理部分
end;
默认:调用一个匿名块/存储过程,只执行不输出
学习调试时:set serveroutput on
varchar2(n)
char(n)
number
declare
i number default 9;
begin
i := i + 1;
dbms_output.put_line('double i is '||i);
end;
declare
age int default 20;
height int :=170;
begin
dbms_output.put_line('his age is '||age);
dbms_output.put_line('his height is '||height);
end;
type people is record
(
name varchar2(10),
age number,
gender char(2)
);
create procedure p13
is
type charset is table of char;
answ charset := charset('a','b','c','d');
begin
dbms_output.put_line('has '||answ.count()||' option answer');
end;
when no_data_find then
dbms_out.put_line();
when too_many_rows then
dbms_out.put_line();
when others then
dbms_out.put_line();
当执行一个dml语句时,隐式游标由系统自动创建叫SQL,
SQL有几个属性 isopen true/false
rowcount 增删改影响的行数,对于select无意义(只有1行时,才能读到该值)
found true/false 是否影响到行
notfound true/false,与上同,只是值恰相反
cursor 游标名 is select 语句;
使用的逻辑步骤:
声明
打开
取值
关闭
declare
--声明
cursor cur18 is select * from dept;
e dept%rowtype;
beign
open cur18;--打开
fetch cur18 into e;--取值
dbms_output.put_line(e.dname||':'||e.loc);
close cur18;--关闭
end;
declare
--声明
cursor cur18 is select * from dept;
e dept%rowtype;
beign
open cur18;--打开
fetch cur18 into e;--取值
while cur18%FOUND loop
dbms_output.put_line(e.dname||':'||e.loc);
fetch cur18 into e;--取值
end loop;
create table odr(
oid number,
gid number,
much number
)
insert into goods values(5,'pig',80);
insert into goods values(6,'dog',40);
insert into goods values(7,'cat',30);
insert into odr values (seq1.nextval,5,3);
update goods set cnt=cnt-3 where gid=5;
//只能以表为单位,监视insert/update/dalete操作,
//不能精确知道新的insert/update/dalete的行是什么内容的
create or replace trigger tr1
after insert
on odr
begin
end;
create or replace trigger tr1
after insert
on odr
for each row
begin
update goods set cnt=cnt-:new.much where gid=:new.gid;
end;