Create user through a shell script

To create a new user, you must log in to SQL as a system user. To create a new user account, we are going to write the CREATEUSER command.

We grant all of the privileges to a user in the same script. Let's create the script to create a user and grant them privileges:

sqlplus system/Training2 <<MY_QUERY 
set serveroutput on; 
create user demo_user identified by userdemo; 
grant connect, resource to demo_user; 

Save the script and run it as follows:

          $ chmod +x
          $ ./

The output will be:

    SQL*Plus: Release Production on Mon Apr 30 17:44:50 2018
    Copyright (c) 1982, 2009, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise ...

Get Learning Linux Shell Scripting - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.