Copy and paste the code in ORACLE to create the function. The sample query to demontrate the function is also provided in the code below
Function: FN_RAND_PWD_ORACLE
CREATE OR REPLACE FUNCTION FN_RAND_PWD_ORACLE(inputval in number) RETURN VARCHAR2 AS
passvalue VARCHAR2(20);
tran NUMBER;
RandNum NUMBER;
the_letter VARCHAR2(20);
e NUMBER;
x NUMBER;
BEGIN
tran:=5;
select to_char(sysdate,'HH24') into x from dual;
if MOD(x,2)=0 then
x:=5;
else
x:=6;
end if;
for i in 1..x loop
RandNum := DBMS_RANDOM.VALUE(97, 122);
the_letter:= chr(RandNum);
select to_char(sysdate,'SSSS') into e from dual;
IF MOD(i,2)=0 and tran=5 THEN
passvalue:= concat(passvalue, TO_CHAR(inputval));
tran:=0;
End IF;
IF MOD(e,2)=0 THEN
the_letter:=LOWER(the_letter);
else
the_letter:= UPPER(the_letter);
end if;
passvalue:= concat(passvalue, the_letter);
end loop;
passvalue := substr(passvalue,1,1)||substr(passvalue,5,7);
return (passvalue);
END FN_RAND_PWD_ORACLE;
Implementation:
update TABLE1 set randompwd=FN_RAND_PWD(6) where id=21;
No comments:
Post a Comment