ORACLE基本操作命令:


[root@ocm2 ~]# su - oracle /* 切换进入oracle
[oracle@ocm2 ~]$ 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 Bell 200.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"添加到文件,如下所示)
[oracle@ocm2 ~]$ 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

 

posted on 2016-07-13 22:34  樱桃小妮子  阅读(264)  评论(0编辑  收藏  举报

导航