【Oracle/PLSQL】一段给表字段充值时赋上随机字符串的PLSQL程序
建表:
create table heishehui( id number, name nvarchar2(20), group_name nvarchar2(20), primary key(id) );
PLSQL:
declare v integer; begin for i in 1..10000 loop v:=dbms_random.value(1,5); insert into heishehui values(i,'Name'||i,decode(mod(v,2),0,'洪兴',1,'东星')); end loop; commit; end; /
执行:
SQL> declare 2 v integer; 3 begin 4 for i in 1..10000 loop 5 v:=dbms_random.value(1,5); 6 7 insert into heishehui values(i,'Name'||i,decode(mod(v,2),0,'洪兴',1,'东星')); 8 end loop; 9 10 commit; 11 12 end; 13 / PL/SQL 过程已成功完成。 SQL> select * from heishehui where rownum<6; ID NAME GROUP_NAME ---------- ---------------------------------------- ---------------------------------------- 262 Name262 东星 263 Name263 洪兴 264 Name264 东星 265 Name265 洪兴 266 Name266 东星 SQL>
END