Oracle implements the Generate_series functionality of PostgreSQL

Source: Internet
Author: User
Tags postgresql

PostgreSQL has a function of generating sequences, which makes it easy to create data. Here I use Oracle to implement the function of the generate_series function of Pgsql.
POSTGRESQL.
t_girl=# SELECT * from Generate_series (1,10);               Generate_series-----------------1 2 3 4 5 6 7 8 9 10 (10 Row Records) Time: 1.290 mst_girl=# select * from generate_s Eries (1,10,2); Generate_series-----------------1 3 5 7 9 (5 line Records) Time: 0.431 mst_girl=# SELECT * from Generate_series (1,10,3);  Generate_series-----------------1 4 7 10 (4 Row Records) Time: 0.879 mst_girl=# SELECT * from Generate_series (2,10,3);  Generate_series-----------------2 5 8 (3 Row Records) Time: 0.867 mst_girl=# Select COUNT (*) From Generate_series (1,1000); Count-------1000 (1 Row Records) Time: 1.142 mst_girl=# Select To_char (Now ()-' 1 days ':: Interval * n, ' yyyy-mm-dd ') as result from Gen   Erate_series (1,10) g (n); Result------------2015-12-08 2015-12-07 2015-12-062015-12-05 2015-12-04 2015-12-03 2015-12-02 2015-12-01 2015-11-30 2015-11-29 (10 Row Records) Time: 17.284 ms 






ORACLE:
12:10:34 sql> SELECT * FROM table (Ytt_generate_series (1,10));                                                                               Column_value------------                                                                               1                                                                               2 3                                                                               4                                                                               5 6                                                                                7 8                                                                              9                                            10                        10 rows have been selected. Used Time: 00:00:00.0212:10:36 sql> select * FROM table (Ytt_generate_series (1,10,2));                                                                               Column_value------------                                                                               1                                                                               3 5                                                                               7  9 used time: 00:00:00.0012:10:54 sql> select * FROM Table (Ytt_generate_series (1,10,3));                                                                               Column_value------------                                                               1                4 7                                                                    10 Used Time: 00:00:00.0012:10:56 sql> select * FROM table (Ytt_generate_series (2,10,3));                                                                               Column_value------------                                                                               2                                                                    5 8 Time used: 00:00:00.0212:11:04 sql> Select COUNT (*) from table (Ytt_generate_series (1,10  00));                                                                            COUNT (*)----------      1000                                                                Time used: 00:00:00.1313:32:13 sql> select To_char (sysdat E-n, ' yyyy-mm-dd ') from table (Ytt_generate_series (1,10)); To_char (  SY----------2015-12-082015-12-072015-12-062015-12-052015-12-042015-12-032015-12-022015-12-012015-11-302015-11-29 has been selected 10 lines. Time used: 00:00:00.01






attached code:


--Declare result set.create or replace type Ytt_num is Object (n number),/create or replace type numbers_table is table O F ytt_num;/--function body.--Created by ytt.--2015/12/9create or replace Function ytt_generate_series (f_start_num numbe r: = 1,--Start number.f_end_num number,  --Finish number.f_step_num Number: = 1--step.) return numbers_table Pipelinedis   list numbers_table: = Numbers_table ();  I number: = 0;  J Number: = 1;begin  I: = F_start_num;  J: = 1;  --Increase nested table ' s size.  List.extend (f_end_num);  --Loop begin.  While I <= F_end_num loop  --initlization.    List (j): = Ytt_num (null);    List (j). N: = i;    Pipe row (List (j));    I: = i + f_step_num;    J: = j + 1;  End Loop;  return;end;/




Oracle implements the Generate_series functionality of PostgreSQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.