pl/sql語言的中幾個知識點的總結(一)

來源:互聯網
上載者:User

1  用 update 多欄位批次更新 

update dog qq set(b,c)=
(select b,c from cat tt where tt.a=qq.a)
上面的括弧很重要,不能省略。

如果是t-sql就不能這樣寫。需要有一個from dog的語句。相比來說麻煩了點兒

2  用目表產生新表並拷貝資料

create table horse as select * from dog

3 從一個表取資料插入到另一個表

insert into dog select * from cat

4 預存程序中執行一個ddl語句

dbms_utility.exec_ddl_statement('grant mx_admin_role to '||p_username);

5 執行一個動態dml語句的方法

 

----------------------------
---將歸檔的詳細資料copy到 mx_mxb_committed_t_200中
---參數說明:
--pd_id_list 產品id的列表  例如:'22,34,35,36,37,38,39,40'
----------------------------
procedure mx_copy_to_200
 (
   pd_id_list in varchar2
 )  
 is
  v_cursor number;
  v_numrows number;
  s varchar2(800);
  s1 varchar2(250);
  s2 varchar2(250);
begin
  s:='insert into mxk_200 ';
  s:= s || ' select q.*,'''','''','''','''' from mxk q ';
  s:= s || ' where mxb_id in ';
  
  s1:= 'select b.mxb_id from mx_pd_mxb_syn a,mxk b ';
  s1:= s1 || ' where a.p_id in (' || pd_id_list || ') and a.p_lth_id=b.m_mxb_id'; 
  
  s2:= 'select d.mxb_id from mx_pd_mxb_syn c,mxk_200 d ';
  s2:= s2 || ' where c.p_id in (' || pd_id_list || ') and c.p_lth_id=d.m_mxb_id'; 
  
  s:= s || '(' || s1 ||' minus ' || s2 || ')';
  v_cursor:=DBMS_SQL.OPEN_CURSOR;
  DBMS_SQL.PARSE(v_cursor,s,DBMS_SQL.V7);
  v_numrows:=DBMS_SQL.EXECUTE(v_cursor);
  DBMS_SQL.CLOSE_CURSOR(v_cursor);
 
end mx_copy_to_200;

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.