1、創建用戶
##使用sys登錄 sqlplus /nolog ##首先創建表空間 create tablespace test918 datafile 'E:\SOFT\ORACLE\dbf\test918.dbf' size 2048M autoextend on next 5M maxsize 3000M; ##創建表空間之后再創建用戶
(因oracle用戶名大小寫問題對於新手很不友好,所以創建用戶名密碼均使用大寫
此處后面遇到了幾次坑,就是oracle11g的用戶名和密碼大小寫問題,所以說明下
此處創建用戶的用戶名密碼,用戶名不加引號, 密碼加英文格式雙引號,這樣做的好處是防止創建完登錄出現問題且防止密碼被轉存成大寫)
create user gary identified by “gary” default tablespace test918;
##創建用戶之后給用戶授權(此處授予DBA權限) grant connect,resource,create session,dba to gary;
##用戶解鎖
alter user gary account unlock;
3、創建表
##首先連接到對應的用戶下,如果已經是對應的用戶則忽略 conn gary/gary as sysdba; ##創建表 create table t1(id int not null,name varchar(8) not null,tel int not null);
4、修改表
##修改表名 rename t1 to tb1; ##增加字段 alter table tb1 add sex char(4); ##修改字段名 alter table tb1 rename column tel to tell; ##刪除字段 alter table tb1 drop column sex;
##修改字段類型
alter table tb1 modify sex int;
##
5、插入數據
6、更新表數據
7、刪除表
2、刪除用戶
8、查看當前所用數據庫
查看當前用戶所有表
(user_tables是單用戶級別,all_tables所有用戶級別,dba_tables全局級別包括系統表)
查看表結構(僅在命令行模式下起效,在sql窗口中無效如PLSQL這類工具,因為這類工具通常只識別標准的SQL格式的語句。)
desc tb1;
查看當前登錄的用戶
查看oracle版本號
select * from v$version;
查看當前環境是pdb還是cdb(12c用11g用不到)