Oracle 比較方便且很實用的幾個SQL語句

2021-09-27 07:47:21 字數 2513 閱讀 8269

select

count(0

)as aanum

from user_tab_columns

where upper(column_name)

='pt_dietaryhabit'

and table_name =

'table'

select

count(*

)from user_tab_columns where table_name=upper(

'表名'

)

select table_name from dba_tab_columns where column_name=

'欄位名'

select

*from

(select a1.

*,rownum rn from

(select

*from student) a1 where rownum <=5)

where rn>=2;

select a1.

*from

(select student.

*,rownum rn from student where rownum <=

5) a1 where rn >=3;

select a1.

*from

(select student.

*,rownum rn from student) a1 where rn between

3and

5;

select to_char(sysdate,

'yyyy/mm/dd hh24:mi:ss'

)from dual;

insert

into table2(field1,field2,..

.)select value1,value2,..

.from table1

insert

into table2 select

*from table1

- 注意:

(1)要求目標表table2必須存在,並且欄位field,field2…也必須存在

(2)注意table2的主鍵約束,如果table2有主鍵而且不為空,則 field1, field2…中必須包括主鍵

(3)注意語法,不要加values,和插入一條資料的sql混了,不要寫成:insert into

table2(field1,field2,…) values (select value1,value2,… from table1) 由於目標表table2已經存在,所以我們除了插入源表table1的字段外,還可以插入常量。示例如下:+ expand sourceview plaincopy to clipboardprint

測試如下:

for

(int i =

0; i < chtpattemp.columns.count -

1; i++

)string sql =

@"insert into table1 select "

+ sselect +

" from table2 where field =:fieldtest"

;

insert

into table1

select(.

....省略其他字段)

field1,

field2,

field3,

field4

from table2

where ch.field=:fieldtest

//擷取rep_memo欄位中_符號中間的內容,例值為:1_r_263,則擷取的內容為r

substr(rep_memo,instr(rep_memo,

'_',1,

1)+1

,instr(rep_memo,

'_',1,

2)-1

-instr(rep_memo,

'_',1,

1))//擷取rep_memo欄位中最後乙個_符號之後的內容,例值為:1_r_263,則擷取的內容為263

substr(rep_memo,instr(rep_memo,

'_',2,

2)+1

,length(rep_memo)

-instr(rep_memo,

'_')

)

好啦!到這裡已經成功啦,快去試試吧!✌

更多部落格內容請檢視 ? 可可西里的部落格

程式設計中常用的一些函式概括,很實用也很方便

平時在各大oj做題的時候發現有的題用很巧妙的方法就可以了,但對於我這種什麼都不會的菜鳥簡直要命,只能用最笨最麻煩的方法來a題,這樣往往效率較低 所以一直尋思著整個總結歸納啥的,以後有需要就拿出來看看,比如我常用的乙個函式 unique去重函式,說實話,很好用,做題特別方便,有時在比賽中就能佔據很大的...

LINQ還是很方便的

很長時間沒有linq了,除了知道linq外,基本上都忘了。昨天快下班時,乙個專案要統計圖中的圖塊 blockreference 數量及位置資訊,開始還想自己寫排序及分組的 忽然想到可以使用linq,這使得 簡單了很多很多。使用linq排序 分組 var group from blk in blks ...

oracle 合併列的函式,比較實用

oracle wm concat column 函式使我們經常會使用到的,下面就教您如何使用oracle wm concat column 函式實現字段合併,如果您對oracle wm concat column 函式使用方面感興趣的話,不妨一看。shopping u id goods num 1 ...