绑定变量优缺点、使用、绑定变量窥探、 Oracle自适应共享游标

绑定变量优缺点、使用、绑定变量窥探

    绑定变量是Oracle解决硬解析的首要利器,能解决OLTP系统中library cache的过度耗用以提高性能。然刀子磨的太快,使起来锋利,却容易折断。凡事皆有利弊二性,因地制宜,因时制宜,全在如何权衡而已。本文讲述了绑定变量的使用方法,以及绑定变量的优缺点、使用场合。

 

一、绑定变量

    提到绑定变量,就不得不了解硬解析与软解析。硬解析简言之即一条SQL语句没有被运行过,处于首次运行,则需要对其进行语法分析,语义识别,跟据统计信息生成最佳的执行计划,然后对其执行。而软解析呢,则是由于library cache已经存在与该SQL语句一致的SQL语句文本、运行环境,即有相同的父游标与子游标,采用拿来主义,直接执行即可。软解析同样经历语法分析,语义识别,且生成hash value ,接下来在library cache搜索相同的hash value ,如存在在实施软解析。有关更多的硬解析与软解析以及父游标,子游标请作如下参考:
    
    有关硬解析与软解析,请参考:Oracle 硬解析与软解析    有关父游标、子游标,请参考:父游标、子游标与共享游标    
    绑定变量
      首先其实质是变量,有些类似于我们经常使用的替代变量,替代变量使用&占位符,只不过绑定变量使用:
      替代变量使用时为 &variable_para,相应的绑定变量则为 :bind_variable_para
      通常一个SQL语句包含动态部分和静态部分,占位符实质是SQL语句中容易发生变化的部分,通常为其条件或取值范围。动态部分在一般情况下(数据倾斜除外),对执行计划的生成的影响是微乎其微的。故同一SQL语句不同的动态部分产生的执行计划都是相同的。

        
二、绑定变量的使用
    1、在SQLPlus中使用绑定变量

[sql] view plain copy

 print?

  1. SQL> variable eno number;                           -->使用variable定义变量                                              
  2. SQL> exec :eno:=7788;                                                                                                    
  3. SQL> select ename,job,sal from emp where empno=:eno;                                                                     
  4.                                                                                                                          
  5. ENAME      JOB              SAL                                                                                          
  6. ---------- --------- ----------                                                                                          
  7. SCOTT      ANALYST         3000                                                                                          
  8.                                                                                                                          
  9. SQL> col sql_text format a55                                                                                             
  10. SQL> select sql_id,sql_text,executions from v$sqlarea   -->首次查询后在v$sqlarea保存父游标且执行次数EXECUTIONS为1        
  11.   2  where sql_text like '%select ename,job,sal%' and sql_text not like '%from v$sql%';                                  
  12.                                                                                                                          
  13. SQL_ID        SQL_TEXT                                                EXECUTIONS                                         
  14. ------------- ------------------------------------------------------- ----------                                         
  15. dbc6vx6z6n1zv select ename,job,sal from emp where empno=:eno                   1                                         
  16.                                                                                                                          
  17. SQL> select sql_id,hash_value,child_number,sql_text from v$sql -->查询视图v$sql查看该SQL对应的子游标,且CHILD_NUMBER为0  
  18.   2  where sql_text like '%select ename,job,sal%' and sql_text not like '%from v$sql%';                                  
  19.                                                                                                                          
  20. SQL_ID        HASH_VALUE CHILD_NUMBER SQL_TEXT                                                                           
  21. ------------- ---------- ------------ -------------------------------------------------------                            
  22. dbc6vx6z6n1zv 3194619899            0 select ename,job,sal from emp where empno=:eno                                     
  23.                                                                                                                          
  24. SQL> exec :eno:=7369;                                                                                                    
  25. SQL> select ename,job,sal from emp where empno=:eno;  -->再次对变量赋值并查询                                            
  26.                                                                                                                          
  27. ENAME      JOB              SAL                                                                                          
  28. ---------- --------- ----------                                                                                          
  29. SMITH      CLERK            800                                                                                          
  30.                                                                                                                          
  31. SQL> exec :eno:=7521                                                                                                     
  32. SQL> select ename,job,sal from emp where empno=:eno;                                                                     
  33.                                                                                                                          
  34. ENAME      JOB              SAL                                                                                          
  35. ---------- --------- ----------                                                                                          
  36. WARD       SALESMAN        1250                                                                                          
  37.                                                                                                                          
  38. SQL> select sql_id,sql_text,executions from v$sqlarea -->视图v$sqlarea中EXECUTIONS值为3,对应的SQL被执行了3次            
  39.   2  where sql_text like '%select ename,job,sal%' and sql_text not like '%from v$sql%';                                  
  40.                                                                                                                          
  41. SQL_ID        SQL_TEXT                                                EXECUTIONS                                         
  42. ------------- ------------------------------------------------------- ----------                                         
  43. dbc6vx6z6n1zv select ename,job,sal from emp where empno=:eno                   3                                         
  44.                                                                                                                          
  45. -->视图v$sql中对应的子游标也实现了完全共享,保持CHILD_NUMBER为0                                                          
  46. SQL> select sql_id,hash_value,child_number,sql_text from v$sql                                                           
  47.   2  where sql_text like '%select ename,job,sal%' and sql_text not like '%from v$sql%';                                  
  48.                                                                                                                          
  49. SQL_ID        HASH_VALUE CHILD_NUMBER SQL_TEXT                                                                           
  50. ------------- ---------- ------------ -------------------------------------------------------                            
  51. dbc6vx6z6n1zv 3194619899            0 select ename,job,sal from emp where empno=:eno                                     

    2、PL/SQL块中使用绑定变量

[sql] view plain copy

 print?

  1. SQL> create table t(id number,val number);  -->首先创建表t                                                               
  2.                                                                                                                          
  3. SQL> get get_parse.sql                                                                                                   
  4.   1  select name,value from v$mystat a join v$statname b                                                                 
  5.   2* on a.statistic#=b.statistic# where b.name like 'parse count%';                                                      
  6.                                                                                                                          
  7. SQL> @get_parse.sql   -->获得当前的解析情况,此时hard parase 为63                                                        
  8.                                                                                                                          
  9. NAME                           VALUE                                                                                     
  10. ------------------------- ----------                                                                                     
  11. parse count (total)              394                                                                                     
  12. parse count (hard)                63                                                                                     
  13. parse count (failures)             1                                                                                     
  14.                                                                                                                          
  15. -->下面的pl/sql代码中,Oracle实现自动变量自动绑定,执行了30次的insert操作,但oracle认为每次执行的语句都是一样的          
  16. /**************************************************/                                                                     
  17. /* Author: Robinson Cheng                         */                                                                     
  18. /* Blog:   http://blog.csdn.net/robinson_0612     */                                                                     
  19. /* MSN:    robinson_0612@hotmail.com              */                                                                     
  20. /* QQ:     645746311                              */                                                                     
  21. /**************************************************/                                                                     
  22.                                                                                                                          
  23. SQL> begin                     -->执行pl/sql代码,向表t中插入30条记录                                                    
  24.   2  for i in 1..30 loop                                                                                                 
  25.   3  insert into t values(i,i*2);                                                                                        
  26.   4  end loop;                                                                                                           
  27.   5  commit;                                                                                                             
  28.   6  end;                                                                                                                
  29.   7  /                                                                                                                   
  30.                                                                                                                          
  31. PL/SQL procedure successfully completed.                                                                                 
  32.                                                                                                                          
  33. SQL>  @get_parse              -->代码执行后的结果,硬解析数量仅仅增加了3次                                               
  34.                                                                                                                          
  35. NAME                           VALUE                                                                                     
  36. ------------------------- ----------                                                                                     
  37. parse count (total)              401                                                                                     
  38. parse count (hard)                67                                                                                     
  39. parse count (failures)             1                                                                                     

    3、在存储过程或包中使用绑定变量

[sql] view plain copy

 print?

  1. -->存储过程和保重,对参数的传递即是使用自动绑定变量来实现,因此编程人员无须操心绑定变量问题,如下例所示:               
  2. SQL> create or replace procedure ins_t(p_id in number,p_value in number) -->创建一个过程用于向表t插入记录               
  3.   2  as                                                                                                                 
  4.   3    begin                                                                                                            
  5.   4      insert into t values(p_id,p_value);                                                                            
  6.   5      commit;                                                                                                        
  7.   6    end;                                                                                                             
  8.   7  /                                                                                                                  
  9.                                                                                                                         
  10. Procedure created.                                                                                                      
  11.                                                                                                                         
  12. SQL> select sid,serial# from v$session where username='SCOTT';  -->获得当前用户的sid,serial#                            
  13.                                                                                                                         
  14.        SID    SERIAL#                                                                                                   
  15. ---------- ----------                                                                                                   
  16.       1084        938                                                                                                   
  17.                                                                                                                         
  18. SQL> exec dbms_monitor.session_trace_enable(session_id=>1084,serial_num=>938);  -->对当前的session启用跟踪              
  19.                                                                                                                         
  20. PL/SQL procedure successfully completed.                                                                                
  21.                                                                                                                         
  22. SQL> exec ins_t(31,62);               -->执行存储过程                                                                   
  23.                                                                                                                         
  24. PL/SQL procedure successfully completed.                                                                                
  25.                                                                                                                         
  26. SQL> exec ins_t(32,64);                                                                                                 
  27.                                                                                                                         
  28. PL/SQL procedure successfully completed.                                                                                
  29.                                                                                                                         
  30. SQL> exec dbms_monitor.session_trace_disable(session_id=>1084,serial_num=>938); -->关闭对session的跟踪                  
  31.                                                                                                                         
  32. PL/SQL procedure successfully completed.                                                                                
  33.                                                                                                                         
  34. SQL> SET LINESIZE 180                                                                                                   
  35. SQL> COLUMN trace_file FORMAT A100                                                                                      
  36. SQL> SELECT s.sid,                   -->获得跟踪文件位置                                                                
  37.   2  s.serial#,                                                                                                         
  38.   3  p.spid,                                                                                                            
  39.   4  pa.value || '/' || LOWER(SYS_CONTEXT('userenv','instance_name')) ||                                                
  40.   5  '_ora_' || p.spid || '.trc' AS trace_file                                                                          
  41.   6  FROM v$session s,                                                                                                  
  42.   7  v$process p,                                                                                                       
  43.   8  v$parameter pa                                                                                                     
  44.   9  WHERE pa.name = 'user_dump_dest'                                                                                   
  45.  10  AND s.paddr = p.addr                                                                                               
  46.  11  AND s.audsid = SYS_CONTEXT('USERENV', 'SESSIONID');                                                                
  47.                                                                                                                         
  48.        SID    SERIAL# SPID         TRACE_FILE                                                                           
  49. ---------- ---------- ------------ --------------------------------------------------------------                       
  50.       1084        938 10883        /u02/database/CNMMBO/udump/cnmmbo_ora_10883.trc                                      
  51.                                                                                                                         
  52. SQL> SQL>                                                                                                               
  53. SQL> ho pwd                                                                                                             
  54. /users/oracle                                                                                                           
  55.                                                                                                                         
  56. -->使用tkprof工具格式化跟踪文件便于阅读                                                                                 
  57. SQL> ho tkprof /u02/database/CNMMBO/udump/cnmmbo_ora_10883.trc /users/oracle/ins_t.txt explain=goex_admin/goex_admin    
  58.                                                                                                                         
  59. TKPROF: Release 10.2.0.3.0 - Production on Fri Sep 9 12:55:18 2011                                                      
  60.                                                                                                                         
  61. Copyright (c) 1982, 2005, Oracle.  All rights reserved.                                                                 
  62.                                                                                                                         
  63. SQL> ho cat /users/oracle/ins_t.txt  -->查看跟踪文件                                                                    
  64. ......                                                                                                                  
  65. BEGIN ins_t(31,62); END;                                                                                                
  66. ......                                                                                                                  
  67. INSERT INTO T      -->可以看到insert into语句中使用了绑定变量                                                           
  68. VALUES                                                                                                                  
  69. (:B2 ,:B1 )                                                                                                             
  70.                                                                                                                         
  71. call     count       cpu    elapsed       disk      query    current        rows                                        
  72. ------- ------  -------- ---------- ---------- ---------- ----------  ----------                                        
  73. Parse        0      0.00       0.00          0          0          0           0                                        
  74. Execute      2      0.11       0.11          2        281         27           2                                        
  75. .......                                                                                                                 

    4、在动态SQL中是使用绑定变量    

[sql] view plain copy

 print?

  1. -->动态SQL中不能自动使用绑定变量,需要手动设定绑定变量                                                                   
  2. SQL> @get_parse     -->获得当前hard parse解析情况,此时为120                                                             
  3.                                                                                                                          
  4. NAME                           VALUE                                                                                     
  5. ------------------------- ----------                                                                                     
  6. parse count (total)              533                                                                                     
  7. parse count (hard)               120                                                                                     
  8. parse count (failures)             1                                                                                     
  9.                                                                                                                          
  10. SQL> begin                                                                                                               
  11.   2  for i in 1..30 loop                                                                                                 
  12.   3  execute immediate 'insert into t values(:1,:2)' using i,i+i-2;  -->动态SQL使用绑定变量,该语句将执行30次            
  13.   4  end loop;                                                                                                           
  14.   5  commit;                                                                                                             
  15.   6  end;                                                                                                                
  16.   7  /                                                                                                                   
  17.                                                                                                                          
  18. PL/SQL procedure successfully completed.                                                                                 
  19.                                                                                                                          
  20. SQL> @get_parse     --> 动态SQL执行后,尽管执行了30次,但硬解析数量仅仅增加了2次                                         
  21.                                                                                                                          
  22. NAME                           VALUE                                                                                     
  23. ------------------------- ----------                                                                                     
  24. parse count (total)              537                                                                                     
  25. parse count (hard)               122                                                                                     
  26. parse count (failures)             1                                                                                     
  27.                                                                                                                          
  28. SQL> set serveroutput on;                                                                                                
  29. SQL> get get_sal.sql    -->下面的pl/sql中使用了绑定变量                                                                  
  30.   1   DECLARE                                                                                                            
  31.   2   TYPE emp_cur IS REF CURSOR;                                                                                        
  32.   3   my_emp_cur emp_cur;                                                                                                
  33.   4   my_emp_rec emp%ROWTYPE;                                                                                            
  34.   5   BEGIN                                                                                                              
  35.   6   OPEN my_emp_cur FOR 'select * from emp where deptno=:dno' USING 10;                                                
  36.   7   LOOP                                                                                                               
  37.   8   FETCH my_emp_cur INTO my_emp_rec;                                                                                  
  38.   9   EXIT WHEN my_emp_cur%NOTFOUND;                                                                                     
  39.  10   dbms_output.put_line(my_emp_rec.ename||'''s salary is : '||my_emp_rec.sal);                                        
  40.  11   END LOOP;                                                                                                          
  41.  12*  END;                                                                                                               
  42.  13  /                                                                                                                   
  43. CLARK's salary is : 4900                                                                                                 
  44. KING's salary is : 5000                                                                                                  
  45. MILLER's salary is : 1300                                                                                                
  46.                                                                                                                          
  47. PL/SQL procedure successfully completed.                                                                                 
  48.                                                                                                                          
  49. SQL> /                                                                                                                   
  50. CLARK's salary is : 4900                                                                                                 
  51. KING's salary is : 5000                                                                                                  
  52. MILLER's salary is : 1300                                                                                                
  53.                                                                                                                          
  54. PL/SQL procedure successfully completed.                                                                                 
  55.                                                                                                                          
  56. SQL> select sql_text,executions,sql_id from v$sqlarea where sql_text like 'select * from emp where deptno=:dno%';        
  57.                                                                                                                          
  58. SQL_TEXT                                      EXECUTIONS SQL_ID                                                          
  59. --------------------------------------------- ---------- -------------                                                   
  60. select * from emp where deptno=:dno                    2 c1nx6x02h655a                                                   

        
三、绑定变量的优缺点及使用场合
    优点:
        可以在library cache中共享游标,避免硬解析以及与之相关的额外开销在大批量数据操作时将呈数量级来减少闩锁的使用,避免闩锁的竞争
      
    缺点:
        绑定变量被使用时,查询优化器会忽略其具体值,因此其预估的准确性远不如使用字面量值真实,尤其是在表存在数据倾斜(表上的数据非均匀分布)的列上会提供错误的执行计划。从而使得非高效的执行计划被使用。
    
    使用场合:
        OLTP
            在OLTP系统中SQL语句重复执行频度高,但处理的数据量较少,结果集也相对较小,尤其是使用表上的索引来缩小中间结果集,其解析时间通常会接近或高于执行时间,因此该场合适合使用绑定变量。
        
        OLAP
            在OLAP系统中,SQL语句执行次数相对较少,但返回的数据量较大,因此多数情况下倾向于使用权标扫描更高效,其SQL语句执行时间远高于其解析时间,因此使用绑定变量对于总响应时间影响不大。而且增加生成低效执行计划的风险。即在在OLAP系统中使用字面量的性能高于使用绑定变量。
    
    注意:
        对于实际的数据库对象,如(表,视图,列等),不能使用绑定变量替换,只能替换字面量。如果对象名是在运行时生成的,则需要对其用字符串拼接,同时,sql只会匹配已经在共享池中相同的对象名。



2、绑定变量窥探

 Bind Peeking是Oracle 9i中引入的新特性,一直持续到Oracle 10g R2。它的作用就是在SQL语句硬分析的时候,查看一下当前SQL谓词的值,以便生成最佳的执行计划。而在oracle 9i之前的版本中,Oracle 只根据统计信息来做出执行计划。

    使用SQL首次运行时的值来生成执行计划。后续再次运行该SQL语句则使用首次执行计划来执行。

    影响的版本:Oracle 9i, Oracle 10g

    对于绑定变量列中的特殊值或非均匀分布列上的绑定变量会造成非高效的执行计划被选择并执行。

要注意的是,Bind Peeking只发生在硬分析的时候,即SQL被第一次执行的时候,之后的变量将不会在做peeking。我们可以看出,Bind peeking并不能最终解决不同谓词导致选择不同执行计划的问题,它只能让SQL第一次执行的时候,执行计划选择更加准确,并不能帮助OLAP系统解决绑定变量导致执行计划选择错误的问题。这也是OLAP不应该使用绑定变量的一个原因。

更确切地说,绑定变量窥探是在SQL解析的物理阶段,查询优化器将会窥探绑定变量的值并将其作为字面量来使用。即ORACLE首次解析SQL时会将变量的真实值代入产生执行计划,后续对所有使用该绑定变量SQL语句都采用首次生存的执行计划。如此这般?那性能究竟如何?

结果是并非最佳的执行计划的使用。此问题在Oracle 11g中得以解决。

          

  

 

  1. >      <    >                                           
  2.                                                                                                                 
  3.                                                                                                           
  4.                                                 
  5.                                                               
  6.                                                                                                                 
  7. >           >                                                 
  8.          <                                         
  9.                                                                                                                 
  10. >          >                                       
  11.                                                                                                                 
  12. >                                                >                   
  13.                                                                                  
  14.     >                                                                                          
  15.     >                                                                                              
  16.     >                                                                                     
  17.     >                                                                         
  18.                                                                                                            
  19.                                                                                                               
  20.                                                                                                                 
  21.                                                                            
  22.                                                                                                                 
  23. >       >                           
  24.                                                                                                                 
  25.                                                                         
  26.                                                                  
  27.                                                                                                    

          

  

 

  1. >      <     >                                                 
  2.                                                                                                                        
  3.                                                                                                          
  4.                                                                                                          
  5.                                                                                                                  
  6.                                                                                                                        
  7. >     >                
  8.                                                                    
  9.                                                                                                
  10.                                                                             
  11.                                                                                       
  12.                                                                                                        
  13.                                                                    
  14.                                                                                                                                
  15.                                                                                                       
  16.                                             
  17.                                                                                        
  18.                                                                                   
  19.      <                                                                              
  20.                                                                                                                        
  21.                                                                                                
  22.                                                                                                                        
  23.                                             
  24.                                                                          
  25.                                             
  26.                                                                                          
  27.                                                                                                
  28.                                                                           
  29.                                             
  30.                                                                                                                        
  31.                                                                          
  32.                                                                     
  33.                                                                                                                        
  34.      <                                                                                                
  35.                                                                                                                        
  36. >      <   >                                              
  37.                                                                                                                        
  38. >     >                       
  39.                                                        >  
  40.                                                                                                       
  41.                                              
  42.                                                                                        
  43.                                                                                   
  44.      <                                                                               
  45.                                                                                                                        
  46.                                                                                                
  47.                                                                                                                        
  48.                                   
  49.                                                                          
  50.                                   
  51.                                                                                          
  52.                                                                                                
  53.                                                                        
  54.                                                                               
  55.                                   
  56.                                                                                                                        
  57.                                                                          
  58.                                                                     
  59.                                                                                                                        
  60.      <                                                                                                 

                

  

 

  1. >      >                                                                           
  2. >          >                                                                         
  3.                                                                                                                        
  4.                                                                                   
  5.                                                                                                                        
  6. >      <                                                                      
  7.                                                                                                                        
  8.                                                                                                          
  9.                                                                                                          
  10.                                                                                                                  
  11.                                                                                                                        
  12. >       >     
  13.                                                                                                                        
  14.                                                                                                       
  15.                                          
  16.                                                                                        
  17.                                                                                   
  18.      <                                                                            
  19.                                                                                                                        
  20.                                                                                                
  21.                                                                                                                        
  22.                                             
  23.                                                                          
  24.                                             
  25.                                                                                          
  26.                                                                                                
  27.                                                                           
  28.                                             
  29.                                                                                                                        
  30.                                                                          
  31.                                                                     
  32.                                                                                                                        
  33.      <    >                                                         
  34.                                                                                                                        
  35. >           >                                                                     
  36.                                                                                                                        
  37.                                                                                   
  38.                                                                                                                        
  39. >      <   >                                                 
  40.                                                                                                                        
  41.                                                                                                          
  42.                                                                                                          
  43.                                                                                                                     
  44.                                                                                                                        
  45. >      >                          
  46.                                                         >         
  47.                                        ><           
  48.          >                          
  49.                                                                                        
  50.                                                                                   
  51.      <                                                                            
  52.                                                                                                                        
  53.                                                                                                
  54.                                                                                                                        
  55.                                             
  56.                                                                          
  57.                                             
  58.                                                                                          
  59.                                                                                                
  60.                                                                           
  61.                                             
  62.                                                                                                                        
  63.                                                                          
  64.                                                                     
  65.                                                                                                                        
  66.      <                                                                                              
  67.                                                                                                                        
  68. >        >                                
  69.                                                                                                                            
  70. >                                                                                                         
  71.                                                                                                                        
  72.                                                                                                                    
  73.                                                                                                              
  74.                                                                                                                      
  75.                                                                                                                        
  76. >      <   ><                                   
  77.                                                                                                                        
  78.                                                                                                   
  79.                                                                                                   
  80.                                                                                                                      
  81.                                                                                                                        
  82. >        >       
  83.                                                                                                                        
  84.                                                                                                       
  85.                                 
  86.                                                                                        
  87.                                                                                   
  88.      <                                                                     
  89.                                                                                                                        
  90.                                                                                                
  91.                                                                                                                        
  92.                                   
  93.                                                                          
  94.                                   
  95.                                                                                          
  96.                                                                                                
  97.                                                                        
  98.                                                                               
  99.                                   
  100.                                                                                                                        
  101.                                                                          
  102.                                                                     
  103.                                                                                                                        
  104.      <                                                                                              
  105.                                                                                                                        
  106. >                     >                                                                
  107.                                                                                                                        
  108.                                                                                   
  109.                                                                                                                        
  110. >      <                                                               
  111.                                                                                                                        
  112.                                                                                                   
  113.                                                                                                   
  114.                                                                                                                     
  115.                                                                                                                        
  116. >     >  
  117.                                                                                                                        
  118.                                                                                                       
  119.                                  
  120.                                                                                        
  121.                                                                                   
  122.      <                                                                     
  123.                                                                                                                        
  124.                                                                                                
  125.                                                                                                                        
  126.                                   
  127.                                                                          
  128.                                   
  129.                                                                                          
  130.                                                                                                
  131.                                                                        
  132.                                                                               
  133.                                   
  134.                                                                                                                        
  135.                                                                          
  136.                                                                     
  137.                                                                                                                        
  138.      <                                                                                              
  139.                                                                                                                        
  140. >     


 

    
   
          

  

 

  1. >      <                                                    
  2.                                                                                                 
  3.                                                                                           
  4.                 
  5.                                   
  6.                                                                                                     
  7. >                                                          
  8.          <                         
  9.                                                                                                 
  10. >                                                 
  11.                                                                                                 
  12. >  >                             
  13.                                                                                                 
  14. >                                     
  15.                                                                                                 
  16.                                                         
  17.                                                  
  18.                                                                                    

           

  

 

  1. >                                                                                                 
  2. >                                                                                                  
  3. >                                                                                                 
  4. >      <                                                                  
  5.                                                                                                                    
  6.                                                                                                      
  7.                                                                                                      
  8.                                                                                                                
  9. >                                    
  10.                                                                                    
  11.                                                                               
  12.      <            >    
  13.                                                                                                                    
  14.                                                                                            
  15.                                                                                                                    
  16.                               
  17.                                                                      
  18.                               
  19.                                                                                      
  20.                                                                                            
  21.                                                                    
  22.                                                                            
  23.                               
  24.                                                                                                                    
  25. >        >                                         
  26. >                     
  27.                       
  28.                                                                                                                    
  29.                                                                             
  30.                                 
  31.       <                                                     

   
       
       
      
     
         
         
      
     
         
      
     
         
  
     
         
             
              

          

  

 

  1. >                                                                                                    
  2. >      <                                                                      
  3.                                                                                                                        
  4.                                                                                                          
  5.                                                                                                          
  6.                                                                                                                 
  7.                                                                                                                        
  8. >                                        
  9.                                                                                                                        
  10.                                                                                        
  11.                                                                                   
  12.      <  >                 
  13.                                              >                     
  14.                                                                                                
  15.                                                                                                                        
  16.                                   
  17.                                                                          
  18.                                   
  19.                                                                                          
  20.                                                                                                
  21.                                                                        
  22.                                                                                
  23.                                   
  24.                                                                                                                        
  25. >                                                                           
  26. >                         
  27.                           
  28.                                                                                                                        
  29.                                                                                 
  30.                                     
  31.       <                                                         
  32.                                                                                                                        
  33. >      <   >                                    
  34.                                                                                                                        
  35.                                                                                                          
  36.                                                                                                          
  37.                                                                                                                 
  38.                                                                                                                        
  39. >                                        
  40.                                                                                                                        
  41.                                                                                        
  42.                                                                                   
  43.      <    >      
  44.                                                >                                           
  45.                                                                                                
  46.                                                                                                                        
  47.                                             
  48.                                                                          
  49.                                             
  50.                                                                                          
  51.                                                                                                
  52.                                                                            
  53.                                             
  54.                                                                                                                        
  55. >                                               
  56. >                         
  57.                           
  58.                                                                                                                        
  59.                                                                                 
  60.                                     
  61.       <                                                         
  62.       <                                                         
  63.                                                                                                                        
  64. >        >                                                                        
  65.                                                                                                                        
  66. >      <  >                                        
  67.                                                                                                                        
  68.                                                                                                          
  69.                                                                                                          
  70.                                                                                                                 
  71.                                                                                                                        
  72. >                                  
  73.                           
  74.                                                                                                                        
  75.                                                                                         
  76.                                                                                  
  77.                                                                                                      
  78.                                                                                                      
  79.                              >                                                
  80.                                                                                                                        
  81. >       >                                                                            
  82.                                                                                                                        
  83. >      <  >                                        
  84.                                                                                                                        
  85.                                                                                                          
  86.                                                                                                          
  87.                                                                                                                  
  88.                                                                                                                        
  89.                                                                    
  90.                                                                                                
  91.                                                                             
  92.                                                                                       
  93.                                                                                                        
  94.                                                                    
  95.                                                                                                                        
  96. >                                  
  97.                           
  98.                                                                                                                        
  99.                                                                                         
  100.                                                                                  
  101.                                                                                                      
  102.                                                                                                      
  103.                                 >                  
  104.                                 >                                           
  105.                                                                                                                        
  106. >                                                                         
  107. >                             
  108.                                                                                                                        
  109.                                                                                                       
  110.      
  111.                                                                                        
  112.                                                                                   
  113.      <     >                                             
  114.                                                                                                                        
  115.                                                                                                
  116.                                                                                                                        
  117.                                   
  118.                                                                          
  119.                                   
  120.                                                                                          
  121.                                                                                                
  122.                                                                        
  123.                                                                                
  124.                                   
  125.                                                                                                                        
  126.                                                                                        
  127.                                                                                   
  128.      <   >            
  129.                                                                                                                        
  130.                                                                                                
  131.                                                                                                                        
  132.                                             
  133.                                                                          
  134.                                             
  135.                                                                                          
  136.                                                                                                
  137.                                                                            
  138.                                             
  139.                                                                                                                        
  140.                                                                                        
  141.                                                                                   
  142.      <   >          
  143.                                                                                                                        
  144.                                                                                                
  145.                                                                                                                        
  146.                                             
  147.                                                                          
  148.                                             
  149.                                                                                          
  150.                                                                                                
  151.                                                                            
  152.                                             
  153.                                                                                                                        
  154.                                                                                        
  155.                                                                                   
  156.      <  >             
  157.                                                                                                                        
  158.                                                                                                
  159.                                                                                                                        
  160.                                             
  161.                                                                          
  162.                                             
  163.                                                                                          
  164.                                                                                                
  165.                                                                            
  166.                                             

 
              

  

 

  1. >                          
  2.                                                               
  3.                                                                                                        
  4.                                                                                                                  
  5.                                               
  6.                                               
  7.                                                             >               
  8.                                                             >                  
  9.                                                             >                  
  10.                                                             >                  

   
              

  

 

  1. >             
  2.                                                   
  3.                                                                                        
  4.                                                    
  5.                            
  6.             <                                                    
  7.             <                                                    
  8.             <                                                    

   
              

  

 

  1. >           
  2.                                                                                         
  3.                                                                                                   
  4.                                                                         
  5.                                                                   
  6.                                                                                                
  7.                                                                                                
  8.                                                                                                
  9.                                                                                                
  10.                                                                                                
  11.                                                                                                
  12.                                                                                                
  13.                                                                                                
  14.                                                                                                
  15.                                                                                                
  16.                                                                                                
  17.                                                                                                

   
   
   
   
   



 



    

时间: 2024-09-18 13:14:08

绑定变量优缺点、使用、绑定变量窥探、 Oracle自适应共享游标的相关文章

Oracle自适应共享游标

     自适应游标共享Adaptive Cursor Sharing或扩展的游标共享(Extended Cursor Sharing)是Oracle 11g的新特性之一,主要用于解决以前版 本中由于绑定变量窥探导致SQL语句无法获得最佳执行计划的缺陷,即能够对效率低下的游标(子游标)进行自动识别而选择最佳的执行计划.本 文详细描述了自适应游标共享并给出示例.     有关绑定变量窥探请参考:Oracle 绑定变量窥探 一.示例自适应游标共享    1.创建演示环境        SQL> se

并非所有变量都已绑定,是怎么回事?

问题描述 C#连接Oracle总是报错.oleDbCommand.CommandText="select*fromtwherea=:hhhh";oleDbCommand.Parameters.Add("hhhh",OleDbType.Numeric);oleDbCommand.Parameters[0].Value=2;oleDbConnection.Open();inti=oleDbCommand.ExecuteNonQuery();oleDbConnection

利用angular.copy取消变量的双向绑定与解析_AngularJS

首先我们来看看示例代码 <body ng-app="app"> <div ng-controller="CopyController"> <div> data: <input ng-model="user.data" /><br> user.data: {{user.data}} <br> user1.data: {{user1.data}} <br> <b

asp.net中静态变量和非静态变量的区别

静态变量:静态变量使用 static 修饰符进行声明在所属类被装载时创建通过类进行访问所属类的所有实例的同一静态变量都是同一个值非静态变量:不带有 static 修饰符声明的变量称做非静态变量在类被实例化时创建通过对象进行访问同一个类的不同实例的同一非静态变量可以是不同的值示例: [复制到剪贴板]CODE: using System;using System.Collections.Generic;using System.Text;namespace Example01{    class P

在.NET中使用静态变量来代替Application变量

application|变量|静态 wincheer|2002-3-1 --------------------------------------------------------------------------------     在传统的ASP程序中,我们总是使用Application对象来保存应用程序级的变量.这种方式比较耗费内存----看看那些空间供应商明目张胆的限制Application的数量就知道了.现在好了,我们有了.NET ,可以充分发挥静态变量的优点.一方面,可以作为应

Sql Server实时错误:对象变量或with块变量未设置

大家这几天在做学生信息管理系统的时候,出现 最多的应该就是这个问题了,"实时错误'91':对象变量或with块变量未设置".如右图: 遇到这个问题,我们首先应该去参考MSDN,不过这时候MSDN似乎没有帮到我们很多,总结了一下,其实出现这个错误的情况有很多种: 1.在运行程序之前没有配置ODBC数据源或者ODBC数据源配置错误,当然前提得是SQL Server执行了相关的SQL代码(学生系统中用到的student.mdb文件). 2.代码问题,大多数情况是查询语句有问题,比如: (1)

final修饰的终态变量只能在声明变量时或构造函数里赋值嘛?

问题描述 final修饰的终态变量只能在声明变量时或构造函数里赋值嘛? class GongChengShi { final String name;//名字 final String dizhi;//地址 int age;//年龄 public GongChengShi(String name, int age) { this.name = name;//构造函数初始化时给名字和年龄赋值 this.age = age; } void setDizhi(String dizhi){//在子类中调

堆-.net在申明变量的时候,变量是属于什么状态?

问题描述 .net在申明变量的时候,变量是属于什么状态? 如题 今天看了一本书,本人的基础底子还是比较薄弱了,代码写了这么久才有兴趣去看看原理, Public struct ValPoint { Public int x; Public ValPoint(int x) { this.x = x; } } ValPoint vPoint1; //在书上表示这里并没有进行入栈,只有对变量进行了操作后才会算作是入栈 vPoint1.x=1;//也就是这一步的时候才会进行入栈 Console.Write

aspx-定义一个变量user使这个变量为当前登陆人帐号

问题描述 定义一个变量user使这个变量为当前登陆人帐号 在Login.aspx.cs中,在用户登陆时,记录了登陆人的帐号UserName: Session["UID"] = UID; Session["UNAME"] = UserName; Response.Redirect("Map.aspx"); 但是在其它的地方,如下,当想先判断UserName的值来执行不同的语句时,发现这个问题 var User = Session["UNA