1. Oracle 命令
再有值的情況下不能直接修改欄位屬性
但是可以通過其他辦法得到
舉個例子
1.先增加一個欄位 alter table table_name add fieldname_C int;
2.更新改欄位為你要的
update table_name set fieldname_C=to_number(fieldname_A)+50 where 日期條件;
commit;
3.刪除A欄位
alter table table_name drop column ....
4.更新C欄位名字為A欄位
alter table table_name rename column C to A;
2. Oracle常見的命令
太多了, 下面的只是一小部分oracle常用命令(我的筆記)
oracle里常用命令第一章:日誌管理 1.forcing log switches
sql> alter system switch logfile;
2.forcing checkpoints
sql> alter system checkpoint;
3.adding online redo log groups
sql> alter database add logfile [group 4]
sql> ('/disk3/log4a.rdo','/disk4/log4b.rdo') size 1m;
4.adding online redo log members
sql> alter database add logfile member
sql> '/disk3/log1b.rdo' to group 1,
sql> '/disk4/log2b.rdo' to group 2;
5.changes the name of the online redo logfile
sql> alter database rename file 'c:/oracle/oradata/oradb/redo01.log'
sql> to 'c:/oracle/oradata/redo01.log';
6.drop online redo log groups
sql> alter database drop logfile group 3;
7.drop online redo log members
sql> alter database drop logfile member 'c:/oracle/oradata/redo01.log';
8.clearing online redo log files
sql> alter database clear [unarchived] logfile 'c:/oracle/log2a.rdo';
9.using logminer analyzing redo logfiles
a. in the init.ora specify utl_file_dir = ' '
b. sql> execute dbms_logmnr_d.build('oradb.ora','c:\oracle\oradb\log');
c. sql> execute dbms_logmnr_add_logfile('c:\oracle\oradata\oradb\redo01.log',
sql> dbms_logmnr.new);
d. sql> execute dbms_logmnr.add_logfile('c:\oracle\oradata\oradb\redo02.log',
sql> dbms_logmnr.addfile);
e. sql> execute dbms_logmnr.start_logmnr(dictfilename=>'c:\oracle\oradb\log\oradb.ora');
f. sql> select * from v$logmnr_contents(v$logmnr_dictionary,v$logmnr_parameters
sql> v$logmnr_logs);
g. sql> execute dbms_logmnr.end_logmnr; 第二章:表空間管理
1.create tablespaces
sql> create tablespace tablespace_name datafile 'c:\oracle\oradata\file1.dbf' size 100m,
sql> 'c:\oracle\oradata\file2.dbf' size 100m minimum extent 550k [logging/nologging]
sql> default storage (initial 500k next 500k maxextents 500 pctinccease 0)
sql> [online/offline] [permanent/temporary] [extent_management_clause]
2.locally managed tablespace
sql> create tablespace user_data datafile 'c:\oracle\oradata\user_data01.dbf'
sql> size 500m extent management local uniform size 10m;
3.temporary tablespace
sql> create temporary tablespace temp tempfile 'c:\oracle\oradata\temp01.dbf'
sql> size 500m extent management local uniform size 10m;
4.change the storage setting
sql> alter tablespace app_data minimum extent 2m;
sql> alter tablespace app_data default storage(initial 2m next 2m maxextents 999);
5.taking tablespace offline or online
sql> alter tablespace app_data offline;
sql> alter tablespace app_data online;
6.read_only tablespace
sql> alter tablespace app_data read only|write;
7.droping tablespace
sql> drop tablespace app_data including contents;
8.enableing automatic extension of data files
sql> alter tablespace app_data add datafile 'c:\oracle\oradata\app_data01.dbf' size 200m
sql> autoextend on next 10m maxsize 500m;
9.change the size fo data files manually
sql> alter database datafile 'c:\oracle\oradata\app_data.dbf' resize 200m;
10.Moving data files: alter tablespace
sql> alter tablespace app_data rename datafile 'c:\oracle\oradata\app_data.dbf'
sql> to 'c:\oracle\app_data.dbf';
11.moving data files:alter database
sql> alter database rename file 'c:\oracle\oradata\app_data.dbf'
sql> to 'c:\oracle\app_data.dbf'; 第三章:表 1.create a table
sql> create table table_name (column datatype,column datatype]....)
sql> tablespace tablespace_name [pctfree integer] [pctused integer]
sql> [initrans integer] [maxtrans integer]
sql> storage(initial 200k next 200k pctincrease 0 maxextents 50)
sql> [logging|nologging] [cache|nocache]
2. an existing table
sql> create table table_name [logging|nologging] as subquery
3.create temporary table
sql> create global temporary table xay_temp as select * from xay;
on commit preserve rows/on commit delete rows
4.pctfree = (average row size - initial row size) *100 /average row size
pctused = 100-pctfree- (average row size*100/available data space)
5.change storage and block utilization parameter
sql> alter table table_name pctfree=30 pctused=50 storage(next 500k
sql> minextents 2 maxextents 100);
6.manually allocating extents
sql> alter table table_name allocate extent(size 500k datafile 'c:/oracle/data.dbf');
7.move tablespace
sql> alter table employee move tablespace users;
8.deallocate of unused space
sql> alter table table_name deallocate unused [keep integer]
9.truncate a table
sql> truncate table table_name;
10.drop a table
sql> drop table table_name [cascade constraints];
11.drop a column
sql> alter table table_name drop column comments cascade constraints checkpoint 1000;
alter table table_name drop columns continue;
12.mark a column as unused
sql> alter table table_name set unused column comments cascade constraints;
alter table table_name drop unused columns checkpoint 1000;
alter table orders drop columns continue checkpoint 1000
data_dictionary : dba_unused_col_tabs 第四章:索引 1.creating function-based indexes
sql> create index summit.item_quantity on summit.item(quantity-quantity_shipped);
2.create a B-tree index
sql> create [unique] index index_name on table_name(column,.. asc/desc) tablespace
sql> tablespace_name [pctfree integer] [initrans integer] [maxtrans integer]
sql> [logging | nologging] [nosort] storage(initial 200k next 200k pctincrease 0
sql> maxextents 50);
3.pctfree(index)=(maximum number of rows-initial number of rows)*100/maximum number of rows
4.creating reverse key indexes
sql> create unique index xay_id on xay(a) reverse pctfree 30 storage(initial 200k
sql> next 200k pctincrease 0 maxextents 50) tablespace indx;
5.create bitmap index
sql> create bitmap index xay_id on xay(a) pctfree 30 storage( initial 200k next 200k
sql> pctincrease 0 maxextents 50) tablespace indx;
6.change storage parameter of index
sql> alter index xay_id storage (next 400k maxextents 100);
7.allocating index space
sql> alter index xay_id allocate extent(size 200k datafile 'c:/oracle/index.dbf');
8.alter index xay_id deallocate unused;
3. oracle基本命令
1.用戶有哪些表空間概念錯了,只能看用戶用了哪些user_tablespaces視圖就可以
select tablespace_name from dba_tablespaces;
2.變數填自己的
select owner,table_name from dba_tables where tablespace_name='SYSTEM';
select tablespace_name from dba_tables where table_name='EMP';
4. 誰能告訴我oracle資料庫常用命令啊
1、su – oracle 不是必需,適合於沒有DBA密碼時使用,可以不用密碼來進入sqlplus界面。
2、sqlplus /nolog 或sqlplus system/manager 或./sqlplus system/manager@ora9i;
3、SQL>connect / as sysdba ;(as sysoper)或
connect internal/oracle AS SYSDBA ;(scott/tiger)
conn sys/change_on_install as sysdba;
4、SQL>startup; 啟動資料庫實例
5、 查看當前的所有資料庫: select * from v$database;
select name from v$database;
desc v$databases; 查看資料庫結構欄位
7、怎樣查看哪些用戶擁有SYSDBA、SYSOPER許可權:
SQL>select * from V_$PWFILE_USERS;
Show user;查看當前資料庫連接用戶
8、進入test資料庫:database test;
9、查看所有的資料庫實例:select * from v$instance;
如:ora9i
10、查看當前庫的所有數據表:
SQL> select TABLE_NAME from all_tables;
select * from all_tables;
SQL> select table_name from all_tables where table_name like 『
u
』;
TABLE_NAME———————————————default_auditing_options
11、查看錶結構:desc all_tables;
12、顯示CQI.T_BBS_XUSER的所有欄位結構:
desc CQI.T_BBS_XUSER;
13、獲得CQI.T_BBS_XUSER表中的記錄:
select * from CQI.T_BBS_XUSER;
14、增加資料庫用戶:(test11/test)
create user test11 identified by test default tablespace users Temporary TABLESPACE Temp;
15、用戶授權:
grant connect,resource,dba to test11;
grant sysdba to test11;
commit;
16、更改資料庫用戶的密碼:(將sys與system的密碼改為test.)
alter user sys indentified by test;
alter user system indentified by test;
5. 關於oracle命令
alter table 表名 modify 欄位名 not null;
不過你那個欄位要是原來有空的,你執行會報錯
6. oracle啟動命令
啟動的階段和啟動的命令如下:
1、nomount:alter database open,此階段需要參數文件支持;
2、mount:alter database mount,此階段需要控制文件支持;
3、open :alter database open,此階段資料庫會驗證所有的數據文件和redo。
4、也可以一條命令直接起庫:startup
具體方法/步驟:
打開命令行窗口界面,可以同時按住「ctrl+R」鍵,在彈出來的運行窗口中輸入cmd。
7. 求Oracle 常用命令!
02.oracle函數
1數值型函數
1.01.返回絕對值.abs()
1.02.返回正負值.sign()
1.03.返回較大的最小整數.ceil()
1.04.返回較小的最大整數.floor()
1.05.返回x的y次冪.power(x,y)
1.06.返回常量e的y次冪.exp(y)
1.07.返回以x為底的y的對數.log(x,y)
1.08.返回以常量e為底的y的對數.ln(y)
1.09.返回x除以y的余數.mod(x,y)
1.10.返回四捨五入後的值.round()
1.11.返回截取後的值.trunc()
1.12.返回x的平方根.sqrt(x)
1.30.三角函數
2字元型函數
2.01.返回字元的ASCII碼.ASCII()
2.02.返回ASCII碼為x的字元.CHR(x)
2.03.連接兩個字元串.CONCAT()
2.04.把每個單詞首個字母變為大寫.INITCAP()
2.05.將整個字元串轉換為小寫.LOWER()
2.06.將整個字元串轉換為大寫.UPPER()
2.07.把每個單詞首個字母變為大寫.NLS_INITCAP()
2.08.把整個字元串轉換為小寫.NLS_LOWER()
2.09.將整個字元串轉換為大寫.NLS_UPPER()
2.10.字元串中搜索字元位置(全形算1字元).INSTR()
2.11.字元串中搜索字元位置(全形算2字元).INSTRB()
2.12.返回字元串的長度(全形算1字元).LENGTH()
2.12.返回字元串的長度(全形算2字元).LENGTHB()
2.13.返回字元串的長度(其它).LENGTHC().LENGTH2().LENGTH4()
2.14.在左邊添加字元.LPAD()
2.15.在右邊添加字元.RPAD()
2.16.刪除左邊字元串.LTRIM()
2.17.刪除右邊字元串.RTRIM()
2.18.替換子字元串.REPLACE()
2.19.字元串語音表示形式.SOUNDEX()
2.20.截取子字元串(全形算1字元).SUBSTR()
2.21.截取子字元串(全形算2字元).SUBSTRB()
2.22.替換子字元.TRANSLATE()
2.23.刪除左邊和右邊字元串.TRIM()
3日期函數
3.01.返回系統當前日期.sysdate
3.02.返回指定月數後的日期.add_months()
3.03.返回本月最後一天的日期.last_day()
3.04.返回2個日期間隔月數.months_between()
3.05.返回時區的對應時間.NEW_TIME()
3.06.四捨五入後的期間第一天.round()
3.07.返回日期所在期間的第一天.trunc()
3.08.返回下周某一天的日期.NEXT_DAY()
3.09.提取時間日期中數據.extract()
3.10.返回會話中的日期和時間.localtimestamp
3.11.返回當前會話時區中的當前日期和時間.current_timestamp
3.12.返回當前會話時區中的當前日期.current_date
3.13.返回資料庫時區設置.dbtimezone
3.14.返回當前會話時區.SESSIONTIMEZONE
3.29.變動日期時間數值.INTERVAL
4轉換函數
4.01.字元串轉換為rowid值.chartorowid()
4.02.rowid值轉換字元串.ROWIDTOCHAR()
4.03.字元串語言字元集轉換.CONVERT()
4.04.16進制轉換為二進制.HEXTORAW()
4.05.二進制轉換為16進制.RAWTOHEX()
4.06.數字或日期轉換為字元串.TO_CHAR()
4.07.字元串轉換為日期型.TO_DATE()
4.08.字元串轉換為數字型.TO_NUMBER()
4.09.半形轉化為全形.TO_MULTI_BYTE()
4.10.全形轉化為半形.to_single_byte()
4.11.字元集名稱轉為ID.nls_charset_id()
4.12.字元集ID轉為名稱.nls_charset_name()
5聚組函數
5.01.統計平均值.AVG()
5.02.統計合計值.SUM()
5.03.統計標准誤差.STDDEV()
5.04.統計方差.VARIANCE()
5.05.統計查詢所得的行數.count()
5.06.統計最大值.MAX()
5.07.統計最小值.MIN()
6分析函數
6.00.oracle分析函數
6.01.連續求和分析函數.sum(...) over(...)
6.02.排序值分析函數.RANK()和dense_rank()
6.03.排序後順序號分析函數.ROW_NUMBER()
6.04.取上下行數據分析函數.lag()和lead()
7其它函數
7.01.返回數據類型、位元組長度和在內部的存儲位置.DUMP()
7.02.返回表達式列表中最大值.greatest()
7.03.返回表達式列表中最小值.least()
7.04.為空值賦值.nvl().nvl2()
7.05.返回當前會話對應的資料庫用戶名.user
7.06.返回當前會話所對應的用戶id號.uid
7.07.返回當前會話上下文屬性.userenv()
7.08.條件取值.decode()
7.09.相等返回空.NULLIF()
7.10.返回列表第一個不為空的表達式.COALESCE()
7.11.返回當前行號.rownum
7.12.指定一個外部二進制文件.BFILENAME()
7.13.返回X的大小(位元組)數.VSIZE(X)
7.14.條件取值.case when then end
7.15.產生32位的隨機數.sys_guid()
7.16.返回系統數據.SYS_CONTEXT()
7.17.生成隨機數值或者字元串dbms_random
7.18.取得Internet中的主機名和IP地址
8. oracle怎麼用命令(sql語句)創建資料庫
樓主,您可以這樣寫SQL語句 1.以jason用戶登陸庫: CONNECT jason/orcale 2.例如創建Jason用戶: create user jason identified by orcale;(這里jason是您創建的用戶名稱,orcale是設置的密碼;) 3.grant create ,resource to username;
9. oracle常用命令有哪些
太多了, 下面的只是一小部分oracle常用命令(我的筆記)
oracle里常用命令第一章:日誌管理 1.forcing log switches
sql> alter system switch logfile;
2.forcing checkpoints
sql> alter system checkpoint;
3.adding online redo log groups
sql> alter database add logfile [group 4]
sql> ('/disk3/log4a.rdo','/disk4/log4b.rdo') size 1m;
4.adding online redo log members
sql> alter database add logfile member
sql> '/disk3/log1b.rdo' to group 1,
sql> '/disk4/log2b.rdo' to group 2;
5.changes the name of the online redo logfile
sql> alter database rename file 'c:/oracle/oradata/oradb/redo01.log'
sql> to 'c:/oracle/oradata/redo01.log';
6.drop online redo log groups
sql> alter database drop logfile group 3;
7.drop online redo log members
sql> alter database drop logfile member 'c:/oracle/oradata/redo01.log';
8.clearing online redo log files
sql> alter database clear [unarchived] logfile 'c:/oracle/log2a.rdo';
9.using logminer analyzing redo logfiles
a. in the init.ora specify utl_file_dir = ' '
b. sql> execute dbms_logmnr_d.build('oradb.ora','c:\oracle\oradb\log');
c. sql> execute dbms_logmnr_add_logfile('c:\oracle\oradata\oradb\redo01.log',
sql> dbms_logmnr.new);
d. sql> execute dbms_logmnr.add_logfile('c:\oracle\oradata\oradb\redo02.log',
sql> dbms_logmnr.addfile);
e. sql> execute dbms_logmnr.start_logmnr(dictfilename=>'c:\oracle\oradb\log\oradb.ora');
f. sql> select * from v$logmnr_contents(v$logmnr_dictionary,v$logmnr_parameters
sql> v$logmnr_logs);
10. oracle中事務的命令有哪些
在存儲過程中寫一個語句用於對主表進行修改,然後
針對主表寫一個update觸發器,當主表進行修改進相關的副表就也能進行相應的修改了。
事務沒有提交之前是不會對資料庫中的數據進行操作的,只有commit以後才能實現,所以
要想得到修改後的記錄,必須在提交以後將你所需要值賦到一個變數中然後返回這個變數。
再在一個新的存儲過程中調用那一個專門用來獲取返回值的存儲過程,下次調用此方法時,
只需調用此新的存儲過程就行了,既獲取到修改後的值又執行了修改操作,何樂而不為呢?
至於怎麼獲取未修改以前的值就不用我說了,我知道你會做。
這樣的話,這個問題就解決了。。
這是我個人的觀點,如果不正確請予以批評和指證。謝謝。