Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Thursday, 6 December 2018

Datatypes

Date TypeEach value manipulated by Oracle Database has a data type. The data type of a value associates a fixed set of properties with the value. Data type is associated with a specific storage format, constraints, and a valid range of values

There are Two Types:  1. Scalar Datatypes
                                     2. Composite Datatypes


Scalar Datatypes:


PL/SQL Scalar Data Types and Subtypes
Date Type
Description
Numeric
Numeric values on which arithmetic operations are performed.
Character
Alphanumeric values that represent single characters or strings of characters.
Boolean
Logical values on which logical operations are performed.
Datetime
Dates and times.

PL/SQL Numeric Data Types and Subtypes
Data Type
Description
PLS_INTEGER
Signed integer in range -2,147,483,648 through 2,147,483,647, represented in 32 bits
BINARY_INTEGER
Signed integer in range -2,147,483,648 through 2,147,483,647, represented in 32 bits
BINARY_FLOAT
Single-precision IEEE 754-format floating-point number
BINARY_DOUBLE
Double-precision IEEE 754-format floating-point number
NUMBER(prec, scale)
Fixed-point or floating-point number with absolute value in range 1E-130 to (but not including) 1.0E126. A NUMBER variable can also represent 0.
DEC(prec, scale)
ANSI specific fixed-point type with maximum precision of 38 decimal digits.
DECIMAL(prec, scale)
IBM specific fixed-point type with maximum precision of 38 decimal digits.
NUMERIC(pre, secale)
Floating type with maximum precision of 38 decimal digits.
DOUBLE PRECISION
ANSI specific floating-point type with maximum precision of 126 binary digits (approximately 38 decimal digits)
FLOAT
ANSI and IBM specific floating-point type with maximum precision of 126 binary digits (approximately 38 decimal digits)
INT
ANSI specific integer type with maximum precision of 38 decimal digits
INTEGER
ANSI and IBM specific integer type with maximum precision of 38 decimal digits
SMALLINT
ANSI and IBM specific integer type with maximum precision of 38 decimal digits
REAL
Floating-point type with maximum precision of 63 binary digits (approximately 18 decimal digits)
PL/SQL Character Data Types and Subtypes
Data Type
Description
CHAR
Fixed-length character string with maximum size of 32,767 bytes
VARCHAR2
Variable-length character string with maximum size of 32,767 bytes
RAW
Variable-length binary or byte string with maximum size of 32,767 bytes, not interpreted by PL/SQL
NCHAR
Fixed-length national character string with maximum size of 32,767 bytes
NVARCHAR2
Variable-length national character string with maximum size of 32,767 bytes
LONG
Variable-length character string with maximum size of 32,760 bytes
LONG RAW
Variable-length binary or byte string with maximum size of 32,760 bytes, not interpreted by PL/SQL
ROWID
Physical row identifier, the address of a row in an ordinary table
UROWID
Universal row identifier (physical, logical, or foreign row identifier)
PL/SQL Datetime and Interval Types
Field Name
Valid Datetime Values
Valid Interval Values
YEAR
-4712 to 9999 (excluding year 0)
Any nonzero integer
MONTH
01 to 12
0 to 11
DAY
01 to 31 (limited by the values of MONTH and YEAR, according to the rules of the calendar for the locale)
Any nonzero integer
HOUR
00 to 23
0 to 23
MINUTE
00 to 59
0 to 59
SECOND
00 to 59.9(n), where 9(n) is the precision of time fractional seconds
0 to 59.9(n), where 9(n) is the precision of interval fractional seconds
TIMEZONE_HOUR
-12 to 14 (range accommodates daylight savings time changes)
Not applicable
TIMEZONE_MINUTE
00 to 59
Not applicable
TIMEZONE_REGION
Found in the dynamic performance view V$TIMEZONE_NAMES
Not applicable
TIMEZONE_ABBR
Found in the dynamic performance view V$TIMEZONE_NAMES
Not

PL/SQL Large Object (LOB) Data Types
Data Type
Description
Size
BFILE
Used to store large binary objects in operating system files outside the database.
System-dependent. Cannot exceed 4 gigabytes (GB).
BLOB
Used to store large binary objects in the database.
8 to 128 terabytes (TB)
CLOB
Used to store large blocks of character data in the database.
8 to 128 TB
NCLOB
Used to store large blocks of NCHAR data in the database.
8 to 128 TB



Composite Datatypes:
             There are two types 1. Records
                                              2. Collections
                                                        i. Index-by tables or Associative array
                                                                             ii. Nested table
                                                                             iii. Variable-size array or Varray 

SQL Functions

o    ROLLUP,
o    CUBE,
o    GROUP BY,
o    GROUPING,
o    GROUPING SETS

DATA TYPES

SUB QUERIES

TABLE

USER, PRIVILEGE, ROLE

DATA DICTIONARIES

  • ALL views have information about all accessible data.
  • USER views have information about your own data.
  • DBA views have database-wide information.
  • V$ views are dynamic performance views.

Oracle function list in alphabetical order



Name
Description
ABS(x)
absolute value of x
ACOS(n)
Arccosine
ADD_MONTHS(d, n)
Date d plus n months
Gives the ASCII value of the first character of a string.
Converts x to an ASCII string, where x may be a string in any character set.
ASIN(n)
Arcsine of n
ATAN(n)
Arctangent of n
ATAN2(x,y)
Returns the arctangent of x and y.
Calculates the average
Converts a binary number x to a NUMBER.
BITAND(x,y)
a bitwise AND on x and y.
Converts x to a compatible type specified in type.
Returns the ceiling value (next highest integer above a number).
Converts x to a ROWID.
CHR(n)
Character with ASCII value n
COALESCE(a, b, ...)
The first not NULL argument (and NULL if all arguments are NULL)
Converts x to a Unicode string in normalized form.
Concatenates two strings
Converts x from source_char_set to dest_char_set.
COS(n)
Cosine of n (n expressed in radians)
COSH(n)
Hyperbolic cosine of n
Returns the number of rows returned by a query involving x
Returns rows containing a subtotal for all combinations of columns
Returns the position of a value relative to a group.
returns the current date in the local time zone in the database session
Returns a TIMESTAMP WITH TIME ZONE for the session
Returns the time zone for the database
Use it as if then else statement
Decomposes the string into the same character set as x and convert x to a Unicode string.
Rank the rows and does not skip ties
Returns e raised to a value.
Extracts and returns the year, month, day, hour, minute, second, or time zone from x.
EXTRACT(c FROM d)
Extract date/time component c from expression d
FIRSTFirst
gets the first values in an ordered group.
Gets the first rows in a window.
Returns the floor value (next lowest integer below number).
FROM_TZ(x, time_zone)
Merges xand time_zone into one value.
GREATEST(a, b, ...)
Greatest value of the function arguments
Removes duplicate rows returned by a ROLLUP or CUBE.
Deals with NULL value for ROLLUP and CUBE
Returns the decimal equivalent of the GROUPING bit vector.
Converts the character x containing hexadecimal digits (base-16) to a binary number (RAW).
Rank and Distribution Functions
Changes the first letter of a string or series of words into uppercase.
Returns the beginning location of a pattern in a given string.
gets the last values in an ordered group.
Last day of the month containing date d
Gets the last rows in a window.
LEAST(a, b, ...)
Least value of the function arguments
Returns the length of a string.
LN(n),LOG(m,n)
Natural logarithm, and logarithm base m
Returns a TIMESTAMP for the session.
Converts every letter of a string to lowercase.
Adds a specified set of characters to the left of the original string.
Removes a set of characters from the left of a string.
Returns the maximum value
Returns the median value
Returns the minimum value
Returns The Remainder Of N/M Where Both N And M Are Integers.
Months between dates d and e
NEW_TIME(x,time_zone1,time_zone2)
Converts x from time_zone1 to time_zone2
NEW_TIME(d, z1, z2)
Convert date/time d from time zone z1 to z2
NEXT_DAY(d, weekday)
The first weekday (mon, tue, etc.) after d
Groups data by putting data into a number of percentile groups
NULLIF(a, b)
NULL if a = b; otherwise a
Converts the number x to an INTERVAL DAY TO SECOND.
Converts number x to INTERVAL DAY TO SECOND.
Converts the number x to an INTERVAL YEAR TO MONTH.
Converts number x to INTERVAL YEAR TO MONTH.
Returns value if x is null; otherwise x is returned.
Returns value1 if x is not null; otherwise value2 is returned.
Separate data groups and perform calculation within that group
Returns the percent rank of a value relative to a group.
Checks the percent rank values in each group
Checks the cumulative distribution values
Returns value raised to some exponential power.
Returns the rank of items in a group and leaves a gap for a tie.
Ratio to report
Converts the binary number (RAW) x to a VARCHAR2string in equivalent hexadecimal number.
Converts the binary number (RAW) x to an NVARCHAR2string in the equivalent hexadecimal number.
Returns the number of times the pattern is found.
Returns the location of a pattern in a given string and supports the regular expression.
Searches x for the regular expression defined in the pattern parameter.
Replaces string with the regular expression matching supports
Returns the substring with the regular expression matching supports
REGR_AVGX(y, x)
Returns the average of x after eliminating x and y pairs
REGR_AVGY(y, x)
Returns the average of y after eliminating x and y pairs
REGR_COUNT(y, x)
Returns the number of non-null number pairs that are used to fit the regression line
Returns the intercept on the y-axis of the regression line
REGR_R2(y, x)
Returns the coefficient of determination of the regression line
REGR_SLOPE(y, x)
Returns the slope of the regression line
REGR_SXX(y, x)
Returns REG_COUNT (y, x) * VAR_POP(x)
REGR_SXY(y, x)
Returns REG_COUNT (y, x) * COVAR_POP(y, x)
REGR_SYY(y, x)
Returns REG_COUNT (y, x) * VAR_POP (y)
REMAINDER(n1, n2)
Identifies the multiple of n2 that is nearest to n1, and returns the difference between those two values.
Does the string replacement
Returns a row containing a subtotal
ROUND(d[, fmt])
d rounded on fmt (the default for fmt is midnight)
Returns the number rounded to nearest value, adjusts precision.
row number for ranking
Converts the ROWID x to a VARCHAR2 string.
Converts the ROWID x to an NVARCHAR2 string.
pseudo-column and is calculated as rows are retrieved
Adds a specified set of characters to the right of the original string.
Removes a set of characters from the right of a string.
Returns the database session time zone
Returns 1 If The Argument Is Positive; -1 If The Argument Is Negative; And 0 If The Argument Is Negative.
SIN(n)
Sine of n (n expressed in radians)
SINH(n)
Hyperbolic sine of n
Converts a string to a code value based on similar sounds.
Sqrt(x)
Square Root Of x
Returns the standard deviation
Concatenates two strings.
Retrieves a portion.
Returns the sum
Converts the TIMESTAMP WITH TIMEZONE x to a TIMESTAMP in UTC.
Extracts the UTC from a datetime value.
Returns the current operating system date from database server
Returns a TIMESTAMP WITH TIME ZONE for the database.
TAN(n)
Tangent of n (n expressed in radians)
TANH(n)
Hyperbolic tangent of n
Converts x to a BINARY_DOUBLE.
Converts x to a BINARY_FLOAT.
Converts x to a binary large object (BLOB).
Converts number and date value to string and format
Converts x to a character large object (CLOB). A CLOBis used to store large amounts of character data.
Converts string to date value
Converts the string x to an INTERVAL DAY TO SECOND.
Converts string x to INTERVAL DAY TO SECOND.
Converts the single-byte characters in x to the corresponding multi-byte characters.
Converts x in the database character set to an NVARCHAR2 string.
Converts x to a large object NCLOB.
Converts x to a NUMBER.
Converts the multi-byte characters in x to the corresponding single-byte characters.
Converts the string x to a TIMESTAMP.
TO_TIMESTAMP(x, [format])
Converts the string x to a TIMESTAMP.
Converts the string xto a TIMESTAMP WITH TIME ZONE.
TO_TIMESTAMP_TZ(x, [format])
Converts the string x to a TIMESTAMP WITH TIMEZONE.
Converts the string x to an INTERVAL YEAR TO MONTH.
Converts string x to INTERVAL YEAR TO MONTH.
Converts all occurrences of from_string in x to to_string.
Replaces a string character by character.
Removes a set of characters from both sides.
TRUNC(d[, fmt])
d truncated on fmt (the default for fmt is midnight)
Returns the truncated value (removes decimal part of a number, precision adjustable).
TZ_OFFSET(time_zone)
Returns the offset for time_zone in hours and minutes
Converts the characters in x to an NCHAR character.
Converts every letter to uppercase.
Returns the variance
Returns the storage size.