@ ("at" sign) ------------- Runs the SQL*Plus statements in the specified script. The script can be called from the local file system or a web server. Only the url form is supported in iSQL*Plus.
@ {url|file_name[.ext]} [arg ...]
where url supports HTTP and FTP protocols in the form:
@@ (double "at" sign) --------------------- Runs the specified script. This command is almost identical to the @ command. It is useful for running nested scripts because it has the additional functionality of looking for the nested script in the same url or path as the calling script. Only the url form is supported in iSQL*Plus.
@@ {url|file_name[.ext]} [arg ...]
---4 / 执行当前缓冲区的命令(运行上一次执行的SQL语句).
SQL> HELP /
/ (slash) --------- Executes the most recently executed SQL command or PL/SQL block which is stored in the SQL buffer. Use slash (/) at the command prompt or line number prompt in SQL*Plus command line, oruse slash (/) in the iSQL*Plus Workspace. The buffer has no command history and does not record SQL*Plus commands.
例子:如下图所示: ---5 ACCEPT SQL> HELP ACCEPT
ACCEPT可以修改既有变量,也可定义一个新变量并等待用户输入初始值。
ACCEPT ------ Reads a line of input and stores it in a given substitution variable. In iSQL*Plus, displays the Input Required screen for you to enter a value for the substitution variable.
ACC[EPT] variable [NUM[BER]|CHAR| DATE | BINARY_FLOAT | BINARY_DOUBLE] [FOR[MAT] format] [DEF[AULT]default] [PROMPT text | NOPR[OMPT]] [HIDE]
---6 APPEND 将text附加到当前行之后。
SQL> HELP APPEND
APPEND ------ Adds textto the endof the current line in the SQL buffer.
A[PPEND]text
Not available in iSQL*Plus
---7 ARCHIVE LOG 启动或停止归档在线重做日志文件。
SQL> HELP ARCHIVE LOG
ARCHIVE LOG ----------- Starts or stops automatic archiving of online redo log files, manually (explicitly) archives specified redo log files, or displays information about redo log files.
ATTRIBUTE --------- Specifies display characteristics for a given attribute of an Object Type column, such as the format ofNUMBER data. Columns and attributes should not have the same names as they share a common namespace. Lists the current display characteristics for a single attribute orall attributes.
whereoption represents one of the following terms or clauses: ALI[AS] alias CLE[AR] FOR[MAT] format LIKE {type_name.attribute_name | alias} ON|OFF
---9 BREAK break命令抑制重复的列或表达你的名字的默认值。因此,要制止重复在ORDER BY子句中指定的列值,使用最简单的形式break命令: SQL> HELP BREAK
BREAK ----- Specifies where changes occur in a report and the formatting action to perform, such as: - suppressing display of duplicate valuesfor a given column - skipping a line each time a given column value changes (In iSQL*Plus, onlywhen Preformatted Output isON) - printing computed figures each time a given column value changes or at the endof the report. Enter BREAKwith no clauses to list the currentBREAK definition.
BRE[AK][ON report_element [action [action]]] ...
where report_element has the following syntax: {column| expression | ROW | REPORT}
andwhere action has the following syntax: [SKI[P] n |[SKI[P]] PAGE] [NODUP[LICATES]| DUP[LICATES]]
The SKIP optionisnot supported in iSQL*Plus
---10 BTITLE 设置格式化页脚
SQL> HELP BTITLE ;
BTITLE ------ Places and formats a specified title at the bottom of each report page, or lists the current BTITLE definition.
BTI[TLE][printspec [text|variable] ...] |[OFF|ON]
where printspec represents one or more of the following clauses:
Changes the first occurrence of the specified texton the current line of the SQL buffer. The buffer has no command history list and does not record SQL*Plus commands.
C[HANGE] sepchar old [sepchar [new[sepchar]]]
Not available in iSQL*Plus
---12 CLEAR 清除或重设当前指定配置的值。CLEAR BUFFER 即清空缓存区所有行。
Resets or erases the current value or setting for the specified option.
CL[EAR]option ...
whereoption represents one of the following clauses: BRE[AKS] BUFF[ER] COL[UMNS] COMP[UTES] SCR[EEN] SQL TIMI[NG]
CLEAR SCREEN isnot available in iSQL*Plus
例子: CLEAR BUFFER;
CLEAR SQL;
---13 COLUMN 用于格式化列标题和列数据的现实格式。
Specifies display attributes for a given column, such as: -textfor the column heading - alignment for the column heading - format forNUMBER data - wrapping ofcolumn data Also lists the current display attributes for a singlecolumn orall columns.
COL[UMN][{column | expr} [option ...] ]
whereoption represents one of the following clauses: ALI[AS] alias CLE[AR] ENTMAP {ON|OFF} FOLD_A[FTER] FOLD_B[EFORE] FOR[MAT] format HEA[DING]text JUS[TIFY] {L[EFT]| C[ENTER]| R[IGHT]} LIKE {expr | alias} NEWL[INE] NEW_V[ALUE] variable NOPRI[NT]| PRI[NT] NUL[L]text OLD_V[ALUE] variable ON|OFF WRA[PPED]| WOR[D_WRAPPED]| TRU[NCATED]
例子:
---14 COMPUTE In combination with the BREAK command, calculates and prints summary lines using various standard computations. Also lists allCOMPUTE definitions.
COMP[UTE][function [LAB[EL]text] ... OF {expr|column|alias} ... ON {expr|column|alias|REPORT|ROW} ...]
CONNECT ------- Connects a given username to the Oracle Database. When you run a CONNECT command, the site profile, glogin.sql, and the user profile, login.sql, are processed in that order. CONNECT does not reprompt for username or password if the initial connection does not succeed.
CONN[ECT][{logon|/|proxy} [AS {SYSOPER|SYSDBA}]]
where logon has the following syntax: username[/password][@connect_identifier]
Copies data from a query to a tablein the same or another database. COPY supports CHAR, DATE, LONG, NUMBERandVARCHAR2.
COPY {FROMdatabase|TOdatabase|FROMdatabaseTOdatabase} {APPEND|CREATE|INSERT|REPLACE} destination_table [(column, column, column, ...)] USING query
wheredatabase has the following syntax: username[/password]@connect_identifier
---17 DEFINE 定义替换变量并附值给它,或列出指定赋值变量值或所有变量 Specifies a substitution variable and assigns a CHAR value to it, or lists the value and variable type of a single variable orall variables.
---18 DEL DEL删除命令缓冲区的某一行。 DEL 删除当前行 DEL n 删除第n行。 Deletes one or more lines of the SQL buffer. The buffer has no command history list and does not record SQL*Plus commands.
DEL [n | n m | n * | n LAST | * | * n | * LAST | LAST]
Lists the column definitions for a table, view, or synonym or the specifications for a functionorprocedure.
DESC[RIBE] {[schema.]object[@connect_identifier]}
例子: DESC SCOTT.EMP;
SQL>DESC SCOTT.EMP; 名称 是否为空? 类型 ----------------------------------------- -------- ----------------------- EMPNO NOTNULLNUMBER(4) ENAME VARCHAR2(10) JOB VARCHAR2(9) MGR NUMBER(4) HIREDATE DATE SAL NUMBER(7,2) COMM NUMBER(7,2) DEPTNO NUMBER(2)
---20 DISCONNECT 让当前用户从ORACLE数据库断开,但是不退出 SQL*PLUS
Commits pending changes to the databaseand logs the current user out of Oracle, but does notexit SQL*Plus. In SQL*Plus command line, useEXITor QUIT tolog out of Oracle andreturn control to your computer''s operating system. In iSQL*Plus, click the Logout button tolog out of Oracle.
DISC[ONNECT]
例子 SQL> DISCONNECT; 从 Oracle Database 10g Enterprise Edition Release 10.2.0.1.0- Production With the Partitioning, OLAP and Data Mining options 断开
Invokes an operating system text editor on the contents of the specified fileoron the contents of the SQL buffer. The buffer has no command history list and does not record SQL*Plus commands.
ED[IT][file_name[.ext]]
Not available in iSQL*Plus
例子:不指定文件名 SQL> EDIT F:/
会创建一个*。sql文件,如下图所示
SQL> EDIT F:/123.TXT 创建123.txt文件。如下图所示
---22 EXECUTE 执行存储过程或PL/SQL块
Executes a single PL/SQL statement or runs a stored procedure.
EXEC[UTE] statement
---23 EXIT 退出SQL*PLUS
Commits or rolls back all pending changes, logs out of Oracle, terminates SQL*Plus andreturns control to the operating system. In iSQL*Plus, commits or rolls back all pending changes, stops processing the current iSQL*Plus script andreturns focus to the Workspace. There is no way to access the return code in iSQL*Plus. In iSQL*Plus click the Logout button tolog out of Oracle Database.
Loads a SQL statement or PL/SQL block from a script into the SQL buffer. In iSQL*Plus click the Load Script button toload a script into the Workspace. The buffer has no command history list and does not record SQL*Plus commands.
GET [FILE]file_name[.ext][LIST | NOLIST]
Not available in iSQL*Plus
例子:SQL> GET FILE F:/11.EXT LIST 11111111 2*111111
其中1,2所列内容是我放在11.EXT中的内容
---25 HOST HOST ---- Executes an operating system command without leaving SQL*Plus. Enter HOST without command to display an operating system prompt. You can then enter multiple operating system commands.
HO[ST][command]
Not available in iSQL*Plus
---26 INPUT INPUT ----- Adds one or more new lines oftext after the current line in the SQL buffer. The buffer has no command history list and does not record SQL*Plus commands.
I[NPUT][text]
Not available in iSQL*Plus
---27 LIST 列出SQL*Plus缓存区的所有行或指定的N行语句。例如 LIST N; LIST ---- Lists one or more lines of the most recently executed SQL command or PL/SQL block which is stored in the SQL buffer. Enter LIST with no clauses to list all lines. In SQL*Plus command-line you can also use ";" to list all the lines in the SQL buffer. The buffer has no command history list and does not record SQL*Plus commands.
L[IST][n | n m | n * | n LAST | * | * n | * LAST | LAST]
例子: SQL> LIST 1*SELECT*FROM SCOTT.EMP
---28 PASSWORD; 更改数据库用户密码,不指定用户,则默认跟改SYS用户账号
PASSWORD -------- Allows you to change a password without displaying it on an input device. In iSQL*Plus, use the Password screen to change your password.
---29 PAUSE; PAUSE ----- Displays the specified textthen waits for the userto press RETURN. In iSQL*Plus, displays the Next Page button which the user must click tocontinue.
PAU[SE][text]
---30 PRINT; 显示当前绑定变量值或列出所有绑定变量
PRINT ----- Displays the currentvaluesof bind variables, or lists all bind variables.
PROMPT ------ Sends the specified message or a blank line to the users screen.
PRO[MPT][text]
例子: SQL> PROMPT HELLO KERRY HELLO KERRY
---32 QUIT; 提交或回滚所有的变化,退出ORACLE,中断SQL*PLUS。 QUIT (Identical toEXIT) ---- Commits or rolls back all pending changes, logs out of Oracle, terminates SQL*Plus andreturns control to the operating system. In iSQL*Plus, commits or rolls back all pending changes, stops processing the current iSQL*Plus script andreturns focus to the Workspace. There is no way to access the return code in iSQL*Plus. In iSQL*Plus click the Logout button tolog out of Oracle Database.
---33 RECOVER; RECOVER ------- Performs media recovery on one or more tablespaces, one or more datafiles, or the entire database.
Because of possible network timeouts, it is recommended that you use SQL*Plus command-line, not iSQL*Plus, forlong running DBA operations such as RECOVER.
where printspec represents one or more of the following clauses: COL n LE[FT] BOLD S[KIP][n] CE[NTER] FORMAT text TAB n R[IGHT]
--37 HELP RESERVED WORDS (SQL); 查看SQL中保留关键字。有时候在写脚本时应该避免使用SQL保留关键字做变量、表名、字段名等 如果你不确认自己定义的变量是否是保留关键字,就可以用这个命令看看。如果你只想查看SQL的保留 关键字 可以用 HELP RESERVED WORDS (SQL),如果想查看两者就直接输入HELP RESERVED WORDS 即可。
RESERVED WORDS (SQL) ----------------------- PL/SQL Reserved Words have special meaning in PL/SQL, and may not be used for identifier names (unless enclosed in "quotes").
---38 HELP RESERVED WORDS (PL/SQL); 查看PL/SQL中保留关键字。类似上面命令。
RESERVED WORDS (SQL) -------------------- SQL Reserved Words have special meaning in SQL, and may not be used for identifier names unless enclosed in "quotes".
An asterisk (*) indicates words are also ANSI Reserved Words.
Oracle prefixes implicitly generated schema object and subobject names with "SYS_". To avoid name resolution conflict, Oracle discourages you from prefixing your schema object and subobject names with "SYS_".
---39 RUN 运行缓存区中保存的语句。 RUN --- Lists and executes the most recently executed SQL command or PL/SQL block which is stored in the SQL buffer. The buffer has no command history list and does not record SQL*Plus commands.
R[UN]
---40 SAVE; 将SQL*Plus缓冲区的内容保存到所指定的文件中。如果用户没有指定文件扩展名,则默认 扩展名为SQL,后面的CREATE表示如果文件不存在创建一个文件。REPLACE表示如果文件不 存在则创建,否则替换覆盖文件中的内容。 APPEND把缓冲区的内容追加到文件末尾。 SAVE ---- Saves the contents of the SQL buffer in a script. In iSQL*Plus, click the Save Script button tosave the Workspace contents to a script. The buffer has no command history list and does not record SQL*Plus commands.
SPOOL ----- Stores query results in a file, or optionally sends the fileto a printer. In iSQL*Plus, use the Preferences screen to direct output to a file.
---45 SQLPLUS 运行SQL*Plus SQLPLUS ------- Starts SQL*Plus from the operating system prompt.
SQLPLUS [ [option][logon][start] ]
whereoption has the following syntax: -H[ELP] |-V[ERSION] |[[-C[OMPATIBILITY] x.y[.z]] [-L[OGON]] [-M[ARKUP] markup_option] [-R[ESTRICT] {1|2|3}] [-S[ILENT]]]
andwhere markup_option has the following syntax: HTML [ON|OFF][HEAD text][BODY text][TABLE text] [ENTMAP {ON|OFF}][SPOOL {ON|OFF}][PRE[FORMAT] {ON|OFF}]
andwhere logon has the following syntax: {username[/password][@connect_identifier]|/} [AS {SYSOPER|SYSDBA}]|/NOLOG
andwhere start has the following syntax: @{url|filename[.ext]} [arg ...]
---46 START 将filename文件的内容读入SQL*Plus缓冲区,然后执行缓冲区的脚本(运行脚本文件) START ----- Runs the SQL*Plus statements in the specified script. The script can be called from the local file system or a web server. Only the url form is supported in iSQL*Plus.
STA[RT] {url|file_name[.ext]} [arg ...]
where url supports HTTP and FTP protocols in the form:
http://host.domain/script.sql
---47 STARTUP 启动ORACLE实例。
STARTUP ------- Starts an Oracle instance with several options, including mounting, and opening a database.
STARTUP options | upgrade_options
where options has the following syntax: [FORCE][RESTRICT][PFILE=filename][QUIET][ MOUNT [dbname]| [ OPEN [open_options][dbname] ] | NOMOUNT ]
where open_options has the following syntax: READ {ONLY| WRITE [RECOVER]} | RECOVER
andwhere upgrade_options has the following syntax: [PFILE=filename] {UPGRADE | DOWNGRADE} [QUIET]
--- 48 STORE STORE ----- Saves attributes of the current SQL*Plus environment in a script.
STORE {SET} file_name[.ext][CRE[ATE]| REP[LACE]| APP[END]]
Not available in iSQL*Plus
--- 49 TIMING TIMING ------ Records timing data for an elapsed time period, lists the current timer''s name and timing data, or lists the numberof active timers.
TIMI[NG][START text|SHOW|STOP]
---50 TTITLE; 设置页眉选项。 TTITLE ------ Places and formats a title at the topof each report page. Enter TTITLE with no clause to list its current definition.
The old form of TTITLE is used ifonly a single word or a string in quotes follows the TTITLE command.
TTI[TLE][printspec [text|variable] ...] |[OFF|ON]
where printspec represents one or more of the following clauses:
COL n LE[FT] BOLD S[KIP][n] CE[NTER] FORMAT text TAB n R[IGHT]
例子: TTITLE ON 开启页眉 TTITLE OFF 关闭页眉
SQL> TTITLE CENTER '职工信息表' SQL>SELECT*FROM SCOTT.EMP;
---51 UNDEFINE; 删除一个或多个你定义的替换变量。 UNDEFINE -------- Deletes one or more substitution variables that you defined either explicitly (with the DEFINE command), or implicitly (with a START command argument).
UNDEF[INE] variable ...
---52 VARIABLE; VARIABLE -------- Declares a bind variable that can be referenced in PL/SQL, or lists the current display characteristics for a single variable orall variables.
---53 SQL> WHENEVER OSERROR WHENEVER OSERROR ---------------- Performs the specified action (exits SQL*Plus bydefault) if an operating system error occurs (such as a file writing error). In iSQL*Plus, performs the specified action (stops the current script bydefault) andreturns focus to the Workspace if an operating system error occurs.
---54 WHENEVER SQLERROR ----------------- Performs the specified action (exits SQL*Plus bydefault) if a SQL command or PL/SQL block generates an error. In iSQL*Plus, performs the specified action (stops the current script bydefault) andreturns focus to the Workspace if a SQL command or PL/SQL block generates an error.
启动oracle9i数据库命令:
$ sqlplus /nolog
SQL*Plus: Release 9.2.0.1.0 - Production on Fri Oct 31 13:53:53 2003
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
SQL> connect / as sysdba
Connected to an idle instance.
SQL> startup^C
SQL>select * from dictionary where instr(comments,'index')>0;
如果我们想知道user_indexes表各字段名称的详细含义,可以用下面这条SQL语句:
SQL>select column_name,comments from dict_columns where
table_name='USER_INDEXES';
依此类推,就可以轻松知道数据字典的详细名称和解释,不用查看ORACLE的其它文档资料了。
下面按类别列出一些ORACLE用户常用数据字典的查询使用方法。
1、用户
查看当前用户的缺省表空间
SQL>select username,default_tablespace from user_users;
查看当前用户的角色
SQL>select * from user_role_privs;
查看当前用户的系统权限和表级权限
SQL>select * from user_sys_privs;
SQL>select * from user_tab_privs;
2、表
查看用户下所有的表
SQL>select * from user_tables;
查看名称包含log字符的表
SQL>select object_name,object_id from user_objects
where instr(object_name,'LOG')>0;
查看某表的创建时间
SQL>select object_name,created from user_objects where
object_name=upper('&table_name');
查看某表的大小
SQL>select sum(bytes)/(1024*1024) as "size(M)" from
user_segments where segment_name=upper('&table_name');
查看放在ORACLE的内存区里的表
SQL>select table_name,cache from user_tables where
instr(cache,'Y')>0;
3、索引
查看索引个数和类别
SQL>select index_name,index_type,table_name from
user_indexes order by table_name;
查看索引被索引的字段
SQL>select * from user_ind_columns where
index_name=upper('&index_name');
查看索引的大小
SQL>select sum(bytes)/(1024*1024) as "size(M)" from
user_segments
where segment_name=upper('&index_name');
4、序列号
查看序列号,last_number是当前值
SQL>select * from user_sequences;
5、视图
查看视图的名称
SQL>select view_name from user_views;
查看创建视图的select语句
SQL>set view_name,text_length from user_views;
SQL>set long 2000;
说明:可以根据视图的text_length值设定set long 的大小
SQL>select text from user_views where
view_name=upper('&view_name');
6、同义词
查看同义词的名称
SQL>select * from user_synonyms;
7、约束条件
查看某表的约束条件
SQL>select constraint_name,
constraint_type,search_condition, r_constraint_name
from user_constraints where table_name =
upper('&table_name');
SQL>select c.constraint_name,c.constraint_type,cc.column_name
from user_constraints c,user_cons_columns cc
play.bitsCN.com累了吗玩一下吧
where c.owner = upper('&table_owner') and c.table_name =
upper('&table_name')
and c.owner = cc.owner and c.constraint_name =
cc.constraint_name
order by cc.position;
8、存储函数和过程
查看函数和过程的状态
SQL>select object_name,status from user_objects where
object_type='FUNCTION';
SQL>select object_name,status from user_objects where
object_type='PROCEDURE';
查看函数和过程的源代码
SQL>select text from all_source where owner=user and
name=upper('&plsql_name');
三、查看数据库的SQL
1、查看表空间的名称及大小
select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size
from dba_tablespaces t, dba_data_files d
where t.tablespace_name = d.tablespace_name
group by t.tablespace_name;
2、查看表空间物理文件的名称及大小
select tablespace_name, file_id, file_name,
round(bytes/(1024*1024),0) total_space
from dba_data_files
order by tablespace_name;
3、查看回滚段名称及大小
select segment_name, tablespace_name, r.status,
(initial_extent/1024) InitialExtent,(next_extent/1024)
NextExtent,
max_extents, v.curext CurExtent
From dba_rollback_segs r, v$rollstat v
Where r.segment_id = v.usn(+)
order by segment_name ;
4、查看控制文件
select name from v$controlfile;
5、查看日志文件
select member from v$logfile;
6、查看表空间的使用情况
select sum(bytes)/(1024*1024) as free_space,tablespace_name
from dba_free_space
group by tablespace_name;
SELECT A.TABLESPACE_NAME,A.BYTES TOTAL,B.BYTES USED, C.BYTES
FREE,
(B.BYTES*100)/A.BYTES "% USED",(C.BYTES*100)/A.BYTES "% FREE"
FROM SYS.SM$TS_AVAIL A,SYS.SM$TS_USED B,SYS.SM$TS_FREE C
WHERE A.TABLESPACE_NAME=B.TABLESPACE_NAME AND
A.TABLESPACE_NAME=C.TABLESPACE_NAME;
7、查看数据库库对象
select owner, object_type, status, count(*) count# from
all_objects group by owner, object_type, status;
8、查看数据库的版本
Select version FROM Product_component_version
Where SUBSTR(PRODUCT,1,6)='Oracle';
9、查看数据库的创建日期和归档方式
Select Created, Log_Mode, Log_Mode From V$Database;
四、ORACLE用户连接的管理
用系统管理员,查看当前数据库有几个用户连接:
SQL> select username,sid,serial# from v$session;
如果要停某个连接用
SQL> alter system kill session 'sid,serial#';
如果这命令不行,找它UNIX的进程数
SQL> select pro.spid from v$session ses,v$process pro where
ses.sid=21 and ses.paddr=pro.addr;
4.数据库链接 (DATABASE LINK)
CREATE DATABASE LINK数据库链接名CONNECT TO 用户名 IDENTIFIED BY 密码 USING
‘数据库连接字符串’;
数据库连接字符串可以用NET8 EASY CONFIG或者直接修改TNSNAMES.ORA里定义.
数据库参数global_name=true时要求数据库链接名称跟远端数据库名称一样
数据库全局名称可以用以下命令查出
SELECT * FROM GLOBAL_NAME;
查询远端数据库里的表
SELECT …… FROM 表名@数据库链接名; http://www.bitscn.net/网管博客等你来搏
五.权限管理 (DCL) 语句
1.GRANT 赋于权限
常用的系统权限集合有以下三个:
CONNECT(基本的连接), RESOURCE(程序开发), DBA(数据库管理)
常用的数据对象权限有以下五个:
ALL ON 数据对象名, SELECT ON 数据对象名, UPDATE ON
数据对象名,
DELETE ON 数据对象名, INSERT ON 数据对象名, ALTER ON 数据对象名
GRANT CONNECT, RESOURCE TO 用户名;
GRANT SELECT ON 表名 TO 用户名;
GRANT SELECT, INSERT, DELETE ON表名 TO 用户名1, 用户名2;
2.REVOKE 回收权限
REVOKE CONNECT, RESOURCE FROM 用户名;
REVOKE SELECT ON 表名 FROM 用户名;
REVOKE SELECT, INSERT, DELETE ON表名 FROM 用户名1, 用户名2;
查询数据库中第63号错误:
select orgaddr,destaddr from sm_histable0116 where error_code='63';
查询数据库中开户用户最大提交和最大下发数: select MSISDN,TCOS,OCOS from ms_usertable;
查询数据库中各种错误代码的总和:
bitsCN_com
select error_code,count(*) from sm_histable0513 group by error_code order by error_code;
查询报表数据库中话单统计种类查询。
select sum(Successcount) from tbl_MiddleMt0411 where ServiceType2=111
select sum(successcount),servicetype from tbl_middlemt0411 group by servicetype
alter table table_name modify (field_name varchar2(100));
改大行,改小不行(除非都是空的)
93. 如何查询某天的数据?
select * from a where trunc(日期字段)=to_date('2003-05-02','yyyy-mm-dd'); 若是date型数据 insert into bsyear values(to_date('20130427','yyyymmdd')); 或者是insert into bsyear values('27-4月-2013'); 94. sql 语句如何插入全年日期?
create table BSYEAR (d date);
insert into BSYEAR select to_date('20030101','yyyymmdd')+rownum-1 from all_objects where rownum <= to_char(to_date('20031231','yyyymmdd'),'ddd'); --在表后直接插入365行数据日期。 紧急插入几条重要的: 如何在Oracle中复制表结构和表数据 1. 复制表结构及其数据: create table table_name_new as select * from table_name_old 2. 只复制表结构: create table table_name_new as select * from table_name_old where 1=2; 或者: create table table_name_new like table_name_old 3. 只复制表数据: 如果两个表结构一样: insert into table_name_new select * from table_name_old 如果两个表结构不一样: insert into table_name_new(column1,column2...) select column1,column2... from table_name_old 创建带主键的表: create table stuInfo(stuID int primary key,stuName varchar2(20),age int); 或是不直接增加主键 alter table stuInfo add constraint stuInfo _PK primary key (stuID) 95. 如果修改表名?
alter table old_table_name rename to new_table_name;
97. 如何知道用户拥有的权限?
SELECT * FROM dba_sys_privs ; --一个权限对应一条数据,这样对于同一个用户就有多条数据了。
SELECT * FROM empLOYEE WHERE ROWNUM < n ORDER BY empno; Select * from a where rownum
104. 如何统计两个表的记录总数?
select (select count(id) from aa)+(select count(id) from bb) 总数 from dual; --总数那是没有单引号的,双引号可以。
106. 如何在给现有的日期加上2年?(
select add_months(sysdate,24) from dual; -- 2015/4/27 9:28:52
110. tablespace 是否不能大于4G?
没有限制.
111. 返回大于等于N的最小整数值?
SELECT CEIL(N) FROM DUAL;
112. 返回小于等于N的最小整数值?
SELECT FLOOR(N) FROM DUAL;
113. 返回当前月的最后一天?
SELECT LAST_DAY(SYSDATE) FROM DUAL;
;
115. 如何找数据库表的主键字段的名称?
SQL>SELECT * FROM user_constraints WHERE CONSTRAINT_TYPE='P' and table_name='TABLE_NAME'; --我没有查出来。
116. 两个结果集互加的函数?
SQL>SELECT * FROM BSEMPMS_OLD INTERSECT SELECT * FROM BSEMPMS_NEW;
SQL>SELECT * FROM BSEMPMS_OLD UNION SELECT * FROM BSEMPMS_NEW;
SQL>SELECT * FROM BSEMPMS_OLD UNION ALL SELECT * FROM BSEMPMS_NEW;
117. 两个结果集互减的函数?
SQL>SELECT * FROM BSEMPMS_OLD MINUS SELECT * FROM BSEMPMS_NEW;
139. 如何查找重复记录?
SELECT * FROM TABLE_NAME WHERE ROWID!=(SELECT MAX(ROWID) FROM TABLE_NAMe WHERE TABLE_NAME.COL1=D.COL1 AND TABLE_NAME.COL2=D.COL2);
140. 如何删除重复记录?
DELETE FROM TABLE_NAME WHERE ROWID!=(SELECT MAX(ROWID) FROM TABLE_NAME D WHERE TABLE_NAME.COL1=D.COL1 AND TABLE_NAME.COL2=D.COL2);
162. 如何知道表在表空间中的存储情况?
select segment_name,sum(bytes),count(*) ext_quan from dba_extents where tablespace_name='&tablespace_name' and segment_type='TABLE' group by tablespace_name,segment_name; --把&tablespace_name改成相应的表空间名称。
/**
* 要执行的算法,返回结果v
*/
public interface Computable<A, V> {
public V comput(final A arg);
}
/**
* 用于缓存数据
*/
public class Memoizer<A, V> implements Computable<A,