Oracle syntax and oracle syntax

Source: Internet
Author: User

Oracle syntax and oracle syntax

Top number

Select * FROM Table Where ROWNUM <= 2 order by AgeUnitNo desc

ROWNUM <= 2 indicates that two pieces of data are queried.

Date

To_date () indicates the data that can be recognized by Oracle

Update talbe set A1 = to_date ('"+ model. Tstamp. ToString () +"', 'yyyy-MM-DD HH24: MI: ss ');

Auto-increment ID

1. Oracle does not have the auto-increment attribute. Therefore, you need to customize a SEQUENCE.

Create sequence emp_sequence
Increment by 1 -- add several
Start with 1 -- count from 1
NOMAXVALUE -- do not set the maximum value
NOCYCLE -- always accumulate without repeating
NOCACHE -- do not create a buffer

2. Create a trigger

Create or replace trigger emp BEFORE
Insert ON Table FOR EACH ROW
Begin
Select emp_Sequence.nextval into: New. TableID from Dual;
End;

To be supplemented


Basic oracle syntax

Query statement-select * from table;
Select * from table where Condition 1 = value and condition 2 = value;
Select * from table where id in (select id from table); two table associations
Select a. a, B. B, c. c from table1 a, table2 B, table3 c where a. id1 = B. id2;
Insert statement-insert into table (Field 1, Field 2, Field 3 ,......)
Values (value 1, value 2, value 3 ,......);
Update statement-update table name set value where = id = 1;

Add column statement-alter table name
Add (column name 1 Type 1, column name 2 type 2, column name 3 type 3 ,......);

Query 20 random records-select * from (select * from emp order by dbms_random.value) where rownum <= 10;
Alter column type-alter table name
Modify (column name 1 Type 1, column name 2 type 2, column name 3 type 3 ,......);
Delete column statement-alter table name
Drop column name s;
Display query time-set timing on;

Delete table statement-deltet table name;

Clear table data-truncate table name;

Alter table emp rename column comm TO newa;

Set query (no duplicates): select * from table_name union
Select * from table_name;
Set query (repeated): select * from table_name union all
Select * from table_name;
Query the difference set: select * from table_name minus
Select * from table_name;

--------------------------------------------------------------------------------
Run the script-start d: \ file name. SQL;

Edit script-edit d: \ file name. SQL;

Save As script-spool d: \ file. SQL;
Select * from emp;
Spool off;

Page display-set pagesize page number;

Display the number of rows-set linesize the number of rows;

Create user-create user username identified by password (requires SYS/SYSTEM permission to create a user)
Grant permissions-grant resource to user name; (Table creation permission)
Grant query permission-grant select on emp to user name;
Grant the modification permission-grant update on emp to the user name;
Grant all access permissions-grant all on emp to user name;
----------------------------------------------------- ...... The remaining full text>

| What is represented in Oracle syntax?

Connector. For example, select 'this is '| 'connector' from dual
The result is as follows:
Is to splice two pieces of data.
Hope to adopt
 

Related Article

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.