---管理員登錄
conn sys/oracle@orcl as sysdba;
--解鎖scott方案
alter user scott account unlock;
--scott登錄
conn scott/tiger@orcl as normal;
例題:
創建表 temp id nubmer(8) names varchar2(20) age number(8)
create table temp(
id number(8),
names varchar2(20),
age number(8)
);
1 增加列 address(30)
alter table temp add address varchar2(30);
2 將地址列 長度修改為50
alter table temp modify address varchar2(50);
3 刪除地址列
alter table temp drop column address;
4 增加一條數據 1,'張三',30
insert into temp values(1,'張三',30);
5 再增加一個數據 '王五'
insert into temp(names) values('王五');
6 將王五的年齡設置為25
update temp set age=25 where names='王五';
7 將標號是1的人的 姓名修改為李強,年齡修改為33
update temp set names='天佑',age=60 where id=1;
8 將王五刪除
delete from temp where names='王五';
9 查詢所有的數據
select * from temp;
10 刪除temp表
drop table temp;
在Oracle 中效果如下:
SQL> create table temp(
2 id number(8),
3 names varchar2(20),
4 age number(8)
5 );
Table created
SQL> select * from temp;
ID NAMES AGE
--------- -------------------- ---------
SQL> alter table temp add address varchar2(30);
Table altered
SQL> select * from temp;
ID NAMES AGE ADDRESS
--------- -------------------- --------- ------------------------------
SQL> alter table temp modify address varchar2(50);
Table altered
SQL> select * from temp;
ID NAMES AGE ADDRESS
--------- -------------------- --------- --------------------------------------------------
SQL> alter table temp drop column address;
Table altered
SQL> select * from temp;
ID NAMES AGE
--------- -------------------- ---------
SQL> insert into temp values(1,'張三',30);
1 row inserted
SQL> insert into temp(names) values('王五');
1 row inserted
SQL> select * from temp;
ID NAMES AGE
--------- -------------------- ---------
1 張三 30
王五
SQL> update temp set age=25 where names='王五';
1 row updated
SQL> select * from temp;
ID NAMES AGE
--------- -------------------- ---------
1 張三 30
王五 25
SQL> update temp set names='天佑', age=60 where id=1;
1 row updated
SQL> select * from temp;
ID NAMES AGE
--------- -------------------- ---------
1 天佑 60
王五 25
SQL> delete from temp where names='王五';
1 row deleted
SQL> select * from temp;
ID NAMES AGE
--------- -------------------- ---------
1 天佑 60
SQL> drop table temp;
Table dropped
SQL> select * from temp;
select * from temp
ORA-00942: 表或視圖不存在
