乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Oracle學(xué)習(xí)筆記(6) 動(dòng)態(tài)SQL - telense的日志 - 網(wǎng)易博客

       汲取者 2010-05-24

      動(dòng)態(tài)SQL:
      注意:不能用綁定變量替換實(shí)際的數(shù)據(jù)庫(kù)對(duì)象名(表、視圖、列等),只能替換字 面量
      動(dòng)態(tài)SQL的實(shí)現(xiàn)可以用:dbms_sql、execute immediate、open...for...(用于游標(biāo))
      Sql 代碼
      declare 
         type emp_table_type is table of employee%rowtype index by binary_integer;  
         emp_table emp_table_type;  
         emps employee%rowtype;  
         v_sql varchar2(1000);  
         v_name employee.name%type;  
         n_salary employee.salary%type;  
         type emp_cur_type is ref cursor;  
         emp_cur emp_cur_type;  
      begin 

      declare
         type emp_table_type is table of employee%rowtype index by binary_integer;
         emp_table emp_table_type;
         emps employee%rowtype;
         v_sql varchar2(1000);
         v_name employee.name%type;
         n_salary employee.salary%type;
         type emp_cur_type is ref cursor;
         emp_cur emp_cur_type;
      begin

      在PL/SQl程序塊中執(zhí)行DDL語(yǔ)句,在execute immediate后面直接接SQL字符串
      如果要對(duì)單引號(hào)進(jìn)行轉(zhuǎn)意,只要用兩個(gè)單引號(hào)連在一起就可以了(不是雙引號(hào))
      Sql代碼
      v_sql := 'insert into Employee values(66,''xxx'',''yyy'',0,to_char(sysdate,''yyyy-MM-dd hh24:mm:ss''),9999,''zzz'',66)';  
      execute immediate v_sql;  
      -- 通過(guò)綁定變量來(lái)執(zhí)行DDL語(yǔ)句,在SQL語(yǔ)句中使用 : 號(hào)來(lái)指定要?jiǎng)討B(tài)替換的數(shù)據(jù)  
      v_sql := 'insert into Employee values(:empno,''xxx'',''yyy'',0,to_char(sysdate,''yyyy-MM-dd hh24:mm:ss''),9999,''zzz'',66)';  
      execute immediate v_sql using &要插入的員工編號(hào):; 

         v_sql := 'insert into Employee values(66,''xxx'',''yyy'',0,to_char(sysdate,''yyyy-MM-dd hh24:mm:ss''),9999,''zzz'',66)';
         execute immediate v_sql;
         -- 通過(guò)綁定變量來(lái)執(zhí)行DDL語(yǔ)句,在SQL語(yǔ)句中使用 : 號(hào)來(lái)指定要?jiǎng)討B(tài)替換的數(shù)據(jù)
         v_sql := 'insert into Employee values(:empno,''xxx'',''yyy'',0,to_char(sysdate,''yyyy-MM-dd hh24:mm:ss''),9999,''zzz'',66)';
         execute immediate v_sql using &要插入的員工編號(hào):;

      用returning 返回execute immediate 執(zhí)行后影響的列
      將返回的信息傳遞給兩個(gè)綁定變量占位符(:1,:2),注意占位符可以使用任意名稱(chēng),我們可以對(duì)應(yīng)的在 immediate中使用returning接收綁定變量執(zhí)行后的結(jié)果值
      Sql代碼
      v_sql := 'update employee set salary=:salary where empno=:empno returning name,salary into :1,:2';  
      execute immediate v_sql using '&員工工資更改為:',&員工編號(hào) returning into v_name,n_salary;  
      dbms_output.put_line(v_name || ' 的工資更改為 ' || n_salary);  
      -- 使用Select返回隱式游標(biāo)的結(jié)果集  
      v_sql := 'select * from employee where empno=:empno'; 

         v_sql := 'update employee set salary=:salary where empno=:empno returning name,salary into :1,:2';
         execute immediate v_sql using '&員工工資更改為:',&員工編號(hào) returning into v_name,n_salary;
         dbms_output.put_line(v_name || ' 的工資更改為 ' || n_salary);
         -- 使用Select返回隱式游標(biāo)的結(jié)果集
         v_sql := 'select * from employee where empno=:empno';

      因?yàn)镾elect語(yǔ)句本來(lái)就會(huì)返回值,所以在 execute immediate中就不再需要寫(xiě)Returning語(yǔ)句了,記憶的方法是如果在SQL字符串中含有Returning,那么在execute immediate就需要寫(xiě)Returning,反之就不需要寫(xiě)了
      要注意的是在execute immediate子句中的using必須寫(xiě)在最后面
      Sql代碼
         execute immediate v_sql bulk collect into emp_table using &要查詢(xún)的員工編號(hào)1:;  
         for i in 1..emp_table.count loop  
             dbms_output.put_line(emp_table(i).name || '當(dāng)前的工資是 ' || emp_table(i).salary || ',他負(fù)責(zé)的工作是 ' || emp_table(i).job);  
         end loop;  
         -- 使用Select返回游標(biāo)變量的結(jié)果集(open...for...)  
         v_sql := 'select * from employee where empno=:empno';  
         open emp_cur for v_sql using &要查詢(xún)的員工編號(hào)2:;  
         loop  
            fetch emp_cur into emps;  
            exit when emp_cur%notfound;  
            dbms_output.put_line(emps.name || '加入公司的時(shí)間是 ' || emps.hiredate);  
         end loop;  
      end;  

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶(hù) 評(píng)論公約

        類(lèi)似文章 更多