alter table 表名  add constraint 索引名 primary key (字段名)

解决方案 »

  1.   

    没有啊.下面是测试:SQL> set serverout on
    SQL> set autotrace on 
    SQL> set autotrace traceonly
    SQL> create table testd
      2  (
      3      id number primary key,
      4      name varchar2(200)
      5  )
      6  tablespace cux;Table created.SQL> insert into testd select a.user_id ,a.user_name from fnd_user a;483 rows created.
    Execution Plan
    ----------------------------------------------------------
       0      INSERT STATEMENT Optimizer=CHOOSE (Cost=5 Card=450 Bytes=495
              0)   1    0   TABLE ACCESS (FULL) OF 'FND_USER' (Cost=5 Card=450 Bytes=4
              950)Statistics
    ----------------------------------------------------------
             44  recursive calls
             26  db block gets
             35  consistent gets
             24  physical reads
          20908  redo size
            351  bytes sent via SQL*Net to client
            596  bytes received via SQL*Net from client
              4  SQL*Net roundtrips to/from client
              4  sorts (memory)
              0  sorts (disk)
            483  rows processedSQL> commit;Commit complete.SQL> select * from fnd_user a where a.user_id=1055;
    Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=1 Bytes=216)
       1    0   TABLE ACCESS (BY INDEX ROWID) OF 'FND_USER' (Cost=1 Card=1
               Bytes=216)   2    1     INDEX (UNIQUE SCAN) OF 'FND_USER_U1' (UNIQUE)
    Statistics
    ----------------------------------------------------------
              0  recursive calls
              0  db block gets
              2  consistent gets
              0  physical reads
              0  redo size
           1220  bytes sent via SQL*Net to client
            308  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processedSQL>
      

  2.   

    用不用索引是由oracle的优化器决定的,当然,有时并不是最优。
    可以使用hints来强制优化器来使用索引:select /*+ INDEX(aa) */     *   from temp where aa = 'sdfdf';
      

  3.   

    同意kongkongye的说法:
    select /*+ INDEX(temp aa) */     *   from temp where aa = 'sdfdf';