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/[email protected]/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(字串):將字串左右邊兩邊的空格移除。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章