Oracle小技巧

更改Oracle http端口(8080改为8081)
SQL> call dbms_xdb.cfg_update(updateXML(dbms_xdb.cfg_get(),
  2  '/xdbconfig/sysconfig/protocolconfig/httpconfig/http-port/text()',8081))
  3  /
SQL> commit;
Commit complete.
SQL>  exec dbms_xdb.cfg_refresh;

SQL>  call dbms_xdb.cfg_update(updateXML(dbms_xdb.cfg_get(),
  2  '/xdbconfig/sysconfig/protocolconfig/ftpconfig/ftp-port/text()',2111))
  3  /
Call completed.
SQL> commit;
Commit complete.
SQL>  exec dbms_xdb.cfg_refresh;



表自复制

INSERT INTO 表名 (列,...) SELECT * FROM 表名;
如:
INSERT INTO students (sid,sname,sage,...) SELECT * FROM students;


SET命令(常用): SET 系统变量 值

ARRAY[SIZE] {20d|n} SQL*PLUS一次从数据库获取的行数,有效值为1至5000.
LIN[ESIZE] {80d|n} SQL*PLUS一行显示的字符总数,它还控制对准中心的文本和右对齐文本.
PAGES[IZE] {14d|n} 从顶部标题至页结束之间的行数.
SQLN[UMBER] {OFF|ONd}   为SQL命令和PL/SQL块的第二行和后继行设置提示.
TIMI[NG] {OFFd|ON}  显示每一个运行的SQL命令或PL/SQL块的时间统计.

ORACLE保留关键字
ACCESS ADD ALL ALTER AND ANY AS ASC AUDIT BETWEEN BY CHAR CHECK CLUSTER COLUMN COMMENT
COMPRESS CONNECT CREATE CURRENT DATE DECIMAL DEFAULT DELETE DESC DISTINCT DROP ELSE EXCLUSIVE
EXISTS FILE FLOAT FOR FROM GRANT GROUP HAVING IDENTIFIED IMMEDIATE IN INCREMENT INDEX INITIAL
INSERT INTEGER INTERSECT INTO IS LEVEL LIKE LOCK LONG MAXEXTENTS MINUS MLSLABEL MODE MODIFY
NOAUDIT NOCOMPRESS NOT NOWAIT NULL NUMBER OF OFFLINE ON ONLINE OPTION OR ORDER PCTFREE PRIOR
PRIVILEGES PUBLIC RAW RENAME RESOURCE REVOKE ROW ROWID ROWNUM ROWS SELECT SESSION SET
SHARE SIZE SMALLINT START SUCCESSFUL SYNONYM SYSDATE TABLE THEN TO TRIGGER UID UNION UNIQUE
UPDATE USER VALIDATE VALUES VARCHAR VARCHAR2 VIEW WHENEVER WHERE WITH

TO_DATE与TO_CHAR
1.在使用Oracle的to_date函数来做日期转换时,很多Java程序员也许会和我一样,直觉的采用“yyyy-MM-dd HH:mm:ss”的格式作为格式进行转换,但是在Oracle中会引起错误:“ORA 01810 格式代码出现两次”。
如:select to_date('2005-01-01 13:14:20','yyyy-MM-dd HH24:mm:ss') from dual;
原因是SQL中不区分大小写,MM和mm被认为是相同的格式代码,所以Oracle的SQL采用了mi代替分钟。
select to_date('2005-01-01 13:14:20','yyyy-MM-dd HH24:mi:ss') from dual;
2.另要以24小时的形式显示出来要用HH24
select to_char(sysdate,'yyyy-MM-dd HH24:mi:ss') from dual;//mi是分钟
select to_char(sysdate,'yyyy-MM-dd HH24:mm:ss') from dual;//mm会显示月份

     
JDBC连接Oracle
1.本机连接:控制面板-管理工具-数据源 (ODBC)添加相应的Oracle的DNS服务(DNSname);
  加载驱动:Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  建立连接:DriverManager.getConnection("jdbc:odbc:DNSname","username","password");
2.URL连接:
  加载驱动:Class.forName("oracle.jdbc.driver.OracleDriver");
         (此驱动一般在Oracle安装目录内相应server\jdbc\lib目录下能找到);
  建立连接:DriverManager.getConnection("jdbc:oracle:thin:@url:port:OSname","username","password");

你可能感兴趣的:(Oracle小技巧)