Oracle note (2) sqlplus command

Source: Internet
Author: User

For Oracle database operations, the command line method is used, and all commands are completed using sqlplus. For SQL Plus, there are two forms.

    • One is DOS-style sqlplus: sqlplus.exe;
    • The other is Windows-style sqlplus: sqlplusw.exe;

The sqlplusw command is mainly used in Oracle 10 Gb, because it can adjust some display data.

The default available database instance is found.

Example:Enter query commands

 
Select * FromEMP;

At this time, the data can be normally displayed, but there will still be a data line problem, because this is the default data size of each line, and now you can adjust it using two commands:

    • Set the length of the record displayed per line: Set linesize 300;
    • Set the length of the record displayed on each page: Set pagesize 30;

These two commands will be called the formatting command in the future, but the setting of these formatting commands under sqlplus is not very obvious.

Although sqlplusw is easier to display, it is not very convenient to edit the command. For example, if the command is wrong during normal operations, you must use the direction key to move it to the wrong position for modification, however, in sqlplusw, the arrow keys can only control the movement of the screen, so this command is not suitable for editing at all. Therefore, the ED and @ commands are provided in sqlplusw to call and execute notepad;

    • Use Ed to call notepadProgram: Ed;

At this time, the user will be prompted that ". SQL file, ask whether to create, select "yes", but after using ed to open notepad, The sqlplusw window in Oracle will enter the blocking status and cannot be used.

    • Run the @ program: @;

Secret file, which saves the programCode.

To read the file on the hard disk, you must enter the complete path @ D: \ demo.txt. If the file is suffixed with "*. SQL, you do not need to enter the file suffix (demo. SQL), enter @ D: \ demo, or enter @ D: Demo directly.

There are many users in a database (four users are known now). Each user has multiple data tables of their own. Therefore, to view all data tables, you can use the following command:

Select * FromTab;

In addition, because there are many users, you can use the show USER command to know the current logon user.

In addition, in sqlplusw, you can directly switch the user's logon, using the following syntax:

 
Conn User Name/Password[As sysdba];

Use sys User Logon: conn sys/change_on_install as sysdba;

However, once the Sys connection is used, the EMP table data cannot be directly queried.

Each table has its users. Therefore, the full name of a table is "user name. table name or schema name. table Name ". Therefore, to access tables of other users, add the user name, that is, the current access Name:

 
Select * FromScott. EMP;

Once a super administrator is used to log on, you can use commands to manually control the opening and closing of database instances;

    • Close the database instance:Shutdown immediate;

      • Once it is disabled, the user cannot directly connect to the sqlplusw command. At this time, you can use "/nolog" to log on and then use the Administrator to log on;
 
SQL>Conn sys/SysAsSysdba; connected. SQL> ShutdownImmediate; the database has been disabled. The database has been detached. The Oracle routine has been disabled. SQL> 

    •  Start a database instance:Startup;

In addition, the sqlplusw command window can also call the local operation command and use "host" as the prefix.

 
Host Copy D: \ demo. SQL D: \ hello.txt

The above commands must be mastered and will be used in the future.

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.