How to automatically generate a table with dates from 20000101 to 20500101 for a total of 50 years?

Source: Internet
Author: User
How to automatically generate a table with a date of 50 years from 20000101 to 20500101?
  • software environment:

      1. Windows NT4.0 + Oracle 8.0.4
      2. Oracle installation path: C: \ orant
  • SQL statement:

      Drop table da_yyyymmdd; -- If yes, delete the table first.
      Create Table da_yyyymmdd (RQ char (8) primary key); -- create a table. RQ (date) is the primary keyword.

      declare
      I number; -- use cyclically
      J char (8); -- record the date value
      begin
      J: = '123 '; -- set the initial value
      for I in 1 .. 18250 loop -- 365*50 = 600 days
      insert into da_yyyymmdd values (j); -- insert record
      J: = to_char (to_date (J, 'yyyymmdd ') + 1, 'yyyymmdd'); -- date plus 1 day
      end loop; -- loop end
      end;
      /
      commit; -- submit, PL/SQL blocks are not automatically submitted

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.