你这个问题太笼统了!
你的密码如果要加密进行的话,要写一个算法程序!
如果只是要一个简单的标示: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;
你的密码如果要加密进行的话,要写一个算法程序!
如果只是要一个简单的标示: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;
能保证不唯一么?
来学习一下。
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;
:)
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;
这个不行吧,这个触发器就是建在这个t_booth表上的
if Num>0 then
else
delete from t_corp_user where ecode=:old.ecode; 最好把你的错误提示贴出来!
yxxx(小孬) 说的对!!
触发器中不能操作当前表.因为是变异表,这时候可以使用: select '密码' into :new.密码字段 的方式给该字段赋值.一个表上可以建多个触发器.根据条件触发.