Oracle命令行连接数据库并创建表插入数据
1、切换到oracle用户
[root@oracledb ~]# su - oracle
Last login: Tue Jun 1 01:48:10 PDT 2021 on pts/5
2、以dba身份进入sql语句
[oracle@oracledb ~]$ 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、查看运行的实例
SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
orcl
SQL> select status from v$instance;
STATUS
------------
OPEN
4、查看当前库的所有数据表
SQL> select TABLE_NAME from all_tables;
5、查询表名
SQL> select table_name from all_tables where table_name = 'USERS';
TABLE_NAME
------------------------------
USERS
USERS
USERS
6、查询表记录,HMF是schma(模式)
SQL> SELECT NAME FROM "HMF"."USERS";
NAME
--------------------------------------------------------------------------------
张军
张军
7、在schema:HMF中创建表USERS22
CREATE TABLE TESTSDK( "ID" NUMBER(22,0) NOT NULL ENABLE,
"NAME" VARCHAR2(100) NOT NULL ENABLE,
"EMAIL" VARCHAR2(100) NOT NULL ENABLE
)
TABLESPACE USERS;
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、给USERS22表中插入数据
INSERT INTO HMF.USERS22 VALUES ('2', '张军', 'zhangjun@yaho.net', '45', 'M', '50011919870824110X', '18152276065', 'SYP618183458', '', '北京市朝阳区国贸');
9、查询USERS22表
select * FROM "HMF"."USERS22";