部分重要SQL語句

2021-09-01 13:40:42 字數 1891 閱讀 7733

to_char(date, 'fmt')

用於將日期或時間戳轉換成varchar2型別字串,如果指定了格式字串,則用它控制結果的結果。

格式控制串由格式元素構成。

格式控制串必須用單引號括起來

select to_char(sysdate, 'dd-mon-yy hh24:mi:ss') "rigth now" from dual;

select ename, hiredate, to_char(hiredate,'yyyy/mm/dd') from emp

select sysdate, to_char(sysdate,'yyyy-mon-dd hh12:mi:ss') from dual;

to_char(num,format)

用於將number型別引數轉換為varchar2型別,如果指定了format,它會控制整個轉換。

select to_char(sal, 『$99,999.9999』) salary from emp where ename = 『allen』;

select to_char(sal, 『$00,000.0000』) salary from emp where ename = 『allen』;

select to_char(123456, '99,99,00') from dual;

to_date (string,format)

將char或varchar2型別的string轉換為date型別

select to_date('04,05,19,10,23,40','yy,mm,dd,hh12,mi,ss') from dual;

select to_date('2004-09-19','yyyy-mm-dd') from dual;

to_number(string,format)

將char或varchar2型別的string轉換為number型別

select to_number('$39343.783','$99990.000') from dual;

select to_number('11.231','999.999') from dual;

oracle和mysql中的分頁技術:

oracle分頁:

oracle下select語句每個結果集中都有乙個偽欄位存在,這個欄位的名字叫做rownum.用來標識每條記錄的行號,行號從1開始,每次遞增1

只能使用:<,<=

注意:oracle中的rownum的是在取資料的時候產生的序號 。當rownum和order by一起使用時,會首先選出符合rownum條件的記錄,然後再進行排序,這會給我們的查詢帶來難度。

select r,ename,sal from

(select rownum r,ename,sal

from (select * from emp order by sal desc)

) where r>5 and r <=10;

rowid和rownum都是虛列,但含義完全不同。rowid是實體地址,用於定位oracle中具體資料的物理儲存位置,而rownum則是sql的輸出結果排序。通俗的講:rowid是相對不變的,rownum會變化,尤其是使用order by的時候

mysql分頁:

limit:

select * from … where …. limit 4, 10

資料庫邏輯備份和遷移

c:\documents and settings\administrator>exp scott/tiger tables=(emp,dept) file=d:\data.dmp

c:\documents and settings\administrator>imp system/orcl fromuser=scott touser=system tables=(emp,dept) file=d:\data.dmp

sql語句部分彙總 1 1

alter table tmplisting add 列名 varchar max 新增一列select name from syscolumns where id object id 查詢資料表所有列名create procedure checkindata as begin declare ci...

自己覺得重要的sql語句

查詢表資料 select from tablename 修改表字段值 update tablename set column newval where columnid id 刪除比表中某一字段值 delete from tablename where columnid id 刪除 表資料和表結構 ...

Mysql的部分常用SQL語句

管理 查詢 1.查詢資料庫中,包含有資料記錄的表名 select table name from information schema.tables where table schema 資料庫名稱 and table rows 0 2.查詢當前日期時間前三天資料 select from 表名 wh...