Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB
ÈÈÃűêÇ©£º c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 ×îÐÂÎÄÕ : Oracle

ÍæתOracle£¨7£©

||-------  pl/sql »ù´¡ -------||
pl/procedural language ¹ý³ÌÓïÑÔ
//´´½¨±í
SQL> create table mytest(
  2  name varchar2(30),
  3  pwd varchar2(30));
//´´½¨¹ý³Ì
create procedure sp_pro1 is
create or replace procedure sp_pro1 is --Èç¹û´æÔÚ¼´Ìæ»»
begin
--Ö´Ðв¿·Ö
insert into mytest values('valen','123');
--½áÊø²¿·Ö
end;
SQL> create or replace procedure sp_pro2 is
  2  begin
  3  --Ö´Ðв¿·Ö
  4  delete from mytest where name='valen';
  5  --½áÊø²¿·Ö
  6  end;
  7  /
//²é¿´¹ý³ÌµÄ´íÎóÐÅÏ¢
show error;
//ÈçºÎµ÷Óô洢¹ý³Ì
1.exec ¹ý³ÌÃû£¨²ÎÊýÖµ1£¬²ÎÊýÖµ2£©£»
2.call ¹ý³ÌÃû£¨²ÎÊýÖµ1£¬²ÎÊýÖµ2£©£»
//pl/sql±à³Ì¹æ·¶
1.µ¥ÐÐ×¢ÊÍ --
2.¶àÐÐ×¢ÊÍ/*...*/
3.¶¨Òå±äÁ¿£¬v_×÷Ϊǰ׺
4.¶¨Òå³£Á¿£¬c_×÷Ϊǰ׺
5.¶¨ÒåÓα꣬_cursor×÷Ϊºó׺
6.¶¨ÒåÀýÍ⣬e_×÷Ϊǰ׺
//¿é½á¹¹ÊÂÒËͼ
declear
/* ¶¨Ò岿·Ö--³£Á¿£¬±äÁ¿£¬Óα꣬ÀýÍ⣬¸´ÔÓÊý¾ÝÀàÐÍ */
begin
/* Ö´Ðв¿·Ö- ......

oracle´´½¨ÊÓͼÖÐÉæ¼°µ½ÁíÍâÒ»¸öÓû§µÄ±íȨÏÞ²»×ãÎÊÌâ

    ÔÚoracleÖд洢¹ý³Ì»òÕßÊÓͼµÈ¶ÔÏó´´½¨Ê±£¬Èç¹ûÉæ¼°µ½ÁíÍâÒ»¸öÓû§µÄ±í£¬¼´Ê¹ÄãÒѾ­grant dbaÁË£¬Ò²²»ÐУ¬±ØÐëÏÔʽµØ¸³Óè²éѯȨÏÞ¡£·ñÔò£¬Äã»á·¢ÏÖÔÚpl/sqlÖпÉÒÔÖ´ÐÐÓï¾ä£¬µ«ÊÇÒ»µ©·Åµ½create Öо͸æËßÄãȨÏÞ²»×ã¡£
grant   select   any     table   to   user ......

ʵÀý½²½âOracleÊý¾Ý¿âÉèÖÃĬÈϱí¿Õ¼äÎÊÌâ

DBAÃǾ­³£»áÓöµ½Ò»¸öÕâÑùÁîÈËÍ·ÌÛµÄÎÊÌ⣺²»ÖªµÀË­ÔÚOracleÉÏ´´½¨ÁËÒ»¸öÓû§£¬´´½¨Ê±£¬Ã»ÓиøÕâ¸öÓû§Ö¸¶¨Ä¬Èϱí¿Õ¼ä£¬ËùÒÔÕâ¸öÓû§¾Í»á²ÉÓÃĬÈϵıí¿Õ¼ä——system±í¿Õ¼ä¡£µ¼ÖÂϵͳ±í¿Õ¼äѸËÙ±»Óû§Êý¾ÝÕ¼Âú£¬Ö±ÖÁå´»ú¡£
ÔÚ10GÖУ¬DBAÓа취±ÜÃâÕâÖÖÎÊÌâÁË——ÔÚÏßÖ¸¶¨ÏµÍ³Ä¬Èϱí¿Õ¼ä£º
ALTER DATABASE DEFAULT TABLESPACE <tsname>;
ͨ¹ýÖ´ÐÐÒÔÉÏÃüÁ¿ÉÒÔÉ趨ϵͳµÄĬÈϱí¿Õ¼ä¡£ÕâÑùµÄ»°£¬ÔÚ´´½¨ÐÂÓû§Ê±£¬Èç¹û²»Ö¸¶¨ËûµÄĬÈϱí¿Õ¼ä£¬¾Í»á²ÉÓÃÉÏÃæÖ¸¶¨µÄϵͳĬÈϱí¿Õ¼ä×÷ΪÕâ¸öÓõÄĬÈϱí¿Õ¼ä¡£
SQL>conn /as sysdba
SQL> create user test1 identified by test1 default tablespace ringidx;
Óû§ÒÑ´´½¨¡£
SQL> alter database default tablespace ring;
Êý¾Ý¿âÒѸü¸Ä¡£
SQL> create user test identified by test;
Óû§ÒÑ´´½¨¡£
SQL> select username, default_tablespace defspace from dba_users where
username=’TEST’;
USERNAME DEFSPACE
————– —————-
TEST RING
µ«ÊÇҪעÒâµÄÊÇ£¬Ò»µ©½«ÏµÍ³Ä¬Èϱí¿Õ¼äÐÞ¸ÄÁËÒ ......

ÔÚOracle 9iÖÐÐ޸ıíµÄ½á¹¹µÄÏà¹ØsqlÓï¾ä

ÓÃsql*plus»òµÚÈý·½¿ÉÒÔÔËÐÐsqlÓï¾äµÄ³ÌÐòµÇ¼Êý¾Ý¿â£º
Ôö¼ÓÒ»¸öÁУº
ALTER TABLE ±íÃû ADD(ÁÐÃû Êý¾ÝÀàÐÍ);
È磺
ALTER TABLE emp ADD(weight NUMBER(38,0));
ÐÞ¸ÄÒ»¸öÁеÄÊý¾ÝÀàÐÍ(Ò»°ãÏÞÓÚÐ޸ij¤¶È£¬ÐÞ¸ÄΪһ¸ö²»Í¬ÀàÐÍʱÓÐÖî¶àÏÞÖÆ):
ALTER TABLE ±íÃû MODIFY(ÁÐÃû Êý¾ÝÀàÐÍ);
È磺
ALTER TABLE emp MODIFY(weight NUMBER(3,0) NOT NULL);
Demo:
ALTER TABLE PY_CCORDER ADD(
 CCORD_REFUNDEDTIMES INTEGER,
 CCORD_REFUNDEDAMOUNT NUMBER(15,2)
);
¸øÁиÄÃû£º
ALTER TABLE ±íÃû RENAME COLUMN µ±Ç°ÁÐÃû TO ÐÂÁÐÃû;
È磺
ALTER TABLE emp RENAME COLUMN weight TO weight_new;
ɾ³ýÒ»¸öÁУº
ALTER TABLE ±íÃû DROP COLUMN ÁÐÃû;
È磺
ALTER TABLE emp DROP COLUMN weight_new;
½«Ò»¸ö±í¸ÄÃû£º
ALTER TABLE µ±Ç°±íÃû RENAME TO бíÃû;
È磺
ALTER TABLE bouns RENAME TO bonus_new ......

ÔÚOracle 9iÖÐÐ޸ıíµÄ½á¹¹µÄÏà¹ØsqlÓï¾ä

ÓÃsql*plus»òµÚÈý·½¿ÉÒÔÔËÐÐsqlÓï¾äµÄ³ÌÐòµÇ¼Êý¾Ý¿â£º
Ôö¼ÓÒ»¸öÁУº
ALTER TABLE ±íÃû ADD(ÁÐÃû Êý¾ÝÀàÐÍ);
È磺
ALTER TABLE emp ADD(weight NUMBER(38,0));
ÐÞ¸ÄÒ»¸öÁеÄÊý¾ÝÀàÐÍ(Ò»°ãÏÞÓÚÐ޸ij¤¶È£¬ÐÞ¸ÄΪһ¸ö²»Í¬ÀàÐÍʱÓÐÖî¶àÏÞÖÆ):
ALTER TABLE ±íÃû MODIFY(ÁÐÃû Êý¾ÝÀàÐÍ);
È磺
ALTER TABLE emp MODIFY(weight NUMBER(3,0) NOT NULL);
Demo:
ALTER TABLE PY_CCORDER ADD(
 CCORD_REFUNDEDTIMES INTEGER,
 CCORD_REFUNDEDAMOUNT NUMBER(15,2)
);
¸øÁиÄÃû£º
ALTER TABLE ±íÃû RENAME COLUMN µ±Ç°ÁÐÃû TO ÐÂÁÐÃû;
È磺
ALTER TABLE emp RENAME COLUMN weight TO weight_new;
ɾ³ýÒ»¸öÁУº
ALTER TABLE ±íÃû DROP COLUMN ÁÐÃû;
È磺
ALTER TABLE emp DROP COLUMN weight_new;
½«Ò»¸ö±í¸ÄÃû£º
ALTER TABLE µ±Ç°±íÃû RENAME TO бíÃû;
È磺
ALTER TABLE bouns RENAME TO bonus_new ......

oracle sql*plus set &spool½éÉÜ(Ò»)

1). ÉèÖõ±Ç°sessionÊÇ·ñ¶ÔÐ޸ĵÄÊý¾Ý½øÐÐ×Ô¶¯Ìá½» :SET AUTO[COMMIT] {ON|OFF|IMM[EDIATE]| n}
SQL> set autocommit off
2)£®ÔÚÓÃstartÃüÁîÖ´ÐÐÒ»¸ösql½Å±¾Ê±£¬ÊÇ·ñÏÔʾ½Å±¾ÖÐÕýÔÚÖ´ÐеÄSQLÓï¾ä :SET ECHO {ON|OFF}
SQL> set echo on
3).ÊÇ·ñÏÔʾµ±Ç°sqlÓï¾ä²éѯ»òÐ޸ĵÄÐÐÊý
SQL> SET FEED[BACK] {6|n|ON|OFF}
ĬÈÏÖ»Óнá¹û´óÓÚ6ÐÐʱ²ÅÏÔʾ½á¹ûµÄÐÐÊý¡£Èç¹ûset feedback 1 £¬Ôò²»¹Ü²éѯµ½¶àÉÙÐж¼·µ»Ø¡£µ±Îªoff ʱ£¬Ò»Âɲ»ÏÔʾ²éѯµÄÐÐÊý
 SQL> set feed off
SQL> select * from dual;
D
-
X
SQL> set feed on
SQL> select * from dual;
D
-
X
ÒÑÑ¡Ôñ 1 ÐС£(Çø±ðÓÚ´Ë)
4).ÊÇ·ñÏÔʾÁбêÌâ
SQL> SET HEA[DING] {ON|OFF}
µ±set heading off ʱ£¬ÔÚÿҳµÄÉÏÃæ²»ÏÔʾÁбêÌ⣬¶øÊÇÒÔ¿Õ°×ÐдúÌæ
SQL> set hea on
SQL> select * from a;
        ID SNAME                                   ......

oracle sql*plus set &spool½éÉÜ(Ò»)

1). ÉèÖõ±Ç°sessionÊÇ·ñ¶ÔÐ޸ĵÄÊý¾Ý½øÐÐ×Ô¶¯Ìá½» :SET AUTO[COMMIT] {ON|OFF|IMM[EDIATE]| n}
SQL> set autocommit off
2)£®ÔÚÓÃstartÃüÁîÖ´ÐÐÒ»¸ösql½Å±¾Ê±£¬ÊÇ·ñÏÔʾ½Å±¾ÖÐÕýÔÚÖ´ÐеÄSQLÓï¾ä :SET ECHO {ON|OFF}
SQL> set echo on
3).ÊÇ·ñÏÔʾµ±Ç°sqlÓï¾ä²éѯ»òÐ޸ĵÄÐÐÊý
SQL> SET FEED[BACK] {6|n|ON|OFF}
ĬÈÏÖ»Óнá¹û´óÓÚ6ÐÐʱ²ÅÏÔʾ½á¹ûµÄÐÐÊý¡£Èç¹ûset feedback 1 £¬Ôò²»¹Ü²éѯµ½¶àÉÙÐж¼·µ»Ø¡£µ±Îªoff ʱ£¬Ò»Âɲ»ÏÔʾ²éѯµÄÐÐÊý
 SQL> set feed off
SQL> select * from dual;
D
-
X
SQL> set feed on
SQL> select * from dual;
D
-
X
ÒÑÑ¡Ôñ 1 ÐС£(Çø±ðÓÚ´Ë)
4).ÊÇ·ñÏÔʾÁбêÌâ
SQL> SET HEA[DING] {ON|OFF}
µ±set heading off ʱ£¬ÔÚÿҳµÄÉÏÃæ²»ÏÔʾÁбêÌ⣬¶øÊÇÒÔ¿Õ°×ÐдúÌæ
SQL> set hea on
SQL> select * from a;
        ID SNAME                                   ......

oracle ³£ÓÃÐÔÄܲéѯSQL·ÖÏí

select count(1) from dictionary;
select * from dba_data_files;
select count(1) from dba_objects t where t.owner='BESTTONE';
select * from dba_tablespaces t where t.tablespace_name='BESTTONE';
select count(1) from dba_tables t where t.owner='BESTTONE';
select t.table_name,t.comments from dictionary  t where t.table_name like 'V$%';
select * from dba_constraints;
select * from dba_cons_columns;
select * from dba_tablespaces t where t.tablespace_name='SIM002';
CREATE TABLESPACE SS DATAFILE 'D:\ORACLE\ORADATA\BSTO\SS.DBF' SIZE 1M;
SELECT T.tablespace_name, T.status from DBA_TABLESPACES T;
SELECT T.TABLESPACE_NAME,T.FILE_NAME from DBA_DATA_FILES T;
ALTER TABLESPACE SIM002 OFFLINE;
ALTER TABLESPACE SIM002 ONLINE;
SELECT T.os_username,
       T.username,
       T.terminal,
       DECODE(T.returncode,
              '0' ......

oracle ³£ÓÃÐÔÄܲéѯSQL·ÖÏí

select count(1) from dictionary;
select * from dba_data_files;
select count(1) from dba_objects t where t.owner='BESTTONE';
select * from dba_tablespaces t where t.tablespace_name='BESTTONE';
select count(1) from dba_tables t where t.owner='BESTTONE';
select t.table_name,t.comments from dictionary  t where t.table_name like 'V$%';
select * from dba_constraints;
select * from dba_cons_columns;
select * from dba_tablespaces t where t.tablespace_name='SIM002';
CREATE TABLESPACE SS DATAFILE 'D:\ORACLE\ORADATA\BSTO\SS.DBF' SIZE 1M;
SELECT T.tablespace_name, T.status from DBA_TABLESPACES T;
SELECT T.TABLESPACE_NAME,T.FILE_NAME from DBA_DATA_FILES T;
ALTER TABLESPACE SIM002 OFFLINE;
ALTER TABLESPACE SIM002 ONLINE;
SELECT T.os_username,
       T.username,
       T.terminal,
       DECODE(T.returncode,
              '0' ......
×ܼǼÊý:3994; ×ÜÒ³Êý:666; ÿҳ6 Ìõ; Ê×Ò³ ÉÏÒ»Ò³ [11] [12] [13] [14] 15 [16] [17] [18] [19] [20]  ÏÂÒ»Ò³ βҳ
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ