121. 取時間點的日的寫法:
select to_char(sysdate,'dd') from dual;
122. 取時間點的時的寫法:
select to_char(sysdate,'hh24') from dual;
123. 取時間點的分的寫法:
select to_char(sysdate,'mi') from dual;
124. 取時間點的秒的寫法:
select to_char(sysdate,'ss') from dual;
125. 取時間點的日期的寫法:
select trunc(sysdate) from dual;
126. 取時間點的時間的寫法:
select to_char(sysdate,'hh24:mi:ss') from dual;
127. 日期,時間形態變為字元形態:
select to_char(sysdate) from dual;
128. 將字串轉換成日期或時間形態:
select to_date('2003/08/01') from dual;
129. 返回引數的星期幾的寫法:
select to_char(sysdate,'d') from dual;
130. 返回引數一年中的第幾天的寫法:
select to_char(sysdate,'ddd') from dual;
131. 返回午夜和引數中指定的時間值之間的秒數的寫法:
select to_char(sysdate,'sssss') from dual;
132. 返回引數中一年的第幾周的寫法:
select to_char(sysdate,'ww') from dual;
虛擬字段
133. currval 和 nextval
為表建立序列
create sequence empseq ... ;
select empseq.currval from dual ;
自動插入序列的數值
insert into emp
values (empseq.nextval, 'lewis', 'clerk',
7902, sysdate, 1200, null, 20) ;
134. rownum
按設定排序的行的序號
select * from emp where rownum < 10 ;
135. rowid
返回行的實體地址
select rowid, ename from emp where deptno = 20 ;
136. 將n秒轉換為時分秒格式?
set serverout on
declare
n number := 1000000;
ret varchar2(100);
begin
ret := trunc(n/3600) || '小時' || to_char(to_date(mod(n,3600),'sssss'),'fmmi"分 "ss"秒"') ;
dbms_output.put_line(ret);
end;
137. 如何查詢做比較大的排序的程序?
select b.tablespace, b.segfile#, b.segblk#, b.blocks, a.sid, a.serial#, a.username, a.osuser, a.status
from v$session a,v$sort_usage b
where a.saddr = b.session_addr
order by b.tablespace, b.segfile#, b.segblk#, b.blocks ;
138. 如何查詢做比較大的排序的程序的sql語句?
select /*+ ordered */ sql_text from v$sqltext a
where a.hash_value = (
select sql_hash_value from v$session b
where b.sid = &sid and b.serial# = &serial)
order by piece asc ;
139. 如何查詢重覆記錄?
select * from table_name
where rowid!=(select max(rowid) from table_name d
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);
Oracle入門必會(5)
81.內連線inner join?select a.from bsempms a,bsdptms b where a.dpt no b.dpt no 82.如何外連線?select a.from bsempms a,bsdptms b where a.dpt no b.dpt no select a...
Oracle入門必會(9)
162.如何知道表在表空間中的儲存情況?select segment name,sum bytes count ext quan from dba extents where tablespace name tablespace name and segment type table group b...
Oracle入門必會(12)
221.translate char1,char2,char3 將char1中的char2的部分用char3代替。select translate abcdefgh de mn from dual 222.upper char 將字串char全部為大寫。223.add months d,n 將n個月...