Oracle知識梳理

來源:互聯網
上載者:User

標籤:default   oracle   可擴充性   create   status   


create tablespace user1 datefile ‘‘ size 20M //建立一個名為User1的資料表空間

autoextend on//資料檔案的可擴充性

autoextend off//關閉

autoextend on next 5M//指定資料檔案的增長幅度

autoextend on next 5m maxsize 500M

//查看錶空間是否建立成功

select file_name,tablespace_name from dba_data_files order by file_name

//查看錶空間

select tablespace_name,status,allocation_type from dba_tablespaces

select user_id,username,default_tablespace from dba_users//修改資料庫預設資料表空間的的SQL語句

alter tablespace default tablespace user1

alter tablespace user2 rename to user20

dorp tablespace user20 including contents and datafiles

//建立主鍵約束

create table student (student_id number primary key,student_name vachar2(20),student_birthday date,student_address vachar2(50),student_phone vachar2(20))

//建立外鍵

create table customers(customer_id number primary key,customers_name vachar2(50),customers_address vachar2(50),customers_phone vachar2(20),email vachar2(20))

create table orders(orders_id number primary key,customers_id number,goods_name vachar2(20),quantity number,unit vachar2(10))

alter table orders add constraint fk_orders_customer foreign key (customer_id) referemces customers (customer_id)

//建立視圖

create table employees1(employee_id number primary key,first_name vachar2(4),last_name vachar2(4),province vachar2(10),city vachar2(10),salary number)

select text from user_views where view_name=‘VW_EMPLOYEES‘

select *from VW_EMPLOYEES

//修改視圖

create or replace view VW_EMPLOYEES as 

select employee_id,last_name||first_name as employee_name,province||‘-‘||city as location,salary from employees1

//刪除視圖

drop view VW_EMPLOYEES

//建立索引

create index idx orders(orders_id,goods_name)

函數

//截取字串

select substr(‘1234567890‘,5,4) from dual;//第五位開始的四個字元

//獲得字串出現的位置

select instr(‘big big tiger‘,‘big‘) from dual;

itrim()//刪除字串首部空格

rtrim()//刪除字串尾部空格

current_timestamp()//返回當前會話時區的目前時間戳

current_times()//返回當前會話時區的當前日期

//in判式用於判斷表的列值是否存在於列表(集合)中。而exists判式則可用於判斷查詢結果集合是否為空白

//排名

select student_name,rank() over(orders by student_age) position from student;

//if else

set serverout on;

delete employee_num number;

begin

select count(*) into employee_num from t_employees where status="ACT";

if employees_num>0 then

dbms_output.put_line(‘存在記錄‘);

else

dbms_output.put_line(‘不存在記錄‘);

end if;

end;

//case when

declare employee_num number;

begin

select count(*) into employee_num from t_employees where status="ACT";//將數目儲存到變數employee_num中

case

when employee_num>1 then

dbms_output.put_line(‘存在多條有效記錄‘);

when employee_num=1 then

dbms_output.put_line(‘僅存在一條有效記錄‘);

else

dbms_output.put_line(‘不存在記錄‘);

end case;

end;

建立儲存過程

create or replace procedure update_students

begin

update student set student_age=10;

commit;

end update_students;

//執行儲存過程

excute update_students;

IN OUT 參數

create or replace procedure swap(in_out_param1 in out number,in_out_param2 in out number) as

begin

declare param number;

begin

param:=in_out_param1;

in_out_param1:=in_out_param2;

in_out_param2:=param;

end;

end;

樹形查詢

查詢 

尋找重複資料

select distinct month from t_salary//獲得唯一性記錄

order by //升序(asc)和降序(desc)排列

group by //用於對記錄集合進行分組

having //對資料來源進行條件過濾


本文出自 “7448566” 部落格,請務必保留此出處http://7458566.blog.51cto.com/7448566/1554811

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.