oracle常用的一些sql命令

//查看系统当前时间   HH24 24小时制  MI是正确的分钟

select to_char(sysdate,'yyyy-mm-dd HH24:MI:SS') from dual

//HH非24   mm不区分大小写 日期中MM系统认为是月份

select to_char(sysdate,'yyyy-mm-dd HH:MM:SS') from dual

//报告TIMESTAMP数据类型格式的系统日期。

select SYSTIMESTAMP from dual; 

//查询当前登录用户

select username from user_users

show user

//查看表结构(字段数据类型)

desc user_users

//查询当前用户所拥有的表

select table_name from  user_tables

//忘记密码登录

打开cmd窗口,输入 sqlplus / as sysdba 

//远程连接

gb/ruiyuan@192.168.0.210/orcl

//创建序列

create sequence 序列名

  start with 起始序列

  increment by 每次增加的值

序列名.nextval(下一个序列)

序列名.currval(当前序列)

//创建回话临时表数据

create global temporary table 表 as 另一张表数据 on commit preserve rows;(可以复制原表中数据,比较常用的就是这个。)

//添加字段注释(表注释)

comment on column tmp_xian.id is '主键'

comment on column tmp_xian.name is '最大用户名'

COMMENT ON TABLE TABLENAME IS '用户表'; 

//varchar2最大长度4000bite   char(2000bite)

//查看前500行数据

select * from T_PUB_DOWNLOAD_DETAIL where rownum<500

//count(*) 和count(1) 效率结果都一样   count(name)统计name列不为空的记录

select count(*) from table;   count(1)

  

//date 日期时间(精确到秒)   timestamp(精确到小数秒)

//union 表链接(筛选重复记录)   union all(简单的2个表结果合并)   union all效率高

//LTRIM(字串):将字串左边的空格移除。   RTRIM(字串): 将字串右边的空格移除。   TRIM(字串): 将字串开头和末尾的空格移除。   ALLTRIM(字串):将字串左右边两边的空格移除。

原文地址:https://www.cnblogs.com/plan123/p/4139829.html