How to create a database user for oracle 11g on windows 8? - oracle

I am new to oracle database and therefore is trying to follow the office guide. (link to the guide) However, it seems that the guide is for Windows 7, so in step 2 - creating database user, it says:
Display the SQL command prompt window. For example, on Windows, click Start, then Programs (or All Programs), then Oracle Database 11g
Express Edition, and then Run SQL Command Line.
And in windows 8, there is not start button. I try to search the menu using keyword oracle but nothing with similar name is found. I tried to go to the Program Files directly but also no similar file found. So, how should I create a database user on Windows 8?

I don't use Windows 8, but I guess that it must have some kind of a "command prompt" (you know, a program that lets you perform text-based (command-line) functions; its window is black with white letters. Once opened, the cursor blinks at the prompt, waiting for your commands). Try to find it, run it.
Then you'll be able to connect to your database (you do have it installed, right?) as
C:\> sqlplus sys/your_sys_password#database as sysdba
You'll be connected as SYS (be careful! It is a powerful user and its misuse might break your database! I'd suggest you to create another user, for example "mydba", grant it DBA role and let it perform DBA actions).
If you're unsure of what your tablespaces are, run
SQL> select tablespace_name from dba_tablespaces;
TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USER_DATA
APEX
APEX_9695076087226093
7 rows selected.
SQL>
as you'll need at least two of them. Now create your new user:
SQL> create user mike identified by lion
2 default tablespace user_data
3 temporary tablespace temp
4 profile default
5 quota unlimited on user_data;
User created.
SQL> grant create session to mike;
Grant succeeded.
SQL>
Granting create session, it'll be able to connect to the database, but won't be able to do anything else, so you'd have to grant it some more privileges (such as create table, create view, create procedure etc.).
SQL> connect mike/lion#orcl
Connected.
SQL> create table test (id number);
create table test (id number)
*
ERROR at line 1:
ORA-01031: insufficient privileges
SQL>

Related

How to create a table in 18c express edition

I just finished installing oracle 18c express edition on windows 8 laptop. During the installations, I did not enter any user name. I entered my password though.
At the end of the installation, I get this screen:
I connected Oracle database using sql plus as follows:
SQL> / as sysdba
I also entered the following commands in sql plus and all have worked. I was just following youtube tutorial without understanding everything.
SQL>alter pluggable database all open;
SQL>alter pluggable database all save state ;
SQL>select name from v$pdbs;
SQL> connect sys/oracle#localhost:1521/XEPDB1 as sysdba;
SQL> alter user hr identified by hr;
SQL> alter user hr account unlock;
SQL>connect hr/hr#localhost:1521/XEPDB1;
SQL> select * from employees;
SQL> CREATE TABLE TEST1 (CUSID NUMBER(10) NOT NULL);
This is the first time I am doing it. I tried to connect to a database using SYS as the user name and the password but did not connect.
SQL> Enter user name: SYS;
Enter password: Welcome1
SYS - During the installation, it said sys, system, and pdbadmin accounts. So I assume sys could be one of the user names.
Password - I entered the same password I used at the time of installation. I can connect to the database using / as sysdba. But I am not sure what this code meaning and what the user name and password and what database it is trying to connect. What would be the database name, user name and password?
Update 1
I created a connection in sql developer. Below shows the connection properties.
I created a table(sqldev2) in sql developer, inserted rows, and selected the data just fine.
Next, I went to sql plus and tried to select the same data from sqldev2 table but it shows no rows selected. I am assuming sql plus and sql developer may be pointing to two different databases?
How can I tell which database I am connected using the sql developer?
How can I connect to the same database using the sql plus?
This way I can work on the same database using the sql plus and sql developer.
Update 2
In Eclipse IDE, I had this code to connect to database. After that, I created a table (testtble) in Eclipse.
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("Driver Loaded");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:#localhost:1521/xe", "sys as sysdba","pw");
In SQL Plus, I connected to the db using "/ as sysdba". After that, I also tried to select * from testtble but it shows no table. I am assuming sql plus might be pointing to something different than what I used in eclipse. How should I connect to the database from SQL plus so I could see the table "testtble" in sql plus?
To check in which pluggable database you are currently connected in SQL*Plus use:
show con_name
If you connect to Oracle using a connect string that is using a database service mapped to a pluggable database (PDB), you will be connected directly to the related PDB.
Try different connections strings and check with show con_name.

How do I connect to the default Oracle10g instance on my PC?

I have a strong SQL Server background but fairly new to Oracle. I have a Windows 10 Home Edition. I installed Oracle 10g along with Oracle SQL Developer. What credentials/settings do I need to do to specify in SQL Developer to connect to the default Oracle database (if one exists)?
Well, that depends on what exactly you installed. Which Oracle 10g version? XE? Standard? Enterprise? As far as I can tell, Oracle was never certified on any Windows Home edition. It's not that it won't work at all, it just depends.
By the way, why 10g? It is outdated; the most recent version is 18c (available for download on Oracle Technology Network, https://www.oracle.com/downloads/).
As you are new to Oracle, I'd suggest you to use XE (Express Edition). Even 10g would do, I presume (if that's what you installed). For amusement, I have 11gXE on my Windows 7, works well. Why? Because it is a small footprint database, fully functional, free to use. It has its restrictions (such as 1 CPU, 1 GB RAM, 8 GB of user data) (those restrictions depend on XE version), but it is OK for most purposes.
Moreover, it automatically installs the database you can start using. During the installation process, you're asked for password for SYS (and SYSTEM) users (they "own" the database). Once you know these, you're the boss.
In XE, you have pre-installed schemas (i.e. users with their objects: tables, views, ...) which are named Scott, HR (Human Resources). By default, they are locked so you'd have to connect to the database as SYS and unlock them.
As you already have SQL Developer, you'd create a connection:
username = SYS
password = you know it
connection type = Basic
role = default
hostname = localhost
port = 1521 (it is the default; if you use some other port, you'll know it)
SID = xe (by default)
Once you're connected, check which users you have
select username, account_status from dba_users;
As I've said, Scott and/or HR might be interesting for you as they already have some objects. See their status; if they are locked, you'd unlock them and set new passwords as
alter user scott account unlock;
alter user scott identified by tiger;
Now you can create a new connection to Scott, following the same instructions as above.
If you want to create your own user, no problem. Still connected as SYS, check available tablespaces (this is SQL*Plus output, command-line tool; in SQL Developer, you won't have the "SQL>" prompt):
SQL> select tablespace_name from dba_tablespaces;
TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USERS
SQL> create user sam identified by nasr
2 default tablespace users
3 temporary tablespace temp
4 quota unlimited on users;
User created.
Once the user is created, it can't do anything - you have to grant it certain privileges, such as :
SQL> grant create session, create table, create view to sam;
Grant succeeded.
Create session allows it to establish connection; another two will let you create tables and views. If you - as the time goes by - need yet another privilege, connect as SYS and grant it the same way.
Now you can connect to it (that would be yet another connection in SQL Developer) and ... do something:
SQL> connect sam/nasr
Connected.
SQL> create table test (id number);
Table created.
SQL> insert into test (id) values (100);
1 row created.
SQL>
So: if you have anything but XE, I'd suggest you to uninstall it. Use Universal Installer to do that. Then download and install XE. In my opinion, as Oracle beginner, that should make your life easier.
On the other hand, if you want to practice to be a DBA, then XE probably isn't the right choice as there can be only one - preinstalled - database.

Oracle Application Express 11g

I am new to Oracle and want to practice SQL.
I downloaded the Application Express Edition 11g for Windows x64. I followed instructions and created a workspace and user.
However when I try to create a table I get an error "ORA-20000: User xxx has no privileges on the schema. Error checking privileges.
However when I go and look at the user in the administration is says that I am the workspace administrator. I also cannot seem to log in as SYSTEM or SYS using the password I created when I installed.
I am very confused.
There are two terms you are dealing with:
a database, which contains tables and data - tables belong to users such as SYS or SYSTEM - you should not use them at all, except for unlocking existing user (HR or SCOTT; whichever it is) in order to use it for practicing
Application Express, which is a tool you use to access the database and create applications which will manage data stored in your tables. Once you log on as admin, you can create workspaces (which are mapped to database users/schemas) and developers (who will create applications). This "admin" user is very different from database owners (sys/system), so you can't log on to Apex using sys as username and its password
As you installed the 11g XE database (which has built-in Apex version 4.x, I think - it is not Apex 11g, it doesn't exist), at the operating system command prompt run SQL*Plus and connect as SYS:
C:\>sqlplus sys#xe as sysdba
SQL*Plus: Release 11.2.0.2.0 Production on Sub Lis 6 20:26:19 2018
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Enter password:
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL>
List users in the database:
SQL> select username, account_status from dba_users order by username;
USERNAME ACCOUNT_STATUS
------------------------------ --------------------------------
ANONYMOUS OPEN
APEX_PUBLIC_USER LOCKED
APEX_040000 LOCKED
APPQOSSYS EXPIRED & LOCKED
CTXSYS EXPIRED & LOCKED
DBSNMP EXPIRED & LOCKED
DIP EXPIRED & LOCKED
FLOWS_FILES LOCKED
HR LOCKED
IMPORTER OPEN
MDSYS EXPIRED & LOCKED
MIKE OPEN
ORACLE_OCM EXPIRED & LOCKED
OUTLN EXPIRED & LOCKED
SCOTT OPEN
SYS OPEN
SYSTEM OPEN
XDB EXPIRED & LOCKED
XS$NULL EXPIRED & LOCKED
19 rows selected.
SQL>
See the HR (human resources) user? It is locked. We'll unlock it and change its password (to "hr") so that you could use it in Apex, as it already contains several tables full of data.
SQL> alter user hr account unlock;
User altered.
SQL> alter user hr identified by hr;
User altered.
SQL>
Connect as HR, just to see what it contains:
SQL> connect hr/hr#xe
Connected.
SQL> select * From tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
COUNTRIES TABLE
DEPARTMENTS TABLE
DEPT TABLE
EMPLOYEES TABLE
EMP_DETAILS_VIEW VIEW
INSTRUCTOR TABLE
JOBS TABLE
JOB_HISTORY TABLE
LOCATIONS TABLE
PRODUCT TABLE
REGIONS TABLE
RIGHTS TABLE
TEACHES TABLE
USERS TABLE
14 rows selected.
SQL>
If you want to create your own tables, do it in HR schema. As I said, leave SYS and SYSTEM alone; they are special, you don't use them for everyday purposes. If you do something unusual, you might destroy the database.
OK; now run Apex, connect as admin, navigate to "Manage workspaces" and:
create workspace - follow the wizard. When asked, "re-use existing schema" answer "Yes" and select HR from list of values
manage developers and users - create user. Follow the wizard. As a workspace, select previously created workspace, set the password
Once you're done, logout of admin and logon as newly created user - provide workspace name, username and password - that should let you in. Once you're in Apex - as a developer - you can create your first page (an interactive report might be a good choice).
Good luck!
[EDIT: built-in Apex on 11gXE]
click Start - All programs - Oracle database 11g Express Edition - Get started
a page opens, offering several red buttons; the last of them is "Application Express"; click it
login asks for database user with DBA privileges; enter username = SYS (or SYSTEM) and its password
you're now redirected to "create Apex workspace" page. Items' labels are underlined; it means that they contain help (feel free to click). The first item is "Database user" radio button which offers "Create new" and "Use existing" - you'd choose "Use existing"
for "Database username", choose "HR" from select list. HR is now unlocked, right? If it is expired, make sure you altered it in order to set the password (alter user hr identified by hr)
Application Express username (and password) represents username related to Apex (i.e. not the database user) - you'll use it to log on to Apex
If you want to see which workspaces already exist, connect to the database as SYS (using SQLPlus at the operating system command prompt):
C:\>sqlplus sys#xe as sysdba
SQL*Plus: Release 11.2.0.2.0 Production on Ned Lis 7 12:40:34 2018
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Enter password:
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL> select * from all_users where username like 'APEX%';
USERNAME USER_ID CREATED
------------------------------ ---------- --------
APEX_040000 47 29.05.14
APEX_PUBLIC_USER 45 29.05.14
SQL> -- describe table that contains info about workspaces
SQL> desc apex_040000.apex_workspaces
Name Null? Type
----------------------------------------- -------- ----------------------------
WORKSPACE NOT NULL VARCHAR2(255)
SOURCE_IDENTIFIER VARCHAR2(8)
SCHEMAS NUMBER
LAST_PURGED_SESSION DATE
ALLOW_APP_BUILDING_YN VARCHAR2(1)
ALLOW_SQL_WORKSHOP_YN VARCHAR2(1)
ALLOW_WEBSHEET_DEV_YN VARCHAR2(1)
ALLOW_TEAM_DEVELOPMENT_YN VARCHAR2(1)
ALLOW_TO_BE_PURGED_YN VARCHAR2(1)
SESSIONS NUMBER
APPLICATIONS NUMBER
APPLICATION_PAGES NUMBER
APEX_USERS NUMBER
APEX_DEVELOPERS NUMBER
APEX_WORKSPACE_ADMINISTRATORS NUMBER
FILES NUMBER
SQL_SCRIPTS NUMBER
TRANSLATION_MESSAGES NUMBER
FILE_STORAGE NUMBER
LAST_LOGGED_PAGE_VIEW DATE
PAGE_VIEWS NUMBER
WORKSPACE_ID NOT NULL NUMBER
SQL> col workspace format a10
SQL> select workspace, source_identifier, apex_developers
2 from apex_040000.apex_workspaces;
WORKSPACE SOURCE_I APEX_DEVELOPERS
---------- -------- ---------------
HR HR 1
INTERNAL 0
SQL>
If HR workspace already contains, it means that you've already created it.
In web browser, connect as admin (use address http://127.0.0.1:8080/apex/apex_admin). (Workspace name is "internal"; you don't have to enter it). Username = admin, password = ... huh, not sure. Try SYS password. If you can't connect, you can change that password. Locate file named APXCHPWD.SQL ("Apex change password") on your disk; for example, it'll be in C:\oraclexe\app\oracle\product\11.2.0\server\apex\apxchpwd.sql directory. In SQLPlus, connected as SYS, execute that file:
SQL> show user
USER is "SYS"
SQL> #C:\oraclexe\app\oracle\product\11.2.0\server\apex\apxchpwd.sql
Enter a value below for the password for the Application Express ADMIN user.
Enter a password for the ADMIN user []
Session altered.
...changing password for ADMIN
PL/SQL procedure successfully completed.
Commit complete.
SQL>
Admin will now have password you've just typed, so - back to Apex admin, connect; you'll have to change that password so - do it, and connect again.
You'll now see "Manage Workspaces" button. In there, there are numerous links which do stuff. If you want, you can remove the HR workspace (following the "Remove Workspace" link) and create it back again.
The next step is to create a developer - use "Manage Developers and Users" link. Once you do that, you should be able to log on to Apex as developer, using "HR" as workspace name, developer username and password as credentials.
In order to be able to simultaneously adjust Apex as admin and connect as a developer, open a new connection using a different browser (for example, Chrome for one thing, Internet Explorer for another) - if you use the same browser (but different tabs or even a new browser session entirely), it won't work - new connection will terminate previous one.
I hope that the above will get you started.
Apparently, built-in Apex version is 4.0.2 (quite old one, at least 5-6 years), but will do at the beginning. Upgrade to a more recent version isn't difficult - download it and run SQL file which does everything for you. Just follow the Installation Guide.
I'd also suggest you to read & follow 4.0 Apex User's Guide, so that I wouldn't have to create a tutorial here, on Stack Overflow :)

Installation process of utPLSQL

I am trying to setup utPLSQL for writing a unit test for PLSQL project.
I am running into error while installing.
I am not getting how to install it.
Could anyone give a step by step procedure to install utPLSQL ?
Thanks
From http://utplsql.sourceforge.net/Doc/fourstep.html
It looks rather simple, but you must connect to sqlplus as SYSTEM - a power user on your database that will be able to create the UTP user.
SQL> connect system/< the system's password >
SQL> create user utp identified by utp default tablespace
users temporary tablespace temp;
SQL> grant create session, create table, create procedure,
create sequence, create view, create public synonym, drop public synonym to utp;
SQL> alter user utp quota unlimited on users;
Then only run
SQL> ut_i_do install

Why do I need a common account in Oracle?

Why do I need a common account in Oracle 12c? A common means a CDB account. When I create an account using enterprise manager express it's creating only common accounts. Could I create a non-common account there? A common user also appears in every container I ever switch/connect to. What's the purpose of this common account to access all those pluggable databases?
Why do I need a common account in Oracle 12c?
What's the purpose of this common account to access all those pluggable databases?
You need a common account(common user) to perform administrative operations on CDB(container database) such as changing the state of a pluggable database, plugging and unplugging pluggable databases (PDBs) and so forth, which local user cannot do. Well, in fact, a local user can change state of pluggable database as well, but only PDB it connected to as sysdba or sysoper.
Could I create a non-common account there(in CDB)?
No, non-common account(Local user) cannot be created in the root - can only be created and operate within a pluggable database(PDB) and wont have access(you cannot use it to log in to) CDB or other PDBs.
Find out more
about commonality and common and local users.
Edit
CDB$ROOT is root container. PDB$SEED is just a template needed to create a pluggable databases. You cannot create or modify objects in it. PDBORCL is a pluggable database, which you should use for your development.
Oracle will throw the ORA-01033 error if you are trying to connect to a closed PDB as non sysdba user. Usually, PDBs database are not open by default, just mounted (unless your have automated that process by creating a trigger, for example, that will do it for you upon starting up CDB) and you need to explicitly open it while connecting as a common user (SYS or other common user that has the privilege to startup/alter pluggable database) and issue:
SQL> alter pluggable database <<name_of_PDB>> open;
or
SQL> startup pluggable database <<name_of_PDB>>
After that you should be able to connect to your PDB as common or local user. Of course they have to have appropriate privileges(create session) to be able to do so.
Edit #2 Automating starting up of pluggable database(s) on startup of CDB using system event(after startup on database) trigger. Unfortunately there is no native way to startup PDs automatically.
SQL> conn / as sysdba
Connected.
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 NKRASNOV READ WRITE NO
This specific trigger opens one pluggable database. If you have more than one PDs and want to open them all, the alter statement can be modified as follows ALTER PLUGGABLE DATABASE ALL OPEN;
SQL> create or replace trigger open_pdb
2 after startup on database
3 begin
4 execute immediate 'alter pluggable database nkrasnov open';
5 end;
6 /
Trigger created.
SQL> shutdown
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Database mounted.
Database opened.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 NKRASNOV READ WRITE NO
SQL> conn hr/hr#nkrasnov_pdb
Connected.
SQL> spool off;

Resources