Oracle資料庫的一些操作

2021-05-21 21:01:32 字數 4539 閱讀 4013

如何備份oracle資料庫:

md f:/db_bak/%date:~0,10%

exp userid=bszlhr/bszlhr@orcl_14 file=f:/db_bak/%date:~0,10%/bszlhr%date:~0,10%.dmp log=f:/db_bak/%date:~0,10%/log_bszlhr_%date:~0,10%.log

buffer=64000 owner=bszlhr

-----建立信用資訊的表----------

create table gccredit(

itemid number(10,0),

empid number(10,0),

creditcots varchar2(100),

notes varchar(100)

)select * from gccredit

gcv_credit

-------建立信用資訊的檢視------

create or replace view gcv_credit (

filepath,

unitid,

deptno,

empno,

empname,

position,

itemid,

empid,

creditcots,

notes)as

select  emp.filepath ,emp.unitid, emp.deptno, emp.empno,      emp.empname,emp.position,

c.itemid,c.empid,c.creditcots,c.notes

from gccredit c, gcemployee emp

where emp.empid = c.empid

select * from gcv_credit

------3.用來查詢資料物件中所包含的字段--------

select * from gc_columns where obj_id in (

select obj_id from gc_dbobjects where obj_class like '%credit%');1.在

oracle

中如何獲取前

10條的記錄:

select   *   from   tablename   where   rownum<11   order   by   colname   desc 2.

在oracle

中的多表連線查詢,

oracle

多表連線與子查詢

posted on 2009-07-02 13:17 仲巨集偉(

anmo)閱讀

(0)  編輯收藏1

:等值連線

迪卡爾集連線

select ename, a.deptno as a_deptno,b.deptno as b_deptno ,b.dname as

部門from emp a, dept b

等值連線

select ename, a.deptno as a_deptno,b.deptno as b_deptno ,b.dname as

部門from emp a, dept b

where a.deptno = b.deptno; 2

:非等值連線,在

emp表和

salgrade

表中查詢員工的姓名,工資,等級,工資上線,工資下線

select ename as

姓名, sal as

工資, grade as

工資等級

,losal as

工資上線,

hisal as

工資下線

from emp, salgrade

where sal between losal and hisal; 3:

外連右外連

select e.ename, d.dname, e.deptno

from emp e,dept d

where e.deptno = d.deptno(+);

左外連與右外連相反 以

hr登陸查詢表

employees

和departments

表select  first_name as

姓名, department_name as

部門名稱

,  d.department_id as

部門編號

from employees e, departments d

where e.department_id= d.department_id(+) ; 4:

自連:在同乙個表中查詢每個員工及上司的工號和姓名

select a.empno  as

員工編號

, a.ename as

員工姓名

, a.mgr as

上司的員工編號

, b.ename as

上司姓名

from emp a, emp b

where a.mgr = b.empno;

5:sql99

交叉連線

cross join------

相當於迪卡爾集

select e.ename,d.dname

from emp e cross join dept d;

自然連線

natural join------

相當等值連線

select e.ename, d.dname

from emp e natural join dept d;

using

子句-----

使用同名列查詢

select e.ename, d.dname

from emp e join dept d

using (deptno); on

子句------

當列名不同時用

on子句用on

查詢兩張表

select e.ename, d.dname

from emp e join dept d

on e.deptno = d.deptno; 用

on查詢多張表

select e.ename, d.dname

from emp e join dept d

on e.deptno = d.deptno

join

第三個表

on 列

1 = 列2;

內連線(

inner join

)-------

內連線只返回滿足連線條件的資料

select employee_id, last_name, salary, department_id, department_name

from employees inner join departments using(department_id);

左外連select employee_id, last_name, salary, department_id, department_name

from employees left join departments using(department_id);

右外連select employee_id, last_name, salary, department_id, department_name

from employees right join departments using(department_id);

滿外連select employee_id, last_name, salary, department_id, department_name

from employees full outer join departments using(department_id);

子查詢------------

查詢出工資比

scott

高的人select ename, sal from emp

where sal>

(select sal from emp where ename='scott');

查詢那些人和

scott

相同職位的人

select ename, job from emp

where job=

(select job from emp where ename='scott')  

and ename <> 'scott';

any的用法< any

意味著小於最大、

> any

大於最小

select empno, ename, sal, job

from emp 

where sal

all的用法< all

:小於所有,即小於最小、

> all

:大於所有,即大於最大

select empno, ename, sal, job

from emp

where sal

oracle資料庫的一些操作

oracle啟用禁用約束 alter table table name disable enable constraint constraint name禁用或啟用約束 alter table table name drop constraint constraint name通過主鍵名刪除約束 查...

oracle 資料庫的一些sql操作

時間字段查詢的sql語句 select from mycontent t where t.create date to date 2010 06 21 yyyy mm dd 修改時間欄位的sql語句 update mycontent t set t.create date to date 2012....

一些資料庫的操作

建立乙個資料庫 create database database name 刪除乙個資料庫 drop database database name 顯示資料庫 show databases 進入某個資料庫 use database name 建立乙個資料表 create table database...