Getting Started with Oracle

Source: Internet
Author: User

--Create User
Create user QJT identified by 1234

--Permissions
Grant Connect to QJT

Grant resource to QJT

--Build a table
CREATE TABLE UserInfo
(ID number primary key NOT NULL)

--Query with several tables
SELECT * from All_tables where owner= ' QJT '

--Pseudo-column
Select Id,rowid,rownum from UserInfo

--The third record of querying natural sort
SELECT * FROM
(
Select Ename,rownum rn from EMP
) Temp
where rn=3

--Query teachers ' information on the fifth salary ranking in the Teacher's table
SELECT * FROM
(
Select RowNum rn,ta.* from
(
Select Ename,sal,rownum rn from emp ORDER BY sal Desc
) Ta where rownum<6
) Where rn>=5

--pagination
--Method One
SELECT * FROM
(
Select Temp.*,rownum rn from
(
Select emp.* from emp
ORDER BY Sal Desc
) Temp
where rownum<=9
)
where rn>=5
--Method Two
SELECT * FROM
(
SELECT Temp.*,rownum RN from
(
SELECT * from emp e ORDER by E.sal DESC
) Temp
) Temp2
WHERE Temp2.rn between 5 and 9

--Authorization
Grant SELECT on HAPPYY2165. STUDENT to Scott

--Unlock User
Alter user HR account unlock

--Revoke permissions
Revoke select on QJT from SCOTT

--Through role control
--Custom roles
CREATE role role_testy2165

--Bind the query table's permissions and roles
Grant SELECT on Y2165. " Student "to role_testy2165

--Assigning roles to users
GRANT role_testy2165 to SCOTT


--distinct querying for data that is not duplicated
Select DISTINCT "Stuname", "stuage" from STUDENT;

--Create a backup table of student tables
CREATE TABLE Studentbak
As
SELECT * FROM STUDENT

--Delete the same column, preserving the highest ID
DELETE from Student
WHERE "Stuno" Not In (select "MAX" ("Stuno") from student GROUP by "Stuname", "Stuage")


SELECT from dual

SELECT ' You ' | | ' Good ' from dual

SELECT ' operation result ' | | ' 5 ' from dual

--Intersection
SELECT Deptno from Dept
INTERSECT
SELECT DISTINCT Deptno from emp

--Reduced set
SELECT Deptno from Dept
Minus
SELECT DISTINCT Deptno from emp

Getting Started with Oracle

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.