Presentation is loading. Please wait.

Presentation is loading. Please wait.

Overview Classes of datatypes available in Oracle 10g – Character – Numeric – Long, Raw – Dates/Times – Large Objects (LOBs) – ROWID – Specialized 1.

Similar presentations

Presentation on theme: "Overview Classes of datatypes available in Oracle 10g – Character – Numeric – Long, Raw – Dates/Times – Large Objects (LOBs) – ROWID – Specialized 1."— Presentation transcript:

1 Overview Classes of datatypes available in Oracle 10g – Character – Numeric – Long, Raw – Dates/Times – Large Objects (LOBs) – ROWID – Specialized 1

2 Usage of Fonts Normal text SQL SYNTAX or ORACLE FUNCTIONS datatype or function parameter datatype or function optional parameter 2

3 Character Datatypes 4 Datatypes – CHAR and NCHAR Fixed-length character literals NCHAR used to represent Unicode characters (UTF8) Store up to 2,000 bytes – VARCHAR2 and NVARCHAR2 Variable-length character literals Store up to 4,000 bytes – VARCHAR DON’T USE!! But, it is synonymous with the VARCHAR2 datatype Shame on you if you use this datatype, Oracle may change this datatype to use different comparison semantics in the future – LONG (deprecated) Store up to (2 gig -1) of char data 3

4 Character Datatype Declarations CHAR( size,{BYTE,CHAR ;DEFAULT=BYTE} ) VARCHAR2( size,{BYTE,CHAR ;DEFAULT=BYTE} ) NCHAR( size ) NVCHAR2( size ) Size can also be specified globally in NLS_LENGTH_SEMANTICS 4

5 Numeric Datatypes 3 Datatypes – NUMBER Fixed or floating point numbers 38 decimal digits of precision Represent from 1x10 -130 to 9.99 x 10 125 Variable storage – 1 to 22 bytes per entry – BINARY_FLOAT Stores floats in 32-bit IEEE 754 format – BINARY_DOUBLE Stores floats in 64-bit IEEE 754 format BINARY_FLOAT and BINARY_DOUBLE advantages – Usually faster computations than NUMBER operations – Use less space to hold data IEEE 754 datatype disadvantages – Fixed size may not be optimal use of space 5

6 Numeric Datatype Declarations NUMBER( precision,size ) 1 <= precision <= 37 -84 <= size <= 127 BINARY_FLOAT BINARY_DOUBLE 6

7 Numeric Operators and Functions Operators Functions – TO_BINARY_DOUBLE – Convert float or decimal to double – TO_BINARY_FLOAT – Convert double or decimal to float – TO_CHAR – Convert float or double to decimal – TO_NUMBER – Convert a float, double or decimal to a number –Addition –Multiplication –Remainder (modulus) –Subtraction –Division –Square Root –Equality 7

8 Time / Date Data Datatypes – DATE Stored as {century, year, month, day, hour, minute, second} – TIMESTAMP Same as DATE, but with fractional seconds Specify the number of seconds of precision, up to 9 digits TIMESTAMP WITH TIME ZONE – Stores TIMESTAMP with displacement between local and UTC time TIMESTAMP WITH LOCAL TIME ZONE – Stores TIMESTAMP but time is normalized to time of database upon entry. Query results return time relative to user – INTERVAL YEAR( precision )TO MONTH – INTERVAL MONTH( precision )TO SECOND 8

9 Date / Time Operators and Functions Operators – Addition, subtraction, equality Functions – ANSI Literal – ‘2009-09-16’ – TO_DATE(‘09-SEP-16 16:00’, ‘YY-MON-DD HH24:MI’) – SYSDATE – System Date (current time) – TRUNC (date) – Truncates sets time portion to midnight – INTERVAL YEAR [precision] TO MONTH – INTERVAL DAY TO SECOND 9

10 RAW and LONG RAW Datatypes Intended for binary data or byte strings not interpreted by Oracle Database Intended to hold binary data such as graphics, documents, etc. Oracle recommends converting these types to LOBs 10

11 Large Objects About – LOBs are used to store binary files – Query results including LOBs returns LOB locator Datatypes – CLOB and NCLOB Store up to (4 gig -1) * ( DMBS_LOB.GETCHUNCKSIZE ) of char data – BLOB – Binary Large Object Store up to (4 gig -1) of data – BFILE – Binary File Store up to 4 gigabytes of data Stored in a separate file on the server Administrator responsible that the files exist and can be accessed 11

12 ROWID Datatype Row addresses in Oracle Access row addresses by querying ROWID Extended rowids – Supports partitioned tables and indexes without ambiguity 12

13 Specialized Datatypes Other types of data that can be represented – Geographic – Multimedia – Searchable Text – XML – Dynamically Typed Data – ANSI/ISO, DB2 and SQL/DS Data 13

14 Geographic Datatype MDSYS.SDO_GEOMETRY – Must have installed Oracle Spatial – Object created using CREATE TYPE SDO_GEOMETRY AS OBJECT ( SDO_GTYPE NUMBER, SDO_SRID NUMBER, SDO_POINT SDO_POINT_TYPE, SDO_ELEM_INFO SDO_ELEM_INFO_ARRAY, SDO_ORDINATES SDO_ORDINATE_ARRAY); SDO_GTYPE – reference to type of point (line, curve, polygon, etc) SDO_SRID – reference for the spatial coordinate system SDO_POINT – (x,y,z) coordinate of point SDO_ELEM_INFO – SDO_ORDINATES – lkj 14

15 Regular Expressions Overview Regular expressions are a language for pattern matching within text (string data) Useful when you want to find like strings or to extract information from strings Portable-ish – syntax can be used across applications, though some applications use more a more feature rich syntax than others Syntax is interpreted through a Regex Engine – DFA – Very fast, tends to use more memory, uses longest leftmost matching – NFA – Uses backtracking, exhaustively searches all permutations of the regex 15

16 Regex Syntax Basics SyntaxNameExampleMatches.Any CharacterO.amaOsama, Obama, Omama +One or more charactersBe+rBer, Beer, Beeeeeeeeeeeeeer ?Zero or OneStuff?Stuf, Stuff *Zero or MoreFoo*Fo, Foo, Fooooooooooooooooo |Alternationcat|batcat, bat {m}Exact CountClas{2}Class {m,}At leastSQ{1,}LSQL, SQQQQQQQQL {m,n}In betweenAp{1,3}leAple, Apple, Appple (…)Grouping, Sub-expression(fa|fi)tfat, fit [...]Character set[bc]atbat, cat [^...]Not in character set[^bc]atfat, hat, ^Beginning of line^TheThe quick brown fox, The lazy dog $End of lines$Sleeps, sleeps, eats \dAny digit\d\d10, 20, 99 \wAny word character\w\w\wwww, w_w, 222 \sAny space character\stab, newline, space, carriage return 16

17 Regex Functions REGEXP_LIKE( columnName,pattern ) – Used in a WHERE clause to search for a pattern REGEXP_REPLACE( string,pattern,repl,pos,occ,m_param ) – Replaces a matched pattern with a specified string REGEXP_INSTR( string,pattern,pos,occ,ret,m_param ) – Searches for an instance of a pattern and returns the position in the string where that pattern is found REGEXP_SUBSTR( string,pattern,pos,occ,m_param) – Returns a substring matching the regex pattern specified 17

18 References Oracle 10g Application Developer’s Guide Oracle 10g Call Interface Programmer’s Guide Oracle 10g SQL Reference Oracle 10g Spatial User’s Guide and Reference Mastering Regular Expressions by Jeffrey Friedl Wikipedia – IEEE 754 18

Download ppt "Overview Classes of datatypes available in Oracle 10g – Character – Numeric – Long, Raw – Dates/Times – Large Objects (LOBs) – ROWID – Specialized 1."

Similar presentations

Ads by Google