Connect to the database through a client and perform relevant operations
I. Access Method: SQL Plus; PL SQL Developer
Connect to the database using the system account. The link identifier is orcl.
1. Access the database through SQL Plus
Two Methods: web Access http: // localhost: 5560/isqlplus/
Enter the command line window through the menu
2. Open PL/SQL Developer, FILE-> new --> SQL Window
Ii. Create an object
Create a user and a table. For example, a user account with the school username and password:
Create user school
Identified by school;
Assign school users the permissions to connect to the database and create objects in their own mode.
Grant create session, resource
To school;
Create a table
Common Oracle field types include:
CHAR fixed-length string
VARCHAR2 variable-length string
NUMBER (M, N) numeric type M is the total length of digits, N is the length of decimal places
DATE type
Example:
Create table "SCHOOL ". "STUDENT" ("SNO" VARCHAR2 (9), "SNAME" VARCHAR2 (20), "SSEX" VARCHAR2 (2), "SAGE" NUMBER, "SDEPT" VARCHAR2 (20), primary key ("SNO") VALIDATE)
Create table "SCHOOL ". "COURSE" ("CNO" VARCHAR2 (4), "CNAME" VARCHAR2 (40), "CPNO" VARCHAR2 (4), "CCREDIT" NUMBER, primary key ("CNO ") VALIDATE, foreign key ("CPNO") REFERENCES "SCHOOL ". "COURSE" ("CNO") VALIDATE)
Create table "SCHOOL ". "SC" ("SNO" VARCHAR2 (9), "CNO" VARCHAR2 (4), "GRADE" NUMBER, PRIMARY KEY ("SNO", "CNO") VALIDATE, foreign key ("SNO") REFERENCES "SCHOOL ". "STUDENT" ("SNO") VALIDATE, foreign key ("CNO") REFERENCES "SCHOOL ". "COURSE" ("CNO") VALIDATE)
Constraint status
Enable validate: Default. Both the New and Old data meet the constraints.
Enable novalidate: the old data may not meet the requirements. Check that the newly inserted data must meet the requirements.
Disable validate: it is not allowed to perform any DML operations on the table. It is mainly used in partitioned tables. For Primary keys and unique conventions, the corresponding unique indexes are deleted, but the constraint status is available.
Disable novalidate data does not meet the constraints. For Primary keys and unique conventions, the corresponding unique index is deleted,
Iii. query related commands. The following is an example of SQL Plus execution.
1) User
View the default tablespace of the current user
SQL> select username, default_tablespace from user_users;
View the role of the current user
SQL> select * from user_role_privs;
View the system and table-level permissions of the current user
SQL> select * from user_sys_privs;
SQL> select * from user_tab_privs;
Displays the permissions of the current session.
SQL> select * from session_privs;
Displays the system permissions of a specified user.
SQL> select * from dba_sys_privs where grantee = 'game ';
2) Table
View All tables under a user
SQL> select * from user_tables;
View tables whose names contain log characters
SQL> select object_name, object_id from user_objects
Where instr (object_name, 'log')> 0;
View the creation time of a table
SQL> select object_name, created from user_objects where object_name = upper ('& table_name ');
View the size of a table
SQL> select sum (bytes)/(1024*1024) as "size (M)" from user_segments
Where segment_name = upper ('& table_name ');
View the table in the ORACLE memory Partition
SQL> select table_name, cache from user_tables where instr (cache, 'y')> 0;
3) Index
View the number and category of Indexes
SQL> select index_name, index_type, table_name from user_indexes order by table_name;
View indexed fields
SQL> select * from user_ind_columns where index_name = upper ('& index_name ');
View index size
SQL> select sum (bytes)/(1024*1024) as "size (M)" from user_segments
Where segment_name = upper ('& index_name ');
4) serial number
View the serial number. last_number is the current value.
SQL> select * from user_sequences;
5) view
View view name
SQL> select view_name from user_views;
View the select statement for creating a view
SQL> set view_name, text_length from user_views;
SQL> set long 2000; Description: You can set the size of set long based on the text_length value of the view.
SQL> select text from user_views where view_name = upper ('& view_name ');
6) Synonyms
View synonym name
SQL> select * from user_synonyms;
7) Constraints
View the constraints of a table
SQL> select constraint_name, constraint_type, search_condition, r_constraint_name
From user_constraints where table_name = upper ('& table_name ');
SQL> select c. constraint_name, c. constraint_type, cc. column_name
From user_constraints c, user_cons_columns cc
Where c. owner = upper ('& table_owner') and c. table_name = upper ('& table_name ')
And c. owner = cc. owner and c. constraint_name = cc. constraint_name
Order by cc. position;
8) storage functions and processes
View the status of functions and processes
SQL> select object_name, status from user_objects where object_type = 'function ';
SQL> select object_name, status from user_objects where object_type = 'Procedure ';
View the source code of functions and processes
SQL> select text from all_source where owner = user and name = upper ('& plsql_name ');