##最近因為用到oracle,所以邊學習邊整理一些入門級的簡單操作和基礎支持,此篇文章會持續更新。
##學習oracle版本為官網11g第二版
##官網地址(如下載需要登錄):https://www.oracle.com/
##完整下載頁面:https://www.oracle.com/technetwork/cn/database/enterprise-edition/downloads/index.html
一、創建庫
1、①在系統盤中安裝目錄下“C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Oracle - OraDb11g_home1\配置和移植工具\Database Configuration Assistant”(具體位置看個人情況)
②或者在菜單欄中“Oracle - OraDb11g_home1\”有Database Configuration Assistant
2、通過圖形界面配置建庫既可
二、基本操作(增刪改查)
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、插入數據
###直接插入數據 insert into t1(id,name,tel) values ('1','linux','13812341234');
6、更新表數據
##直接針對需要改動的點進行修改
update t1 set tel='15512345678' where tel='13812341234';
7、刪除表
##刪除表中的所有數據,速度比delete快很多,截斷表 truncate table 表名 delete from table 條件 drop table 表名
2、刪除用戶
##刪除用戶
drop user gary;
##若用戶擁有對象,無法直接刪除用戶,需要先刪除用戶所有對象再刪除用戶
drop user gary cascade; drop user gary;
8、查看當前所用數據庫
select instance_name from V$instance;
查看當前用戶所有表
(user_tables是單用戶級別,all_tables所有用戶級別,dba_tables全局級別包括系統表)
select table_name from user_tables;
查看表結構(僅在命令行模式下起效,在sql窗口中無效如PLSQL這類工具,因為這類工具通常只識別標准的SQL格式的語句。)
desc tb1;
查看當前登錄的用戶
select user from dual;
show user;
查看oracle版本號
select * from v$version;
查看當前環境是pdb還是cdb(12c用11g用不到)
select name,cdb,open_mode,con_id from v$database;
