TShopping

 找回密碼
 註冊
搜索
查看: 705|回復: 2

[分享] DBA SQL

[複製鏈接]
發表於 2013-10-25 18:50:16 | 顯示全部樓層 |閱讀模式
 
Push to Facebook Push to Plurk Push to Twitter 
1.增加主鍵
alter table TABLE_NAME add constraint KEY_NAME primary key (TABLE_COLUMN);
指定表空間
alter table TABLE_NAME add constraint KEY_NAME primary key (TABLE_COLUMN) using index tablespace TABLE_SPACE_NAME;
2.
增加外鍵
alter table TABLE_NAME add constraint FK_NAME foreign key (TABLE_COLUMN) references KEY_TABLE_NAME;
3.
使主鍵或外鍵失效、生效
alter table TABLE_NAME disable(enable) constraint KEY_NAME;
4
、查看各種約束
select constraint_name,table_name,constraint_type,status from user_constraints;
select constraint_name, constraint_type,search_condition, r_constraint_name from user_constraints where table_name = upper('&table_name')

select c.constraint_name,c.constraint_type,cc.column_name
from user_constraints c,user_cons_columns cc
where c.owner = upper('&table_owner') and c.table_name = upper('&table_name')
and c.owner = cc.owner and c.constraint_name = cc.constraint_name
order by cc.position;

5
、刪除主鍵或外鍵
alter table TABLE_NAME drop constraint KEY_NAME;
6
、建外鍵
單字段時:create table 表名 (col1 char(8),
cno char(4) REFERENCE course);
多個欄位時,在最後加上 Foreign Key (欄位名) REFERENCE 表名(欄位)
連帶刪除選項 (on delete cascade
當指定時,如果父表中的記錄被刪除,則依賴于父表的記錄也被刪除
REFERENCE
表名() on delete cascade;
7
、刪除帶約束的表
Drop table
表名 cascade constraints;

8
:索引管理
<1>.creating function-based indexes
sql> create index summit.item_quantity on summit.item(quantity-quantity_shipped);

<2>.create a B-tree index
sql> create [unique] index index_name on table_name(column,.. asc/desc) tablespace
sql> tablespace_name [pctfree integer] [initrans integer] [maxtrans integer]
sql> [logging | nologging] [nosort] storage(initial 200k next 200k pctincrease 0
sql> maxextents 50);

<3>.pctfree(index)=(maximum number of rows-initial number of rows)*100/maximum number of rows

<4>.creating reverse key indexes
sql> create unique index xay_id on xay(a) reverse pctfree 30 storage(initial 200k
sql> next 200k pctincrease 0 maxextents 50) tablespace indx;

<5>.create bitmap index
sql> create bitmap index xay_id on xay(a) pctfree 30 storage( initial 200k next 200k
sql> pctincrease 0 maxextents 50) tablespace indx;

<6>.change storage parameter of index
sql> alter index xay_id storage (next 400k maxextents 100);

7.allocating index space
sql> alter index xay_id allocate extent(size 200k datafile 'c:/oracle/index.dbf');

<8>.alter index xay_id deallocate unused;

<9>
、查看索引
SQL>select index_name,index_type,table_name from user_indexes order by table_name;
<10>
、查看索引被索引的欄位
SQL>select * from user_ind_columns where index_name=upper('&index_name');

11
、創建序列
select * from user_sequences;
create sequence SEQ_NAME start with 1000
maxvalue 1000 increment by 1;
alter sequence SEQ_NAME minvalue 50 maxvalue 100;
12
、刪除重複行
update a set aa=null where aa is not null;

delete from a where rowid!=
(select max(rowid) from a b where a.aa=b.aa);
13
、刪除同其他表相同的行
delete from a where exits
(select 'X' from b where b.no=a.no);

delete from a where no in (select no from b);
14
、查詢從多少行到多少行的記錄(可以用在web開發中的分頁顯示)

select * from ( select rownum row_id,b.* from (select a.* from sys_oper a) b )
where row_id between 15 and 20

15
、對公共授予訪問權
grant select on
表名 to public;
create public synonym
同義詞名 for 表名;
16
、填加注釋
comment on table
表名 is '注釋';
comment on column
表名.列名 is '注釋';
17
、分散式資料庫,創建資料庫鏈路
create [public] database link LINKNAME
[connect to USERNAME identified by PASSWORD]
[using 'CONNECT_STRING']
可以在伺服器端,也可以在用戶端建立,但必須注意,兩台伺服器之間
資料庫必須可以互訪,必須各有各自的別名資料庫
18
、查看資料庫鏈路
select * from all_db_links;
select * from user_db_links;
查詢 select * from TABLENAME@DBLNKNAME;
創建遠端資料庫同義詞
create synonym for TABLENAME@DBLNKNAME;
操縱遠端資料庫記錄
insert into TABLENAME@DBLNKNAME (a,b) values (va,vb);
update TABLENAME@DBLNKNAME set a='this';
delete from TABLENAME@DBLNKNAME;
怎樣執行遠端的內嵌過程
begin
otherdbpro@to_html(
參數);
end;

19
、資料庫鏈路用戶密碼有特殊字元的時候,可以用雙引號把密碼引起來
create public database link dblink1 connect to db1 identified by "123*456" using 'db11'

20.oracle8
中擴充了group by rollupcube的操作。有時候省了你好多功夫的。
<1>
下面的語句可以進行總計
select region_code,count(*) from aicbs.acc_woff_notify
group by rollup(region_code);
<2>
對第1個欄位小計,最後合計
select region_code,write_status,count(*) from aicbs.acc_woff_notify
group by rollup(region_code,write_status);
----------------------
570 0 3
570 1 2
570 5 --
此處小計了570的記錄
571 0 10
571 1 2
571 12 --
此處小計了571的記錄
.....
100 --
此處有總計
<3>
複合rollup運算式,只做總計
select region_code,write_status,count(*) from aicbs.acc_woff_notify
group by rollup(region_code,write_status);

<4>
對第1個欄位小計,再對第2個欄位小計,最後合計
select region_code,write_status,count(*) from aicbs.acc_woff_notify
group by cube(region_code,write_status);
----------------------
100 --
此處有總計
0 60 --
write_status0的小計
1 39 --
write_status1的小計
3 1 --
write_status3的小計
570 5 --
此處小計了570的記錄
570 0 3
570 1 2
571 12 --
此處小計了571的記錄
571 0 10
571 1 2
....
<3>
複合cube運算式,只做總計
select region_code,write_status,count(*) from aicbs.acc_woff_notify
group by cube(region_code,write_status);


<4>
下面的語句可以按照rollup不同的欄位進行小計
select region_code,write_status,count(*) from aicbs.acc_woff_notify
group by region_code,rollup(write_status);
21.
查詢view的創建語句
sql>set long 1000
sql>select * from user_views where view_name='MY_VIEW_NAME';
or
sql>select * from all_views where view_name='MY_VIEW_NAME';

22
、去除資料庫中特殊字元
<1>.
字串欄位中含有"'",如果用來組合sql語句,會造成語句不準確。
比如:replace(f1,'''','')
<2>.
字串欄位中含有"\t \n",如果用來在c或者c++程式中輸出到檔,格式無法保證。
比如:replace(f2,'\t','')
<3>.
清除換行和回車
比如: replace(f2,chr(13)||chr(10),'')
23
、如何在字串里加回車或者tab
sqlplus中執行
sql>select 'UserId=1233111'||chr(10)||'AccId=13431'||chr(9)||'AccId2=11111' from dual;

24
、樹形查詢
create table zj(
bm number(8),
bmmc varchar2(20),
sjbm number(8)
)

insert into zj values(1,'aaa',0)
insert into zj values(11,'aaa1',1)
insert into zj values(12,'aaa2',1)
insert into zj values(111,'aaa11',11)
insert into zj values(112,'aaa12',11)
insert into zj values(113,'aaa13',11)
insert into zj values(121,'aaa21',12)
insert into zj values(122,'aaa22',12)
insert into zj values(123,'aaa23',12)
--
select bm,bmmc,sjbm,level
from zj
start with sjbm=0
connect by prior bm = sjbm
或者

select bm,bmmc,sjbm,level
from zj
start with sjbm=0
connect by sjbm = prior bm

25
、快照
create snapshot SNAPSHOT_NAME
[storage (storage parameter)]
[tablespace TABLESPACE_NAME]
[refresh [fast\complete\force]
[start with START_DATE next NEXT_DATE]
as QUERY;

create snapshot snapshot_to_study as select * from TABLE_NAME@to_study;
創建角色
create role aa identified by aaa;
授權 grant create snapshot,alter snapshot to aaa;
grant aaa to emp;
create snapshot SNAPSHOT_TO_HTML refresh complete start with sysdate next
sysdate+5/(24*60*60) as select * from a@to_html;
刪除 drop snapshot snap_to_html
手工刷新快照,(調用DBMS_SNAPSHOT包中的refresh過程)DBMS_SNAPSHOT.refresh(snapshot_name,refresh_type);
begin
DBMS_SNAPSHOT.REFRESH('snap_to_html','c');
end;
對所有快照進行刷新
begin
DBMS_SNAPSHOT.REFRESH_ALL;
end;
怎樣執行遠端的內嵌過程
begin
otherdbpro@to_html(
參數);
end;
26
、用戶管理
create a user: database authentication
sql> create user juncky identified by oracle default tablespace users
sql> temporary tablespace temp quota 10m on data password expire
sql> [account lock|unlock] [profile profilename|default];

<1>.
查看當前用戶的缺省表空間
SQL>select username,default_tablespace from user_users;
<2>
生成用戶時指定缺省表空間
create user
用戶名 identified by 口令 default tablespace 表空間名;

<3>
重新指定用戶的缺省表空間
alter user
用戶名 default tablespace 表空間名
<4>
查看當前用戶的角色
SQL>select * from user_role_privs;
<5>
查看當前用戶的系統許可權和表級許可權
SQL>select * from user_sys_privs;
SQL>select * from user_tab_privs;
<6>
查看用戶下所有的表
SQL>select * from user_tables;
<7> alter user
語句的quota子句限制用戶的磁碟空間
:alter user jf quota 10M on system;

27
、查看放在ORACLE的記憶體區裏的表
SQL>select table_name,cache from user_tables where instr(cache,'Y')>0;

28
、約束條件
create table employee
(empno number(10) primary key,
name varchar2(40) not null,
deptno number(2) default 10,
salary number(7,2) check salary<10000,
birth_date date,
soc_see_num char(9) unique,
foreign key(deptno) references dept.deptno)
tablespace users;

關鍵字(primary key)必須是非空,表中記錄的唯一性
not null
非空約束
default
缺省值約束
check
檢查約束,使列的值符合一定的標準範圍
unqiue
唯一性約束
foreign key
外部鍵約束

29
、查看創建視圖的select語句
SQL>set view_name,text_length from user_views;
SQL>set long 2000;
說明:可以根據視圖的text_length值設定set long 的大小
SQL>select text from user_views where view_name=upper('&view_name');

30
、查看同義詞的名稱
SQL>select * from user_synonyms;

31
、用Sql語句實現查找一列中第N大值
select * from
(select t.*,dense_rank() over (order by sal) rank from employee)
where rank = N;

32
虛擬自段
<1>. CURRVAL
nextval
為表創建序列
CREATE SEQUENCE EMPSEQ ... ;
SELECT empseq.currval FROM DUAL ;
自動插入序列的數值
INSERT INTO emp
VALUES (empseq.nextval, 'LEWIS', 'CLERK',
7902, SYSDATE, 1200, NULL, 20) ;

<2>. ROWNUM
按設定排序的行的序號
SELECT * FROM emp WHERE ROWNUM < 10 ;

<3>. ROWID
返回行的物理位址
SELECT ROWID, ename FROM emp WHERE deptno = 20 ;

33
、對CLOB欄位進行全文檢索
SELECT * FROM A WHERE dbms_lob.instr(a.a,'K',1,1)>0;

34.
特殊字元的插入,比如"&"
insert into a values (translate ('at{&}t','at{}','at'));

35.
表管理
<1>.create a table
sql> create table table_name (column datatype,column datatype]....)
sql> tablespace tablespace_name [pctfree integer] [pctused integer]
sql> [initrans integer] [maxtrans integer]
sql> storage(initial 200k next 200k pctincrease 0 maxextents 50)
sql> [logging|nologging] [cache|nocache]

<2>.copy an existing table
sql> create table table_name [logging|nologging] as subquery

<3> create table ... as
方式建表的時候,指定表參數
create table a
storage(
initial 1M /*
第一次創建時分配空間*/
next 1M /*
第一次分配的存儲空間用完時在分配*/
)
as select * from b;
<4>.
創建臨時表
sql> create global temporary table xay_temp as select * from xay;
on commit preserve rows/on commit delete rows
Oracle中,可以創建以下兩種臨時表:
a
會話特有的臨時表:
create global temporary table () on commit preserve rows;
會話指定,當中斷會話時ORACLE將截斷表

b
事務特有的臨時表:
create global temporary table () on commit delete rows;
事務指定,每次提交後ORACLE將截斷表(刪除全部行)
c
說明
臨時表只在當前連接內有效
  臨時表不建立索引,所以如果資料量比較大或進行多次查詢時,不推薦使用
  資料處理比較複雜的時候時表快,反之視圖快點
  在僅僅查詢資料的時候建議用游標: open cursor for 'sql clause';
<5>
pctfree = (average row size - initial row size) *100 /average row size
pctused = 100-pctfree- (average row size*100/available data space)
<6>.change storage and block utilization parameter
sql> alter table table_name pctfree=30 pctused=50 storage(next 500k
sql> minextents 2 maxextents 100);
<7>.manually allocating extents
sql> alter table table_name allocate extent(size 500k datafile 'c:/oracle/data.dbf');
<8>.move tablespace
sql> alter table employee move tablespace users;
<9>.deallocate of unused space
sql> alter table table_name deallocate unused [keep integer]
<10>.drop a column
sql> alter table table_name drop column comments cascade constraints checkpoint 1000;
alter table table_name drop columns continue;
<11>.mark a column as unused
sql> alter table table_name set unused column comments cascade constraints;
alter table table_name drop unused columns checkpoint 1000;
alter table orders drop columns continue checkpoint 1000
data_dictionary : dba_unused_col_tabs

37.
中文是如何排序的?

Oracle9i
之前,中文是按照二進位編碼進行排序的。
oracle9i中新增了按照拼音、部首、筆劃排序功能。設置NLS_SORT
SCHINESE_RADICAL_M
按照部首(第一順序)、筆劃(第二順序)排序
SCHINESE_STROKE_M
按照筆劃(第一順序)、部首(第二順序)排序
SCHINESE_PINYIN_M
按照拼音排序

38.
資料表中的欄位最大數:
表或視圖中的最大列數為 1000

39. oracle
中的裸設備:
裸設備就是繞過檔系統直接訪問的儲存空間

40.
Oracle伺服器上通過SQLPLUS查看本機IP地址 ?
select sys_context('userenv','ip_address') from dual;
如果是登陸本機資料庫,只能返回127.0.0.1

41.
ORACLE中取毫秒?
9i
之前不支持,9i開始有timestamp.
9i
可以用select systimestamp from dual;

42.
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;

43
、在某個用戶下找所有的索引
select user_indexes.table_name, user_indexes.index_name,uniqueness, column_name
from user_ind_columns, user_indexes
where user_ind_columns.index_name = user_indexes.index_name
and user_ind_columns.table_name = user_indexes.table_name
order by user_indexes.table_type, user_indexes.table_name,
user_indexes.index_name, column_position;

44. not in
的替代。
一般not in的效率比較低。特別是資料量大的時候,幾乎不能執行。
用下面幾種方式可以替換寫法
比如要查詢在fee_rev_info表中已經銷戶的用戶(不在cm_user中的)(不過下面的例子不是很好,因為bill_idcm_user的唯一索引)
select * from fee_rev_info where bill_id not in (select bill_id from cm_user)
<1>
not exists
select * from fee_rev_info a where not exists (select 'p' from cm_user b where b.bill_id = a.bill_id)
<2>
用外連接(+)
select a.* from fee_rev_info a,cm_user b
where a.bill_id = b.bill_id (+)
and b.bill_id is null
<3>
hash_aj
select /*+HASH_AJ*/* from fee_rev_info where bill_id not in (select bill_id from cm_user)

45.
怎麼樣查詢特殊字元,如通配符%_
假如資料庫中有表 STATIONTYPE,STATION_571 STATION_572 ...
select * from tab where tname like 'STATION_%'
會顯示 STATIONTYPE,STATION_571 ... 可以用下面的語句
select * from tab where tname like 'STATION\_%' escape'\'

46.
如果存在就更新,不存在就插入可以用一個語句實現嗎
9i
已經支持了,是Merge,但是只支持select子查詢,
如果是單條資料記錄,可以寫作select .... from dual的子查詢。
語法為:
MERGE INTO table
USING data_source
ON (condition)
WHEN MATCHED THEN update_clause
WHEN NOT MATCHED THEN insert_clause;


MERGE INTO cm_user_credit
USING (select * from dual) ON (user_id =1302514690 )
when MATCHED then update set credit_value = 1000
when NOT MATCHED then insert (user_id,acc_id,bill_id,plan_id,region_code,credit_value) values(1302514690,1305032158,'13857141218',10070247,'571',1000);

47.
怎麼實現一條記錄根據條件多表插入
9i
以上可以通過Insert all語句完成,僅僅是一個語句,如:
INSERT ALL
WHEN (id=1) THEN
INTO table_1 (id, name)
values(id,name)
WHEN (id=2) THEN
INTO table_2 (id, name)
values(id,name)
ELSE
INTO table_other (id, name)
values(id, name)
SELECT id,name
FROM a;

如果沒有條件的話,則完成每個表的插入,如
INSERT ALL
INTO table_1 (id, name)
values(id,name)
INTO table_2 (id, name)
values(id,name)
INTO table_other (id, name)
values(id, name)
SELECT id,name
FROM a;

48.
如何實現行列轉換
<1>
、固定列數的行列轉換

student subject grade
---------------------------
student1
語文 80
student1
數學 70
student1
英語 60
student2
語文 90
student2
數學 80
student2
英語 100
...
轉換為
語文 數學 英語
student1 80 70 60
student2 90 80 100
...
語句如下:
select student,sum(decode(subject,'
語文', grade,null)) "語文",
sum(decode(subject,'
數學', grade,null)) "數學",
sum(decode(subject,'
英語', grade,null)) "英語"
from table
group by student

<2>
、不定列行列轉換

c1 c2
--------------
1

1

1

2

2

3

...
轉換為
1
我是誰
2
知道
3


這一類型的轉換必須借助於PL/SQL來完成,這裏給一個例子
CREATE OR REPLACE FUNCTION get_c2(tmp_c1 NUMBER)
RETURN VARCHAR2
IS
Col_c2 VARCHAR2(4000);
BEGIN
FOR cur IN (SELECT c2 FROM t WHERE c1=tmp_c1) LOOP
Col_c2 := Col_c2||cur.c2;
END LOOP;
Col_c2 := rtrim(Col_c2,1);
RETURN Col_c2;
END;
/
SQL> select distinct c1 ,get_c2(c1) cc2 from table;
即可

--
例子:
create table okcai_1
(
user_id varchar2(10),
user_number varchar2(10),
user_num number(8)
)
user_id user_number user_num
---------------------
1 123 2
1 456 5
1 789 6
2 11 2
2 22 3
2 33 4
2 44 5
2 55 6
2 66 7
2 77 8
3 1234 1
3 5678 2

方式一:
create or replace function get_col(
p_userId number,
p_col number
) return varchar
as
v_tmp varchar2(255);
begin
select user_number||chr(9)||user_num into v_tmp
from
(select user_number,user_num,rownum row_id
from okcai_1
where user_id = p_userId) a
where row_id = p_col;
return ltrim(v_tmp);
--return v_tmp;
end;

然後
select distinct user_id,get_col(user_id,1),get_col(user_id,2),get_col(user_id,3) .... from okcai_1

方式二:
create or replace function get_col(
p_userId number,
p_col number
) return varchar
as
v_tmp varchar2(255);
begin
select user_number||chr(9)||user_num into v_tmp
from
(select user_number,user_num,rownum row_id
from okcai_1
where user_id = p_userId) a
where row_id = p_col;
return ltrim(v_tmp);
--return v_tmp;
end;
select distinct user_id,get_col_new(user_id) from okcai_1;

49.
怎麼設置存儲過程的調用者許可權
普通存儲過程都是所有者許可權,如果想設置調用者許可權,請參考如下語句
create or replace
procedure ...()
AUTHID CURRENT_USER
As
begin
...
end;

50.Oracle
有哪些常見關鍵字
詳細資訊可以查看v$reserved_words視圖

51.
怎麼查看資料庫參數
<1> show parameter
參數名
如通過show parameter spfile可以查看9i是否使用spfile
其中參數名是可以匹配的。
比如show parameter cursor ,則會顯示跟cursor相關的參數
<2>
select * from v$parameter
<3>

除了這部分參數,Oracle還有大量隱含參數,可以通過如下語句查看:
SELECT NAME
,VALUE
,decode(isdefault, 'TRUE','Y','N') as "Default"
,decode(ISEM,'TRUE','Y','N') as SesMod
,decode(ISYM,'IMMEDIATE', 'I',
'DEFERRED', 'D',
'FALSE', 'N') as SysMod
,decode(IMOD,'MODIFIED','U',
'SYS_MODIFIED','S','N') as Modified
,decode(IADJ,'TRUE','Y','N') as Adjusted
,description
FROM ( --GV$SYSTEM_PARAMETER
SELECT x.inst_id as instance
,x.indx+1
,ksppinm as NAME
,ksppity
,ksppstvl as VALUE
,ksppstdf as isdefault
,decode(bitand(ksppiflg/256,1),1,'TRUE','FALSE') as ISEM
,decode(bitand(ksppiflg/65536,3),
1,'IMMEDIATE',2,'DEFERRED','FALSE') as ISYM
,decode(bitand(ksppstvf,7),1,'MODIFIED','FALSE') as IMOD
,decode(bitand(ksppstvf,2),2,'TRUE','FALSE') as IADJ
,ksppdesc as DESCRIPTION
FROM x$ksppi x
,x$ksppsv y
WHERE x.indx = y.indx
AND substr(ksppinm,1,1) = '_'
AND x.inst_id = USERENV('Instance')
)
ORDER BY NAME

52.
怎樣建立基於函數索引
8i
以上版本,確保
Query_rewrite_enabled=true
Query_rewrite_integrity=trusted
Compatible=8.1.0
以上
Create index indexname on table (function(field));

53.
怎麼樣移動表或表分區
[A]
移動表的語法
Alter table tablename move
[Tablespace new_name
Storage(initial 50M next 50M
pctincrease 0 pctfree 10 pctused 50 initrans 2) nologging]
移動分區的語法
alter table tablename move (partition partname)
[update global indexes]
之後之後必須重建索引
Alter index indexname rebuild
如果表有Lob段,那麼正常的Alter不能移動Lob段到別的表空間,而僅僅是移動了表段,可以採用如下的方法移動Lob
alter table tablename move
lob(lobsegname) store as (tablespace newts);

54.
怎麼樣修改表的列名
[A]9i
以上版本可以採用rname命令
ALTER TABLE UserName.TabName
RENAME COLUMN SourceColumn TO DestColumn
9i
以下版本可以採用create table …… as select * from SourceTable的方式。
另外,8i以上可以支援刪除列了
ALTER TABLE UserName.TabName
SET UNUSED (ColumnName) CASCADE CONSTRAINTS
ALTER TABLE UserName.TabName
DROP (ColumnName) CASCADE CONSTRAINTS

55.case
的用法
sql語句中
CASE test_value
WHEN expression1 THEN value1
[[WHEN expression2 THEN value2] [...]]
[ELSE default_value]
END

比如1
SELECT last_name, job_id, salary
CASE job_id
WHEN 'IT_PROG' THEN 1.10*salary
WHEN 'ST_CLERK' THEN 1.15*salary
WHEN 'SA_REP' THEN 1.20*salary
ELSE salary END "REVISED_SALARY"
FROM employees

比如2
select
case
when real_charge>=20000 and real_charge<30000 then 5000
when real_charge>=30000 and real_charge<40000 then 9000
when real_charge>=40000 and real_charge<50000 then 10000
when real_charge>=50000 and real_charge<60000 then 14000
when real_charge>=60000 and real_charge<70000 then 18000
when real_charge>=70000 and real_charge<80000 then 19000
when real_charge>=80000 and real_charge<90000 then 24000
when real_charge>=90000 and real_charge<100000 then 27000
when real_charge>=100000 and real_charge<110000 then 27000
when real_charge>=110000 and real_charge<120000 then 29000
when real_charge>=120000 then 36000
else
0
end ,acc_id,user_id,real_charge from okcai_jh_charge_200505

在存儲過程中
case v_strGroupClassCode
when '1' then
v_nAttrNum := v_nAttrNum + 300;
v_strAttrFlag := '1'||substr(v_strAttrFlag,2,7);
when '2' then
v_nAttrNum := v_nAttrNum + 200;
v_strAttrFlag := '2'||substr(v_strAttrFlag,2,7);
else
NULL;
end case;
注意的是存儲過程和sql語句有的細微差別是用end case,而不是end。語句後面跟";"

 

臉書網友討論
發表於 2013-11-13 01:09:28 | 顯示全部樓層
不錯,看看。  

版主招募中

發表於 2013-11-13 01:09:28 | 顯示全部樓層
你加油吧  


您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2016-12-9 14:03 , Processed in 0.068611 second(s), 23 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表