Regarding Users in Oracle 12c

你。 提交于 2019-12-04 06:23:25

Best Practice is to create a tablespace and assign that to the User.

Just to make it easier to understand use same name for username and tablespace

CREATE BIGFILE TABLESPACE C##1
DATAFILE '/path/to/datafile/C##1.dbf'
SIZE 10M AUTOEXTEND ON NEXT 5M MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO NOLOGGING;


--Create User

CREATE USER C##1
IDENTIFIED BY password DEFAULT TABLESPACE C##1
QUOTA UNLIMITED ON C##1;

You should also give the user a quota on his default tablespace:

CREATE USER name
IDENTIFIED BY name
DEFAULT TABLESPACE users
TEMPORARY TABLESPACE temp
QUOTA 50M /* or any other number that makes sense */ ON users

GRANT CONNECT, CREATE SESSION, RESOURCE, CREATE VIEW TO name;
Tom

Try this:

#!/bin/bash
USERVALID=false;

if [ -z $1 ]; then
 echo -e "\nThis script will create a new common user in Oracle"
fi

while [[ $USERVALID == false ]]; do
 if [ -z $1 ]; then
  echo -e "Username must start with 'c##' or 'C##'\n"
  read -p "Enter a username: " NEWUSER
 else
  NEWUSER=$1
 fi
 if [[ $NEWUSER == c##* ]]
 then
  USERVALID=true;
 elif [[ $NEWUSER == C##* ]]
 then
  USERVALID=true;
 else
  USERVALID=false;
  echo -e "\nInvalid username";
  if [ ! -z $1 ]; then
   echo -e "Username must start with 'c##' or 'C##'\n"
   exit 0
  fi
 fi
done

while [[ -z $NEWPWD ]]; do
 if [ -z $2 ]; then
  read -p "Enter a password: " NEWPWD
 else
  NEWPWD=$2
 fi
 if [[ -z $NEWPWD ]]
 then
  echo -e "Password must not be NULL"
 fi
done

get_user_status () {
 sqlplus -s / as sysdba <<!
 set heading off
 set feedback off
 set pages 0
 select username from all_users where username = '${NEWUSER^^}';
!
}

USERDROP=$(get_user_status)
if [[ $USERDROP =~ ${NEWUSER^^} ]]; then
 echo -e "\nUser already exists...\nAttempting to drop user\n"
 echo -e "DROP USER $NEWUSER CASCADE;" | sqlplus -s / as sysdba
 USERDROP=$(get_user_status)
 if [[ $USERDROP =~ ${NEWUSER^^} ]]; then
  echo -e "Please ensure user is disconnected from the database before proceeding.\n"
  exit 0
 fi
fi

echo -e "CREATE USER $NEWUSER IDENTIFIED BY $NEWPWD;"  | sqlplus -s / as sysdba

USERDROP=$(get_user_status)
if [[ ! $USERDROP =~ ${NEWUSER^^} ]]; then
 echo -e "You are a bad person.\n"
 exit 0
fi

echo -e "GRANT CREATE SESSION TO $NEWUSER;"            | sqlplus -s / as sysdba
echo -e "GRANT CREATE PROCEDURE TO $NEWUSER;"          | sqlplus -s / as sysdba
echo -e "GRANT CREATE SEQUENCE TO $NEWUSER;"           | sqlplus -s / as sysdba
echo -e "GRANT CREATE DATABASE LINK TO $NEWUSER;"      | sqlplus -s / as sysdba
echo -e "GRANT CREATE TABLE TO $NEWUSER;"              | sqlplus -s / as sysdba
echo -e "GRANT CREATE VIEW TO $NEWUSER;"               | sqlplus -s / as sysdba
echo -e "GRANT CREATE MATERIALIZED VIEW TO $NEWUSER;"  | sqlplus -s / as sysdba
echo -e "GRANT QUERY REWRITE TO $NEWUSER;"             | sqlplus -s / as sysdba
echo -e "GRANT SELECT ANY TABLE TO $NEWUSER;"          | sqlplus -s / as sysdba
echo -e "GRANT SELECT ON SYS.V_\$SESSION TO $NEWUSER;" | sqlplus -s / as sysdba
echo -e "GRANT EXECUTE ON SYS.DBMS_LOCK TO $NEWUSER;"  | sqlplus -s / as sysdba
echo -e "GRANT UNLIMITED TABLESPACE TO $NEWUSER;"      | sqlplus -s / as sysdba

echo -e "\nAll done!\n"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!