版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、Using Data TypesWhat Will I Learn?Create a table using TIMESTAMP and TIMESTAMP WITH TIME ZONE column data typesCreate a table using INTERVAL YEAR TO MONTH and INTERVAL DAY TO SECOND column data typesGive examples of organizations and personal situations where it is important to know to which time zo
2、ne a date-time value refers.Why Learn It?If you ever travel to another country, youll quickly find out that the money in your pocket may not be that of the local currency. If you want to buy something, it will be necessary to convert your money into the currency of the local country.This conversion
3、process is a lot like dealing with data types in SQL. Different types of data have different types of characteristics, the purpose of which is to efficiently store data. In this lesson, you will learn more about data types and their uses.Data typeEach value manipulated by Oracle has a data type.A va
4、lues data type associates a fixed set of properties with the value. These properties cause the database to treat values of one data type differently from values of another.Data typeDifferent data types offer several advantages:Columns of a single type produce consistent results. For example, DATE da
5、ta type columns always produce date values.You cannot insert the wrong type of data into a column. For example, columns of data type DATE will prevent NUMBER type data from being inserted.For these reasons, each column in a relational database can hold only one type of data. You cannot mix data type
6、s within a column.Most common data typesFor character values: CHAR (fixed size,maximum 2000 characters); VARCHAR2(variable size, maximum 4000 characters);CLOB (variable size, maximum 4 billion characters)For number values: NUMBER (variable size,maximum precision 38 digits)For date and time values: D
7、ATE, TIMESTAMP., INTERVALFor binary values (eg multimedia: JPG, WAV, MP3 and so on): RAW (variable size, maximum 2000 bytes); BLOB(variable size, maximum 4 billion bytes).Most common data typesFor character values, it is usually better to use VARCHAR2 or CLOB than CHAR, because it saves space and is
8、 faster. For example, an employees last name is Chang. In a VARCHAR2(30) column, only the 5 significant characters are stored: C h a n g. But in a CHAR(30) column, 25 trailing spaces would be stored as well, to make a fixed size of 30 characters.Number values can be negative as well as positive. For
9、 example, NUMBER(6,2) can store any value from +9999.99 down to 9999.99.DATE-TIME DATA TYPESThe DATE data type stores a value of centuries down to whole seconds, but cannot store fractions of a second. 21-AUG-2003 17:25:30 is a valid value, but 21-AUG-2003 17:25:30.255 is not.The TIMESTAMP data type
10、 is an extension of the DATE data type which allows fractions of a second.For example, TIMESTAMP(3) allows 3 digits after the whole seconds, allowing values down to milliseconds to be stored.select systimestamp from dual;TIMESTAMP . WITH LOCAL TIME ZONEThink about the time value 17:30. Of course it
11、means “half past five in the afternoon”.But where in the world? Is it half past five New York City time, or Beijing time, or Istanbul time, or . ?In todays globalized organizations which operate in many different countries, it is important to know which time zone a date-time value refers to.TIMESTAM
12、P . WITH LOCAL TIME ZONETIMESTAMP WITH TIME ZONE stores a time zone value as a displacement from Universal Coordinated Time or UCT (previously known as Greenwich Mean Time or GMT).For example, a value of 21-AUG-03 08:00:00 5:00 means 8:00 am 5 hours behind UTC. This is US Eastern Standard Time (EST)
13、.TIMESTAMP WITH LOCAL TIME ZONE is the same, but with one difference:when this column is SELECTed in a SQL statement, the time is automatically converted to the selecting users time zone.TIMESTAMP . WITH LOCAL TIME ZONECREATE TABLE time_example(first_column TIMESTAMP WITH TIME ZONE,second_column TIM
14、ESTAMP WITH LOCAL TIME ZONE); INSERT INTO time_example (first_column, second_column) VALUES( TO_TIMESTAMP_TZ(15-11-2003 08:00:00 -5:00,DD-MM-YYYY HH24:MI:SS TZH:TZM),TO_TIMESTAMP_TZ(15-11-2003 08:00:00 -5:00,DD-MM-YYYY HH24:MI:SS TZH:TZM) );Both values are stored with a time displacement of5 hours (
15、EST).TIMESTAMP . WITH LOCAL TIME ZONEBut now we executes:SELECT * FROM time_example;Our time is 5 hours ahead of EST; when its 8am in NewYork City, its 1pm here.SELECT first_column-second_column FROM time_example;INTERVAL DATA TYPESThese store the elapsed time, or interval of time, between two date-
16、time values.INTERVAL YEAR TO MONTH stores a period of time measured in years and months.INTERVAL DAY TO SECOND stores a period of time measured in days, hours, minutes and seconds.The data type syntax is:INTERVAL YEAR(year_precision) TO MONTHyear_precision is the maximum number of digits in the YEAR
17、 element. The default value of year_precision is 2.This example shows an interval of 120 months,INTERVAL DATA TYPESCREATE TABLE time_example2(loan_duration INTERVAL YEAR(3) TO MONTH);INSERT INTO time_example2 (loan_duration)VALUES (INTERVAL 120 MONTH(3);SELECT TO_CHAR (to_date(26-09-2005,DD-MM-YYYY)
18、+loan_duration,dd-mon-yyyy)FROM time_example2;INTERVAL DAY TO SECONDUse this when you need a more precise difference between two date-time values.The data type syntax is:INTERVAL DAY(day_precision) TO SECOND (fractional_seconds_precision) day_precision is the maximum number of digits in the DAY datetime field.The default is 2.fractional_seconds_precision is the number of digits in the fractional part of the SECOND date-time field.The default is 6.INTERVAL DAY TO SECONDCREATE TABLE time_example3(day_dura
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 醫(yī)院信息管理系統(tǒng)應(yīng)用培訓(xùn)
- 企業(yè)員工安全培訓(xùn)教學(xué)設(shè)計(jì)與案例
- 小學(xué)數(shù)學(xué)乘法定律與小數(shù)運(yùn)算教案
- 人教版八年級(jí)英語(yǔ)上冊(cè)-Unit1-教案
- 通訊行業(yè)培訓(xùn)需求分析報(bào)告
- 幼兒園大班健康教案:這些食物更健康
- 社區(qū)衛(wèi)生清掃制度
- 活動(dòng)場(chǎng)所衛(wèi)生輪值制度
- 培訓(xùn)學(xué)校衛(wèi)生管理制度
- 寶馬展廳衛(wèi)生規(guī)章制度
- 新疆環(huán)保行業(yè)前景分析報(bào)告
- 2025~2026學(xué)年福建省泉州五中七年級(jí)上學(xué)期期中測(cè)試英語(yǔ)試卷
- 聯(lián)合辦公合同范本
- 2025年生物多樣性保護(hù)與生態(tài)修復(fù)項(xiàng)目可行性研究報(bào)告
- 2025年黑龍江省檢察院公益訴訟業(yè)務(wù)競(jìng)賽測(cè)試題及答案解析
- 一氧化碳中毒救治課件
- 廣東事業(yè)單位歷年考試真題及答案
- 《會(huì)計(jì)信息化工作規(guī)范》解讀(楊楊)
- 工程機(jī)械設(shè)備租賃服務(wù)方案投標(biāo)文件(技術(shù)方案)
- 高海拔地區(qū)GNSS大壩監(jiān)測(cè)技術(shù)研究
- 實(shí)施指南(2025)《DL-T 1630-2016氣體絕緣金屬封閉開關(guān)設(shè)備局部放電特高頻檢測(cè)技術(shù)規(guī)范》
評(píng)論
0/150
提交評(píng)論