oracle ocp exam questions 051 knowledge summary

Knowledge test sites summary

IZ0-051

 with check option 

In view created by the with check option, when do dml must meet the conditions where we can either insert or update or delete. Can not be ignored, but also to meet the constraint original data table.

create table A as SELECT * FROM B

A table can only receive not null B table, the other constraint can not be created

months_beetween()

months_between (to_date ( '2019-05-31', 'YYYY-MM-DD'), to_date ( '2019-05-01', 'YYYY-MM-DD')) large date after the date of first small> 0 , whereas <0.

intersect

The intersection of two tables when not ignore null values, if a table has a blank record, b table is also available records do intersect the intersection of the time will be displayed. Column names can not be the same, but the type and number must be the same.

Column Name Definition ""

Must "" contents will be displayed intact, rather than double quotation marks "in the definition of a column name" column names are automatically capitalized.

Examples: SELECT MONTH ms, AREA "Name" FROM mxq; ms column names are automatically capitalized, "Name" will be displayed as Name

Escape q '[Camera's category is Photo]'

. Escaped the original in the parentheses where square brackets ' []' can be changed to any one of the special symbols such as, but must appear in pairs , '\ \', '< >', '| |'.

distinct

Only appears at the beginning of the sql statement, and can only occur once.

NULL operational rule

Any numerical value arithmetic null = null.

 INTERVAL

A grammar

INTERVAL '123-1' YEAR (N) TO MONTH; N 2 by default, as the accuracy of 0-9;

SELECT INTERVAL '123-1' YEAR(3) TO MONTH FROM DUAL ;

Example 1

SELECT INTERVAL '123' YEAR(3)  FROM DUAL ;

If the error will be less than 3, the result is; + 123-00

Example 2

SELECT INTERVAL '123' MONTH FROM DUAL; result: 2 + 10-03 default so 10 years

SELECT INTERVAL '123' MONTH (3) FROM DUAL; result: 010-03 accuracy is + 3 010 is so

From the results of Examples 2 can be seen two precision and accuracy of the latter month year later are represented in the accuracy.

Syntax two

The INTERVAL '{Integer | Integer time_expr | time_expr}'
{{DAY | HOUR | MINUTE} [(leading_precision)]
| SECOND, [(leading_precision [, fractional_seconds_precision])]}
[the TO {DAY | HOUR | MINUTE | SECOND, [(fractional_seconds_precision) ]}]
{} is required, [] is the time to fill can be filled, | is or.

An example of a

select interval '5 23: 45: 30.457' day to second (2) from dual; results +05 23: 45: 30.46, leading_precision defaults to 2

select interval '5 23: 45: 30.457' day (3) to second (2) from dual; results +005 23: 45: 30.46, leading_precision 3

Examples of the dicarboxylic

select interval '5 23: 45: 30.457' day (3) to minute from dual; given interval of the invalid, "523: 45: 30.457" format not to minute

select interval '5 23:45' day (3) to minute from dual; the result is +005 23: 45: 00, DAY | HOUR | MINUTE behind unacceptable precision, careful look behind only the second grammatical accuracy fractional_seconds_precision;

to sum up

Behind 1.interval format should comply to the latter format, such as '523: 45: 30.457' has accurate to the second, not to minute.

2.DAY | HOUR | precision is behind MINUTE day precision, TO DAY | HOUR | MINUTE | SECOND behind only the SECOND can pick accuracy.

Clob blob long data type

clob largest 4g varchar2 (4000) on the use of more than four thousand clob

4g used to store binary blob largest object classes such as pictures, music and so on.

There are long and blob clob type can not group by and order by statements directly.

 Data type number, char, varchar2

number and length of char char can not write the default is 1, number not write the length of time you can store decimal places.

varchar2 length must be written, otherwise it will error

 Create a table name rules

You can not use the reserved word table name can not start with a number, can not have *.

Table Name 1-30 characters, with up to 1000.

Constraint constraint

It can be both a primary and foreign keys

check SYSDATE not be used directly. can to_date ( '2014-01-12', 'YYYY-MM-DD') of this type of date.

 .Nextval sequence and can not be directly used in the sequence .currval constraint.

Column-level constraints and table-level constraints

1. Directly behind the column is defined as a column-level constraint constraint,

2. After defining all the columns in the definition of constraints for the table level constraints

default and not null can only be column-level constraint

Mixing primary key or unique constraints can only be defined in the table level

CREATE TABLE WAREHOUSE (
WAREHOUSE_ID NUMBER(4),
ROOMNO NUMBER(10) CONSTRAINT R_ID CHECK(ROOMNO BETWEEN 101 AND 200), -------列级别
LOCATION VARCHAR2(25),
PROD_ID NUMBER(3),
CONSTRAINT WR_PR_PK PRIMARY KEY (WAREHOUSE_ID,PROD_ID),-----表级别
CONSTRAINT PROD_FK FOREIGN KEY (PROD_ID) REFERENCES PRODUCTS(PROD_ID)----表级别);

Multitable insert

INSERT ALL
INTO Sales_info VALUES (employee_id,week_id,sales_MON)
INTO Sales_info VALUES (employee_id,week_id,sales_TUE)
INTO Sales_info VALUES (employee_id,week_id,sales_WED)
INTO Sales_info VALUES (employee_id,week_id,sales_THUR)
INTO Sales_info VALUES (employee_id,week_id, sales_FRI)
SELECT EMPLOYEE_ID, week_id, sales_MON, sales_TUE,
sales_WED, sales_THUR,sales_FRI 
FROM Sales_source_data;

INSERT ALL
WHEN SAL>10000 THEN
INTO sal_history VALUES(EMPID,HIREDATE,SAL)
WHEN MGR>200 THEN
INTO mgr_history VALUES(EMPID,MGR,SYSDATE)
SELECT employee_id EMPID, hire_date HIREDATE, salary SAL, manager_id MGR
FROM employees WHERE employee_id > 200;

sequence
 
The default cache 20 is then turned off If a database sequence stored in the cache 20 will not be available after the restart normal database directly from the start value of 21.
 
primary key和UNIQUE KEY
 
Add constraint is automatically increased when the index.
 
index
On the composite index columns you can create a separate index, a separate index has been listed, not in the creation of a separate index.
view the index
Single view and complex view can use an index based on the table.
A fixed table indexed by the hint
create view mxq select * from test_1 inner join test_2 on test_1 .id=test_2 .id;
语法 /*+(view.table_name index_name) (view.table_name index_name)*/
select/*+index(mxq .test_1  index_test_1 _id )  (mxq .test_2  index_test_2 _id ) */ * from mxq where id>200;
If you create a view when using a table aliases
The syntax was /*+(view.table_alias_name index_name) /
sequence
Cycle sequence defined as when, after reaching a maximum value if, starting at 1 cycle.
order by
order by clause in the column does not have to appear in the select.
order by the time the largest null value.
It may be null and null First Last controlled null value.
desc descending null, 5,4,3,2,1
asc ascending 1,2,3,4,5, null
ascending order by default.
Function instr
 instr(1,2,3,4)
Variable 1, to search for the string
Variable 2, the character string to be searched
Variable 3, when the time is a positive number, the start position is negative when the time is the end position, are from left to right to start the search characters.
Variable 4, to search for the number of characters appear.
Replace function
It can be replace with select replace (to_date ( '2019-05-31', 'YYYY-MM-DD'), '-') from dual;
Date type may be used for the conversion.
Implicit conversion
vachar 2 and can be converted to char Number;
vachar 2 and char can be converted to a date format type but must correspond; date type corresponding to the default database format.
to_char (date)
to_char(日期,‘yyyy-mm-dd’);
SELECT TO_CHAR(TO_DATE('   11-oct-2007'), 'fmDDthsp"of" Month, Year') FROM DUAL;
Showing results ELEVENTHof October, Two Thousand Seven
fm, removing spaces
Dd, is capitalized at the beginning of the rest lowercase, if DD, then all uppercase
th, th suffix
sp, digital spelling.
NLS_DATE_LANGUAGEE;
NLS_DATE_FORMAT;
nvl function
nvl (exp1, exp2) Expression 1 and type 2 expression must be the same, otherwise it will be converted into exp2 exp1.
test
select nvl (1, 'aa') from dual; being given an invalid number, aa converted into digital numbers must be valid;
select nvl ( 'aa', 1 ) from dual;. is not given, because the conversion into an invisible character format successfully
nvl2 function
nvl2 (exp1, exp2, exp3), 1 display 3 is empty, otherwise display 2.
exp3, exp2 implicitly converted to data type, it is not required if exp3 is empty.
exp1 may be of any type, exp2 3, and is in addition to the type of long
example
SELECT inv_no, NVL2 (inv_date, 'Pending', 'Incomplete') FROM invoice; obviously be consistent and parameter 2 as the parameter data type 3;
Special case
SELECT inv_no, NVL2 (inv_date, sysdate-inv_date, sysdate) FROM invoice; Ann reason that return is numeric parameter 2, parameter 3 is the date format, but can be converted successfully, dates - not simply type the numeric date obtained
SELECT inv_no, NVL2 (inv_date, 1, sysdate) FROM invoice; such a conversion is given
NULLIF
NULLIF(EXP1,EXP2)
1 and 2 data type parameter to be consistent,
1 and 2 if the same, then returns NULL, if not identical, to a return value parameter.
COALESCE
COALESCE(exp1,exp2,.......)   n>=2
Data type needs to be consistent or may be converted to the same implicit
Returns the first value is not null.
decode
decode default return value, and a need to return a value of type
Aggregate function
When no packet can be omitted group by
example
select sum (SHANGJIN) from XZHDX; This
select max (t.SHANGJIN), zhenying from XZHDX t; so you must add the group by otherwise incorrect report
 count
count (*) and duplicate values ​​including a null value
count (id) not including a null value
count (distinct (id)) does not include the null value and repetition value
Aggregate function
select can not be described, be used directly in the having clause of
select AA from XZHDX t  having sum( SHANGJIN)>2 group by  AA.
SHANGJIN need not be present can be used directly in the having clause in the select statement
SELECT SUM(SHANGJIN), ZHENYING
  FROM XZHDX
 WHERE END_DATE - ST_DATE > 30
 GROUP BY ZHENYING;
A first data packet and then
the SELECT the SUM (Shangjin), ZHENYING, MIN - (END_DATE ST_DATE)
  the FROM XZHDX
 the GROUP BY ZHENYING
the HAVING MIN (END_DATE - ST_DATE)> 30;
first packet is then calculated conditions having
 
And using natural link
Links are the same fields as the table name, if different field types, you can query implicit conversion is successful, not implicit conversion, the query is unsuccessful.
Subqueries
Subquery nesting level maximum is 255.
group by 和order by
 group by the back can only take the column name, order by the back can take alias
 
 
 
 
 
 

Guess you like

Origin www.cnblogs.com/throughRiversandLake/p/10894153.html