Oracle(3): Oracle command line to connect to the database and create a table to insert data

Oracle command line to connect to the database and create a table to insert data

1. Switch to oracle user

[[email protected] ~]# su-oracle
Last login: Tue Jun 1 01:48:10 PDT 2021 on pts/5

2. Enter the sql statement as dba

[[email protected] ~]$ sqlplus "/as sysdba"

SQL*Plus: Release 11.2.0.1.0 Production on Tue Jun 1 01:49:31 2021

Copyright (c) 1982, 2009, Oracle. All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0-64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

3. View the running instance

SQL> select instance_name from v$instance;

INSTANCE_NAME
----------------
orcl

SQL> select status from v$instance;

STATUS
------------
OPEN

4. View all data tables in the current library:
SQL> select TABLE_NAME from all_tables;

5. Query table name

SQL> select table_name from all_tables where table_name ='USERS';

TABLE_NAME
------------------------------
USERS
USERS
USERS

6. Query table records, HMF is schma (mode)

SQL> SELECT NAME FROM "HMF"."USERS";

NAME
------------------------------------------------- -------------------------------
Zhang
Jun Zhang Jun

7. Create a table USERS22 in schema: HMF

CREATE TABLE "HMF"."USERS22"    (	"ID" NUMBER(22,0) NOT NULL ENABLE, 	"NAME" VARCHAR2(100) NOT NULL ENABLE, 	"EMAIL" VARCHAR2(100) NOT NULL ENABLE, 	"AGE" NUMBER(*,0) NOT NULL ENABLE, 	"SEX" VARCHAR2(100) NOT NULL ENABLE, 	"ID_CARD" VARCHAR2(100) NOT NULL ENABLE, 	"MOBILE_PHONE" VARCHAR2(100) NOT NULL ENABLE, 	"VISA_CARD" VARCHAR2(100) NOT NULL ENABLE, 	"OFFICER_CARD" VARCHAR2(255), 	"ADDRESS" VARCHAR2(255), 	 PRIMARY KEY ("ID"))TABLESPACE USERS;

8. Insert data into the USERS22 table

INSERT INTO HMF.USERS22 VALUES  ('2', '张军', '[email protected]', '45', 'M', '50011919870824110X', '18152276065', 'SYP618183458', '', '北京市朝阳区国贸');

9. Query the USERS22 table

select * FROM "HMF"."USERS22";