Get the App
SLTechnology News&Howtos  ›  Database  › 

How to call sqlplus in Oracle Program

Shulou Source: shulou.com Published: 2022-05-31 20:38:33 09月20日 Update

This article mainly introduces how to call sqlplus in the Oracle program, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to know about it.

Through sqlplus, you can connect to the database to perform data or set operations according to user permissions, but you need to interoperate and return results. This article describes how to use sqlplus in a program.

Environmental preparation

Create a docker-style demo environment using a stripped-down version of Oracle

Here Document

Because sqlplus is the console way corresponding to the user's interactive input / output, and obviously requires predetermined input during program execution, you can consider using Here Document, for example, if you want to confirm the database version information through sqlplus.

# sqlplus system/liumiao123 EOFSQL*Plus: Release 11.2.0.2.0 Production on Sun Oct 21 11:06:42 2018Copyright (c) 1982, 2011, Oracle. All rights reserved.Connected to:Oracle Database 11g Express Edition Release 11.2.0.2.0-64bit ProductionSQL > BANNER----Oracle Database 11g Express Edition Release 11.2.0.2. 0-64bit ProductionPL/SQL Release 11.2.0.2.0-ProductionCORE 11.2.0.2.0 ProductionTNS for Linux: Version 11.2.0.2.0-ProductionNLSRTL Version 11.2.0.2.0-ProductionSQL > Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0-64bit Production#

Note: note that $in v$version needs to be escaped

Create table

Next, use Here Document to call sqlplus to create a table

# sqlplus system/liumiao123 stuid number (4), > stuname varchar2 (50), > primary key (stuid) >) > desc student; > EOFSQL*Plus: Release 11.2.0.2.0 Production on Sun Oct 21 11:11:52 2018Copyright (c) 1982, 2011, Oracle. All rights reserved.Connected to:Oracle Database 11g Express Edition Release 11.2.0.2.0-64bit ProductionSQL > 2 345 Table created.SQL > Name Null? Type-STUID NOT NULL NUMBER (4) STUNAME VARCHAR2 (50) SQL > Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0-64bit Production# Thank you for reading this article carefully I hope the article "how to call sqlplus in the Oracle program" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Article program data method database environment user input next interactive value information interest at the same time console more friends permissions version knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Apple vpn MySQL Huawei