ORACLE基本操作命令:

來源:互聯網
上載者:User

標籤:


[[email protected] ~]# su - oracle /* 切換進入oracle
[[email protected] ~]$ sqlplus / as sysdba /* 切換進入SQL

SQL*Plus: Release 11.2.0.1.0 Production on 星期二 7月 12 14:51:36 2016

Copyright (c) 1982, 2009, Oracle. All rights reserved.

已串連到空閑常式。 /* 表示資料庫沒有啟動成功,需要使用命令staerup重新啟動資料庫

SQL> startup
ORACLE 常式已經啟動。 /* 表示資料庫啟動成功

Total System Global Area 849530880 bytes
Fixed Size 1339824 bytes
Variable Size 499125840 bytes
Database Buffers 343932928 bytes
Redo Buffers 5132288 bytes
資料庫裝載完畢。
資料庫已經開啟。

 

SQL> create table test1(id int); /* 建立新表test1

表已建立。

SQL> save test1.sql /* 儲存檔案(將建立立的test1儲存到資料庫中,以便下次直接使用)
已建立 file test1.sql
SQL> get test1.sql /*查看檔案
1* create table test1(id int)

SQL> shutdown immediate /* 關閉資料庫
資料庫已經關閉。
已經卸載資料庫。
ORACLE 常式已經關閉。
SQL> startup
ORACLE 常式已經啟動。

Total System Global Area 849530880 bytes
Fixed Size 1339824 bytes
Variable Size 499125840 bytes
Database Buffers 343932928 bytes
Redo Buffers 5132288 bytes
資料庫裝載完畢。
資料庫已經開啟。


基本SQL語句操作:
/*建立新表checks
SQL> create table checks(check# int,payee char(20),amout decimal(14,2),remarks char(60));
表已建立。

/*儲存
SQL> save checks.sql
已建立 file checks.sql

/*查看檔案
SQL> get checks.sql
1* create table checks(check# int,payee char(20),amout decimal(14,2),remarks char(60))

/*增(在表中增加新的一行資料)
SQL> insert into checks values(2,‘Reading R.R‘,245.34,‘train to chicago‘);

已建立 1 行。

SQL> insert into checks values(2,‘Ma Bell‘,200.32,‘cellular phone‘);

已建立 1 行。

/*更新(更新資料庫表中某個屬性的值)
SQL> update checks set check#=‘3‘ where check#=‘2‘ and payee=‘Ma Bell‘;

已更新 1 行。

/*並查看上述操作是否更新成功
SQL> select * from checks where check#=‘3‘;

CHECK# PAYEE AMOUT
---------- ---------------------------------------- ----------
REMARKS
--------------------------------------------------------------------------------
3 Ma Bell200.32
cellular phone

/*刪(刪除資料庫表中某一行的資料)
SQL> delete from checks where check#=‘3‘;

已刪除 1 行。

/*並查看上述操作是否刪除成功
SQL> select * from checks where check#=‘3‘;

未選定行

 

 

 

 

 

 


註:
如果出現亂碼,需要修改一下 ~/.bash_profile 檔案(將export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"添加到檔案,如下所示)
[[email protected] ~]$ vim ~/.bash_profile /* 修改檔案


# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
ORACLE_SID=test /*通過對ORACLE_SID賦值選擇所操作的資料庫,本次操作的資料庫為test

PATH=$ORACLE_HOME/bin:a$PATH:$HOME/bin


export ORACLE_BASE
export ORACLE_HOME
export ORACLE_SID
export PATH

export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK" /*添加這句話就可以不亂碼了

alias sqlplus="rlwrap sqlplus"
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"~/.bash_profile" 24L, 426C

 

ORACLE基本操作命令:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.