oracle 11g,12c安裝+配置,plsql 13安裝+激活

oracle12c下載地址html

oracle12c安裝教程python

Oracle 11g R2 Client(64bit)的下載與安裝(圖文詳解)物理內存檢查失敗解決步驟spring

PLSQL Developer 11安裝與配置sql

listener.ora、sqlnet.ora、tnsnames.ora 配置   tnsping 服務名數據庫

Oracle11g 客戶端與服務器端配置服務器

sqlnet.ora 配置oracle

plsql13.0下載地址dom

PLSQL13.0.0.1882 註冊碼:ide

打開plsql 找到幫助——register——填寫如下信息:

產品號/product code: 4vkjwhfeh3ufnqnmpr9brvcuyujrx3n3le 
序列號/serial Number:226959 
密碼/password: xs374caoop

kfsvzt6zh2exaxzxgjk44rv5kp2yp68vgk   、186220、xs374ca

plsql v12漢化包下載地址:可漢化12.0及以上版本(安裝到plsqldev.exe同級目錄下)

漢化教程

PLSQL遠程鏈接Oracle數據庫

ORA-12541:TNS:no listener 解決方法   cmd: lsnrctl start

ORA-12541: TNS: 無監聽程序 的解決辦法

將兩個文件中的 HOST=192.168.78.138(固然這個是個人地址),全改成 " HOST=localhost " 。

listener.ora 文件修改後,以下圖:

 

tnsnames.ora 文件修改後,以下圖:

 以上兩個配置文件修改完成後,Ctrl + R 在彈出框中輸入 " SERVICES.MSC " ,找到Oracle的服務(OracleService)和 Oralce 監聽服務 (OracleOraDb10g_homeTNLListener
注意:先中止,而後再啓動

 

   查看數據庫信息

一、查詢oracle中全部用戶信息

select * from dba_users;
二、只查詢用戶和密碼

select username,password from dba_users;
三、查詢當前用戶信息

select * from dba_ustats;

四、查詢用戶能夠訪問的視圖文本

select * from dba_varrays;

五、查看用戶或角色所擁有的角色

select * from dba_role_privs;   

select * from user_role_privs;

六、查看用戶或角色系統權限(直接賦值給用戶或角色的系統權限)

select * from dba_sys_privs;   

select * from user_sys_privs; (查看當前用戶所擁有的權限)

  oracle 建新用戶

sqlplus/ as sysdba

-- create new user CREATE USER test IDENTIFIED BY t123; -- grant priviledges GRANT CONNECT, RESOURCE, DBA TO test; --alter password alter user test identified by t123; --oracle對錶空間 USERS 無權限 alter user 用戶名 quota unlimited on users; --刪除用戶 drop user 用戶名 cascade; ---cascade 級聯 --授予權限 -- 分配用戶 Sam 建立表,建立序列,建立存儲過程和建立視圖的權限 grant create table,create sequence,create view,create procedure, update to test --去除用戶權限 -- 去除用戶 Sam 建立視圖的權限 revoke create view from test;

  建表

CREATE TABLE order_items
  (
    order_id   NUMBER( 12, 0 )                                , -- fk
    item_id    NUMBER( 12, 0 )                                ,
    product_id NUMBER( 12, 0 ) NOT NULL                       , -- fk
    quantity   NUMBER( 8, 2 ) NOT NULL                        ,
    unit_price NUMBER( 8, 2 ) NOT NULL                        ,    
    CONSTRAINT pk_order_items 
      PRIMARY KEY( order_id, item_id ),    
    CONSTRAINT fk_order_items_products 
      FOREIGN KEY( product_id )
      REFERENCES products( product_id ) 
      ON DELETE CASCADE,    
    CONSTRAINT fk_order_items_orders 
      FOREIGN KEY( order_id )
      REFERENCES orders( order_id ) 
      ON DELETE CASCADE
  );

  插入數據:

--------------------------------------------------------------------------------------
-- Name	       : OT (Oracle Tutorial) Sample Database
-- Link	       : http://www.oracletutorial.com/oracle-sample-database/
-- Version     : 1.0
-- Last Updated: July-28-2017
-- Copyright   : Copyright ?2017 by www.oracletutorial.com. All Rights Reserved.
-- Notice      : Use this sample database for the educational purpose only.
--               Credit the site oracletutorial.com explitly in your materials that
--               use this sample database.
--------------------------------------------------------------------------------------
-- disable FK constraints 
ALTER TABLE order_items DISABLE CONSTRAINT fk_order_items_products;
ALTER TABLE order_items DISABLE CONSTRAINT fk_order_items_orders;
--------------------------------------------------------
--  OT
--------------------------------------------------------
REM INSERTING into OT.ORDER_ITEMS
SET DEFINE OFF;
Insert into OT.ORDER_ITEMS (ORDER_ID,ITEM_ID,PRODUCT_ID,QUANTITY,UNIT_PRICE) values (70,7,32,132,469.99);
Insert into OT.ORDER_ITEMS (ORDER_ID,ITEM_ID,PRODUCT_ID,QUANTITY,UNIT_PRICE) values (73,5,192,124,519.99);

-- enable FK constraints
ALTER TABLE order_items ENABLE CONSTRAINT fk_order_items_products;
ALTER TABLE order_items ENABLE CONSTRAINT fk_order_items_orders;

  數據update

1、標準update語法(經常使用、速度可能最慢)
-- 當更新的表示單個或者被更新的字段不須要關聯錶帶過來,此法是最好的選擇。
update  a 
set a.c2= (select b.c2from  b where a.c1=b.c1)
where exists   (select 1 from   b where a.c1=b.c1)

2、內聯視圖更新(關聯主鍵字段,速度較快)
-- inline view更新法就是更新一個臨時創建的視圖。
-- 方案:更新一個臨時創建的視圖。要求B表的主鍵字段必須在where條件中,而且是以=號來關聯被更新表。
update (select a.c2 as ac2,b.c2 as bc2 from a, b where a.c1=b.c1 and a.c3=’2011’) as M 
set ac2=bc2

3、merge更新法 (關聯字段非主鍵時,速度較快)
merge是oracle特有的語句,語法以下:
MERGE INTO table_name alias1 --主表,即須要被修改的表
USING (table | view | sub_query) alias2 --從表,即來源表
ON (join condition) --鏈接條件
WHEN MATCHED THEN --在匹配的記錄中進行
  UPDATE table_name SET col1 = col_val1, col2 = col2_val --更改主表信息
WHEN NOT MATCHED THEN --在不匹配的狀況下,篩選從表記錄插入到主表【可選】
  INSERT (column_list) VALUES (column_values);

merge into a
using b 
 on (a.c1=b.c1 and a.c3=’2011’)
   when matched then
update a.c2=b.c2

4、快速遊標更新法(複雜邏輯時,效率很高)
begin
    for cur in (select a.rowid  ,b.c2 from  a, b where a.c1=b.c1 and a.c3=’2011’ )  loop
        UPDATE a  set c2=cur.c2  where rowid=cur.rowid;
    end loop;
end;

  刪表

# 刪表
DROP TABLE ot.order_items; 
# 刪行
delete from 表名 where 條件

  基本操做

constraint ca_pk primary key()
constraint c2 foreign key () references b()

select a,b, row_number() over(partition by a order by b) as c from aaa group by a

select a,b,rownum as id from aaa

update AAA set B=B*0.1;
commit;

update aaa set b=rownum where a='x';
commit;

update a
set (x,y)=(select x,f from a,b where a.id=b.id)
where exists(select 1 from a,b where a.id=b.id)

merge into a
using b
on 
when matched then
 update b set 
when not matched then
	insert () values()

insert into aaa(a,b)
values( 'z', 1);
commit;

insert into aaa(a,b)
(
select a, (select avg(b) from aaa)
from aaa
where a <> 'x'
);
commit;

  經典例題

-- 查找與001號同窗所學課程徹底相同的其餘同窗的學號和姓名
select t4.sid, t4.name
from (
	select sid, count(1) c1 
	from course t 
	where c1.sid <> '001'
	group by c1.sid
) t1, (
	select sid, count(1) as c2
	from course t
	where cid in (select cid from course where sid='001')
	group by sid
) t2, (
	select count(1) c3 
	from course t
	where sid='001'
) t3, (
	select sid, name 
	from student t
) t4
where t1.sid = t2.sid and t1.c1 = t2.c2 and t1.c1 = t3.c3 and t1.sid = t4.sid

  參考資料:

ORACLE 中的union(去重並集),union all(不去重並集),intersect(交集),minus(減集)

相關文章
相關標籤/搜索