你这个问题太笼统了!
你的密码如果要加密进行的话,要写一个算法程序!
如果只是要一个简单的标示:CREATE OR REPLACE TRIGGER "USER"."TRIG_TEST" BEFORE
INSERT ON "TABLE1" FOR EACH ROW DECLAREBEGIN
  --为密码字段设置六位数字随机数
  :NEW.C_MM := to_char(round(dbms_random.value(100000,999999)));
  
END TRIG_TEST;

解决方案 »

  1.   

    dbms_random.value()是怎么生成随机数啊?根据时间吗?
    能保证不唯一么?
    来学习一下。
      

  2.   

    to yxxx(小孬):
     dbms_random.value()生成的不是绝对的随机数,是伪随机!
     不能保证唯一的!
     这是包说明:(很详细的!)
        ------------
        --  OVERVIEW
        --
        --  This package should be installed as SYS.  It generates a sequence of
        --  random 38-digit Oracle numbers.  The expected length of the sequence
        --  is about power(10,28), which is hopefully long enough.
        --
        --------
        --  USAGE
        --
        --  This is a random number generator.  Do not use for cryptography.
        --  For more options the cryptographic toolkit should be used.
        --
        --  By default, the package is initialized with the current user
        --  name, current time down to the second, and the current session.
        --
        --  If this package is seeded twice with the same seed, then accessed
        --  in the same way, it will produce the same results in both cases.
        --
        --------
        --  EXAMPLES
        --
        --  To initialize or reset the generator, call the seed procedure as in:
        --      execute dbms_random.seed(12345678);
        --    or
        --      execute dbms_random.seed(TO_CHAR(SYSDATE,'MM-DD-YYYY HH24:MI:SS'));
        --  To get the random number, simply call the function, e.g.
        --      my_random_number BINARY_INTEGER;
        --      my_random_number := dbms_random.random;
        --    or
        --      my_random_real NUMBER;
        --      my_random_real := dbms_random.value;
        --  To use in SQL statements:
        --      select dbms_random.value from dual;
        --      insert into a values (dbms_random.value);
        --      variable x NUMBER;
        --      execute :x := dbms_random.value;
        --      update a set a2=a2+1 where a1 < :x;
      

  3.   

    谢谢ashzs((可以包含中文字符))
    :)
      

  4.   

    写开了,请ASHZS帮我看下以下代码有什么编译错误?我第一次写触发器。
    create or replace trigger Mod_booth_Corp_User AFTER INSERT OR UPDATE OF ECODE,BOOTHNO,STAGE
     ON T_BOOTH
     FOR EACH ROW 
    DECLARE
     cnt    number;
     oppwd  number;
      Num Integer;
    BEGIN  
    --当该摊位首次分配时  
    if :old.ecode is null then
         select count(*) into from t_corp_user where opcode=:new.ecode;
          if cnt is null or cnt=0 then
          oppwd:= to_char(round(dbms_random.value(100000,999999)));
          insert into t_corp_user values(:new.delecode,:new.ecode,oppwd);
          end if;
      end if;
    --当该摊位取消分配时
     if :new.ecode is null then
        select count(*) into Num from t_booth where ecode=:old.ecode;
       if Num>0 then
       else
       delete from t_corp_user where ecode=:old.ecode; 
        end if;
    end if;
    end;
      

  5.   

    我发现 select count(*) into from t_corp_user where opcode=:new.ecode; 这里漏了一个into cnt ,但修改后编译还是提示有错误
      

  6.   

    select count(*) into from t_corp_user where opcode=:new.ecode;into 后面没变量
      

  7.   

    select count(*) into Num from t_booth where ecode=:old.ecode;
    这个不行吧,这个触发器就是建在这个t_booth表上的
      

  8.   

    to  yxxx(小孬):别客气,共同学习。to sunaldo(风) :这句then和else之间没有内容?
    if Num>0 then
       else
       delete from t_corp_user where ecode=:old.ecode; 最好把你的错误提示贴出来!
      

  9.   

    oracle不允许触发器查询正在被修改的表(变化表)
      

  10.   

    oracle不允许触发器查询正在被修改的表(变化表)
      
    yxxx(小孬) 说的对!! 
     
         
     
      

  11.   

    要生成密码,看你的要求.是随机还是相对规律. 可以考虑使用随机数.,也可以考虑使用时间中的时分秒.  
        触发器中不能操作当前表.因为是变异表,这时候可以使用: select '密码' into :new.密码字段 的方式给该字段赋值.一个表上可以建多个触发器.根据条件触发.