1.create user username identified by password;//username and password Oracle, Oracle
2.grant CONNECT,RESOURCE,DBA to username;//authorized Grant CONNECT,RESOURCE,DBA,SYSDBA to username;
3.connect username/password//entry.
4.select table_name,column_name from User_tab_columns where table_name= ' table_name ';//query table name, field name, and so on. The last table_name to be capitalized.
5. How do I execute a script sql file? Sql> @PATH/filename.sql;
7. Query all tables under User SELECT DISTINCT table_name from User_tab_columns; = = = Only one list name is displayed.
8. How do I search for the top N records?
SELECT * FROM TableName where rownum<n;--is sufficient. (--marks used for annotations)
9. Find all tables under User: SELECT * from Tab; --Query all tables and views under the User (Show table name Tname, type tabname and Clusterid)
2. Show current Connected user
Sql> show user– cannot be used in SQL Windows only in command Commands window.
3. See which users the system has
Sql> select * from All_users;
4. Create a new user and authorize
Sql> create User a identified by A; (default is built under system table space)
Sql> Grant Connect,resource to A;
5. Connect to a new user
Sql> Conn a/a– or connect a/a
6. Querying all objects under the current user
Sql> select * from tab; --table or view
7. Establish the first table
Sql> CREATE Table A (a number);
8. Query table structure
Sql> desc A
9. Insert a new record
Sql> INSERT into a values (1);
10. Inquiry record
Sql> select * from A;
11. Change record
sql> update a set a=2;
12. Delete Records
Sql> Delete from A;
13. Rollback
Sql> roll;
sql> rollback;
14. Submit
Sql> commit;
SELECT * FROM
(select T.*,dense_rank () over (order by Cardkind) rank from Cardkind t)
where rank = 2;
46. How do I add a carriage return to a string?
Select ' Welcome to visit ' | | Chr (10) | | Www.CSDN.NET ' from dual; --' | | Chr (10) | | As line break
53. How do I enable the SELECT statement to automatically generate sequential numbers for query results?
Select RowNum COL from table; --The main thing is the introduction of rownum in Oracle
54. How do I know the tablespace of a table in a data pant?
Select Tablespace_name from User_tables where table_name= ' TEST '; --table_name name to capitalize.
SELECT * FROM User_tables has a field tablespace_name, (Oracle);
SELECT * from Dba_segments where ...;
55. How can I quickly make a backup table the same as the original table?
CREATE TABLE new_table as (SELECT * from old_table);
59. How can I change the primary key of a table?
ALTER TABLE AAA drop constraint Aaa_key;
ALTER TABLE AAA ADD constraint Aaa_key primary key (A1,B1);
60. Change the size of the data file?
Use the ALTER DATABASE .... DataFile ...;
Manually change the size of the data file, there is no damage to the original data file.
61. How do I see which programs are running in Oracle?
View V$session Table
62. How can I see how many tablespace a database has?
SELECT * from Dba_tablespaces;
72. How do I see which users have Sysdba, sysoper permissions?
Sql>conn sys/change_on_install– not go up
Sql>select * from V_$pwfile_users;
76. How do I display the currently connected user?
SHOW USER
77. How do I view the path of the data file placement?
Col file_name Format A50
Sql> Select Tablespace_name,file_id,bytes/1024/1024,file_name from Dba_data_files order by file_id;
79. How do I change the check range of a field's initial definition?
sql> ALTER TABLE XXX drop constraint constraint_name;
Then create a new constraint:
sql> ALTER TABLE XXX add constraint constraint_name check ();
83. How do I execute a script sql file?
sql>@ the file path where the/filename.sql is located;
For example, in the root directory of the E-drive, it should be
@e:\a.sql; the return is OK.
84. How to quickly empty a large table?
Sql>truncate table table_name;
85. How many database instances are checked?
Sql>select * from V$instance;
86. How to query the database how many tables?
Sql>select * from All_tables;
87. How can I test the time spent in SQL statement execution?
Sql>set timing on;
Sql>select * FROM TableName;
89. Connection of strings
SELECT CONCAT (col1,col2) from TABLE;
SELECT col1| | COL2 from TABLE;
90. How do I bring the results of a select to a text file?
Sql>spool C:\ABCD. TXT;
Sql>select * FROM table;
SQL >spool off;
91. How do I estimate the number of I/Os executed by SQL?
Sql>set AUTOTRACE on;
Sql>select * from TABLE;
OR
Sql>select * from V$filestat;
Can see the number of IO
92. How do I change the size of a field under Sqlplus?
ALTER TABLE table_name Modify (field_name VARCHAR2 (100));
Change the line, not the smaller (unless it is empty)
93. How do I query the data for one day?
SELECT * from a where trunc (date field) =to_date (' 2003-05-02 ', ' yyyy-mm-dd ');
If the date type data
INSERT into bsyear values (to_date (' 20130427 ', ' YYYYMMDD '));
or INSERT into bsyear values (' 2 July-April-2013 ');
94. How do SQL statements insert a year-round date?
CREATE TABLE Bsyear (d date);
Insert INTO Bsyear Select To_date (' 20030101 ', ' YYYYMMDD ') +rownum-1
From all_objects where RowNum <= to_char (to_date (' 20031231 ', ' yyyymmdd '), ' ddd '); --Insert the 365-row data date directly after the table.
Urgent insertion of several important:
How to replicate table structures and table data in Oracle
1. Copy the table structure and its data:
CREATE TABLE Table_name_new as SELECT * from Table_name_old
2. Copy only the table structure:
CREATE TABLE Table_name_new as SELECT * from Table_name_old where 1=2;
Or:
CREATE TABLE table_name_new like Table_name_old
3. Copy only the table data:
If the two table structure is the same:
INSERT INTO Table_name_new select * from Table_name_old
If the structure of the two tables is different:
Insert INTO Table_name_new (Column1,column2 ...) select Column1,column2 ... from Table_name_old
To create a table with a primary key:
CREATE TABLE Stuinfo (stuid int primary key,stuname VARCHAR2 (), age int);
Or not directly increase the primary key
ALTER TABLE Stuinfo add constraint stuinfo _pk primary KEY (Stuid)
95. What if I modify the table name?
ALTER TABLE Old_table_name Rename to New_table_name;
97. How do I know what permissions the user has?
SELECT * from Dba_sys_privs; --a permission corresponds to one piece of data, so that there is more than one data for the same user.
98. What is the difference between oracle9i downloaded from the Internet and the Standard Edition sold on the market?
There is no difference in functionality, except that Oracle has expressly stated that Oracle products downloaded from the site may not be used for commercial purposes or otherwise infringed.
101. How do I search for the top N records?
SELECT * from the EmpLOYEE WHERE ROWNUM < n ORDER by Empno;
Select * from a where rownum<n;
104. How do I count the total number of records in two tables?
Select (select count (id) from AA) + (select COUNT (id) from BB) total from dual; --Total that is not single quotes, double quotes can be.
106. How do I add 2 years to an existing date? (
Select Add_months (sysdate,24) from dual; --2015/4/27 9:28:52
Can tablespace be larger than 4G?
There is no limit.
111. Returns the minimum integer value greater than or equal to n?
SELECT ceil (N) from DUAL;
112. Returns the smallest integer value less than or equal to n?
SELECT Floor (N) from DUAL;
113. Return to the last day of the current month?
SELECT Last_day (sysdate) from DUAL;
;
115. How do I find the name of the primary key field for a database table?
Sql>select * from user_constraints WHERE constraint_type= ' P ' and table_name= ' table_name '; --I didn't find out.
116. What are the functions of two result sets that are added to each other?
Sql>select * FROM Bsempms_old INTERSECT SELECT * from Bsempms_new;
Sql>select * FROM Bsempms_old UNION SELECT * from Bsempms_new;
Sql>select * from Bsempms_old UNION all SELECT * from bsempms_new;
117. Function of two result set reciprocal subtraction?
Sql>select * from Bsempms_old minus SELECT * from Bsempms_new;
139. How do I find duplicate records?
SELECT * FROM table_name where rowid!= (select MAX (ROWID) from TABLE_NAME where TABLE_NAME. COL1=D.COL1 and TABLE_NAME. COL2=D.COL2);
140. How do I delete duplicate records?
DELETE from table_name where rowid!= (SELECT MAX (ROWID) from table_name D where TABLE_NAME. COL1=D.COL1 and TABLE_NAME. COL2=D.COL2);
162. How do I know how a table is stored in a tablespace?
Select Segment_name,sum (bytes), COUNT (*) Ext_quan from dba_extents where tablespace_name= ' &tablespace_name ' and Segment_type= ' TABLE ' GROUP by Tablespace_name,segment_name; --Change the &tablespace_name to the corresponding table space name.
Oracle BASIC commands