Oracle Small case

Source: Internet
Author: User

--Create userCREATE USERJim identified byChangeit;--Assign login connection permissions to usersGRANTCONNECT toJim;--assigning resource permissions to usersGRANTRESOURCE toJim;--Reclaim Login PermissionsREVOKECONNECT fromJim;--Reclaim resource Operation permissionsREVOKERESOURCE fromJim;--Lock UserALTER USERJim account LOCK;--Unlocking the userALTER USERJim account UNLOCK;--Change password for userALTER USERJim identified byChangeit;--Create a Time dimension tableCREATE TABLEdim_date (date_idChar(8)Primary Key,--20160704Date_name date,--2016/7/4     Year  Number,-- .Year_halfChar(6),--2016H2Year_monthChar(6),--201607Year_quarterChar(6),--2016q3Half_number Number,--2Half_nameChar(2),--H2Quarter_number Number,--3Quarter_nameChar(2),--Q3Month_number Number,--7Month_name Nvarchar2 ( -),--JUNLWeek_number Number,--2Week_name Nvarchar2 ( -),--MondayCreat_date Date,--creation TimeUpdate_date Date)--Update Time    ; --test to choose a period of time    SelectTo_date ('2014-01-01','YYYY-MM-DD')+(rownum-1) fromDual Connect byRowNum<=(To_date ('2015-01-01','YYYY-MM-DD')-To_date ('2014-01-01','YYYY-MM-DD'));  withtemp_date as (        SelectTo_date ('2014-01-01','YYYY-MM-DD')+(rownum-1) fromDual Connect byRowNum<=(To_date ('2015-01-01','YYYY-MM-DD')-To_date ('2014-01-01','YYYY-MM-DD'))    )    Select *  fromtemp_date; --create a stored procedure, import time    CREATE OR REPLACE PROCEDUREsp_add_date asV_half Number; V_quarter Number; V_month Dim_date.month_name%type; V_month_number Number; CURSORC_date is    SELECTDate_id,dim_date.date_name fromdim_date; C_row c_date%RowType; BEGINMERGE intodim_date T1 USING (SelectTo_date ('2014-01-01','YYYY-MM-DD')+(rownum-1) Date_name fromDual Connect byRowNum<=(To_date ('2018-01-01','YYYY-MM-DD')-To_date ('2014-01-01','YYYY-MM-DD')) Temp_date on(T1.date_name=temp_date.date_name) whenMatched Then        Update Sett1.date_id=To_char (Temp_date.date_name,'YYYYMMDD')       when  notMatched Then        Insert(date_id)Values(To_char (Temp_date.date_name,'YYYYMMDD')); --Circular Cursors         forC_rowinchc_date loop V_month_number:=To_number (To_char (C_row. Date_name,'MM')); ifV_month_number>6  Thenv_half:=2; Elsev_half:=1; End if; UpdateDim_dateSetdim_date. Date_name=To_date (C_row. DATE_ID,'YYYY-MM-DD'), Dim_date. Half_name='H'||V_half--back here to add          whereDim_date. date_id=C_row.          date_id; EndLoop; END; 

Oracle Small case

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.