笔记081108
2008-11-8 上午7:11 发布人 tiger chang ************************************************** NAME :ChangTiger *
* DATE :19:28 2008-11-8 *
* ADDR :o52tiger@yahoo.com.cn *
*************************************************
ORACLE 数据库学习
********************************************************
START file_name
Runs the SQL*Plus statements in the specified script. The script can be
called from the local file system or a web server.
*******************************************************
SHOW (SHO)
SHOW
----
Shows the value of a SQL*Plus system variable, or the
current SQL*Plus environment.
********************************************************
数据库
Date retrieval
DML 数据操作语言 update delete insert select (SQL> select table_name from user_tables;)
DDL 数据定义语言 create
Transaction control
Date Control Language 数据控制语言
********************************************************
DB
A relation datebase uses relations or two-dimensional tables to store information.
DBMS
To manage database ,you need database management system(DBMS),A DBMS is a program that stores ,retireves,and modifies data in the database on request.
********************************************************
查看数据库的环境变量的设置
bash-2.05$ echo $ORACLE_HOME
/export/home/oracle9/product/9.2.0
********************************************************
查看数据库文件
bash-2.05$ pwd
/export/home/oracle9/oradata/tarena
————————————————————————————————————
bash-2.05$ ls -l *.dbf
-rw-r--r-- 1 oracle dba 20979712 11月 8 17:29 cwmlite01.dbf
-rw-r--r-- 1 oracle dba 20979712 11月 8 17:29 drsys01.dbf
-rw-r--r-- 1 oracle dba 156639232 11月 8 17:29 example01.dbf
-rw-r--r-- 1 oracle dba 26222592 11月 8 17:29 indx01.dbf
-rw-r--r-- 1 oracle dba 20979712 11月 8 17:29 odm01.dbf
-rw-r--r-- 1 oracle dba 419438592 11月 8 19:12 system01.dbf
-rw-r--r-- 1 oracle dba 42999808 10月 11 2007 temp01.dbf
-rw-r--r-- 1 oracle dba 10493952 11月 8 17:29 tools01.dbf
-rw-r--r-- 1 oracle dba 209723392 11月 8 19:29 undotbs01.dbf
-rw-r--r-- 1 oracle dba 26222592 11月 8 17:29 users01.dbf
-rw-r--r-- 1 oracle dba 39985152 11月 8 17:29 xdb01.dbf
————————————————————————————————————
bash-2.05$ ls -l *.ctl
-rw-r----- 1 oracle dba 2023424 11月 8 19:32 control01.ctl
-rw-r----- 1 oracle dba 2023424 11月 8 19:32 control02.ctl
-rw-r----- 1 oracle dba 2023424 11月 8 19:32 control03.ctl
-------------------------------------------------------
bash-2.05$ pwd
/export/home/oracle9/product/9.2.0
————————————————————————————————
bash-2.05$ ls
Apache ds lib32 owm syndication
BC4J hs md plsql sysman
JRE install mgw precomp tg4ifmx
assistants inventory network rdbms tg4ingr
bin jar oci relnotes tg4sybs
classes javavm ocommon root.sh tg4tera
ctx jdbc ocs4j root.sh.old ultrasearch
cwmlite jdk oem_webstage slax weboamlib
dbs jlib olap soap wwg
demo jsp oracore sqlj xdk
dm ldap ord sqlplus
doc lib otrace srvm
bash-2.05$
————————————————————————
bash-2.05$ pwd -----命令存贮处
/export/home/oracle9/product/9.2.0/bin
————————————————————————
bash-2.05$ sqlplus
SQL*Plus: Release 9.2.0.1.0 - Production on Sat Nov 8 19:37:29 2008
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Enter user-name: openlab
Enter password: ---隐藏密码open123
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
SQL> -----登录成功
——————————————————————————————————
bash-2.0.5$ sqlplus openlab/open123 ----直接登录到数据库
bash-2.05$ sqlplus scott/tiger ---数据库提供的一个账户,查起具体权限等信息。
********************************************************
查看用户的表的名字
SQL> SELECT TABLE_NAME FROM USER_TABLES; ----USER_TABLES 是一个数据字典上系统的一个 表
TABLE_NAME
------------------------------
BONUS
DEPT
EMP
SALGRADE
********************************************************
查看表EMP的格式
SQL> DESCRIBE EMP -------等价于 SQL> DESC EMP
Name Null? Type
----------------------------------------- -------- ---------------------
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)
SQL>
********************************************************
查询表DEPT的所有数据
SQL> SELECT * FROM DEPT;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
********************************************************
CREATE TABLE TIGER(
ID NUMBER(4),
NAME VARCHAR2(20),
MAIL VARCHAR2(50),
ADDR VARCHAR2(100),
);
* *******************************************************
SQL> DESC TIGER;
Name Null? Type
----------------------------------------- -------- --------------------------
ID NUMBER(4)
NAME VARCHAR2(10)
AGE NUMBER(3)
SQL> INSERT INTO TIGER VALUES(2,'TIGER ',23);
1 row created.
********************************************************
SELECT ID 编号 , NAME 名字 , AGE 年龄 FROM TIGER;
SELECT 'HELLO'||NAME FROM TIGER;
----------------------用||链接字符串
SQL> SELECT 'HELL ' || NAME AS CHANGTIGER FROM TIGER;
CHANGTIGER
---------------
HELL CHANGTIGER
HELL TIGER
HELL HELLO
NVL 函数的使用
将空的值转换成实际的值。
SQL> SELECT NVL(AGE,30) FROM TIGER; 如果年龄为空则显示为30 不能修改表里的数据;
SQL> SELECT NVL(NAME,'NONAME') FROM TIGER; 如果名字为空则显示为NONAME
SQL> SELECT DISTINCT NAME FROM TIGER; 滤除重复的数据;
SQL> SELECT * FROM TIGER WHERE AGE = 8;
SQL> SELECT * FROM TIGER WHERE NAME = 'CHANGTIGER' AND AGE > 0;
SQL> SELECT * FROM TIGER WHERE NAME LIKE '%TIGER';
********************************************************
SQL>@/usr/bin/test.sql 执行sql脚本。