PLSQL 函数学习 - Start with...Connect By

it2022-05-05  209

create table myTestTable as        select rownum as id,               to_char(sysdate + rownum/24/3600, 'yyyy-mm-dd hh24:mi:ss') as inc_datetime,               trunc(dbms_random.value(0, 100)) as random_id,               dbms_random.string('x', 20) random_string          from dual        connect by level <= 100000; 上面SQL是利用了Oracle数据库语法的几个实用小技巧实现的:1、利用Oracle特有的“connect by”树形连接语法生成测试记录,“level <= 10”表示要生成10记录;2、利用rownum虚拟列生成递增的整数数据;--虚拟出0-100的数值   TRUNC(TO_DATE('24-Nov-1999 08:37 pm','dd-mon-yyyy hh:mi am','hh')) ='24-Nov-1999 08:00:00 am'--只显示小时3、利用sysdate函数加一些简单运算来生成日期数据,本例中是每条记录的时间加1秒;4、利用dbms_random.value函数生成随机的数值型数据,本例中是生成0到100之间的随机整数; 5、利用dbms_random.string函数生成随机的字符型数据,本例中是生成长度为20的随机字符串,字符串中可以包括字符或数字。ID         INC_DATETIME        RANDOM_ID  RANDOM_STRING---------- ------------------- ---------- --------------------          1 2009-12-08 19:43:14         76 GWMU280MIVBKKOCZV620         2 2009-12-08 19:43:15         34 GNV88O6TDHD3TWC5GWI5         3 2009-12-08 19:43:16         77 LI6H4O5IAHQIMO4B0WMH         4 2009-12-08 19:43:17         99 LP7XP49I0YOJIYSJDQZO         5 2009-12-08 19:43:18         55 V3284X9RXW4UZI8BQMO3         6 2009-12-08 19:43:19         16 T0OA52UAOGHL1TT46H25         7 2009-12-08 19:43:20         61 UY6RUOF7HWTO86942FLP         8 2009-12-08 19:43:21         25 JYXO4OPEW8J1CKVCPDJR         9 2009-12-08 19:43:22         10 DONU6W9QVQM3KJ2UG8LO        10 2009-12-08 19:43:23         76 J8DJLVNOUIZDXE4UXUJG  ..............................

更多详细的信息:http://www.javaeye.com/topic/287749

转载于:https://www.cnblogs.com/buro79xxd/archive/2010/01/25/1682591.html


最新回复(0)