How to create a table in 18c express edition - oracle

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.

Related

Oracle Apex doesn't show existing schema

I have a problem with connecting data from my local oracle user schema (USERS table space) and apex workplace.
Could you adivise how I can connect apex workplace with my existing schema?
It looks like APEX uses its own table space and ignores my schemas.
Here are my screenshots:
SQL Developer screen Creating a new workspace screen
Forgot one significat thing to mention: schema Pavel in Apex and schema Pavel in SQL Developer are different. Tables, which are created in the Apex in schema Pavel, are not seen in SQL Developer.
No apex user screen
apex create workplace and new schema dialog (different table space), the schema is not visible in sql developer
See whether following helps:
Connect to the database as SYS and check your Apex users:
SELECT * FROM ALL_USERS WHERE USERNAME LIKE 'APEX%',
Suppose there's APEX_180200 listed (and you use it). Then:
ALTER SESSION SET CURRENT_SCHEMA = APEX_180200;
BEGIN
APEX_INSTANCE_ADMIN.UNRESTRICT_SCHEMA(P_SCHEMA => 'ADAM');
COMMIT;
END;
/
Now check whether you can assign the ADAM schema to your workspace.
you will need to add your existing schema to your APEX workspace:
check out oracle docs for this:https://docs.oracle.com/database/121/AEAPI/apex_instance.htm#AEAPI253
BEGIN
APEX_INSTANCE_ADMIN.ADD_SCHEMA('MY_WORKSPACE','FRANK');
END;
The problem was in misunderstanding oracle database architecture.
The APEX data was stored in the pluggable database, while the default connection in SQL Plus was to the root container cdb$root.
alter session set container = XEPDB1;

Not sure how to query Oracle Apex 19.1 tables from TOAD

I've installed Oracle Apex 19.1 on Oracle XE 18c. I then created an Apex workspace for which Apex automatically creates a schema which I called MYSCHEMA. Apex reports "Database user MYSCHEMA created with default tablespace APEX_1270566619000339 using datafile D:\APP\USER\PRODUCT\18.0.0\ORADATA\XE\XEPDB1\APEX_1270566619000339.DBF". I also created a table in MYSCHEMA called EMPLOYEES.
I previously had a 11g XE which I uninstalled and replaced with the Oracle XE 18c. I could connect using the same XE database from that previous database in TOAD. It automatically picks up the new OraDB18Home1. I didn't change the tnsnames.ora. I can connect to the MYSCHEMA user using the same password as SYS.
However I don't see the EMPLOYEES table created in Apex when I use
select *
from all_tables
where table_name like '%EMPLOYEE%';
Where am I going wrong?
PS. I have now noticed that "Connect as SYSDBA" was on and it fails to connect to the user MYSCHEMA if I choose "Connect as Normal". I have tried all the passwords (2) I have used in setting this up. Not sure if there is a default password I should be using.
I then created an Apex workspace for which Apex automatically creates a schema which I called MYSCHEMA
You can do that, but don't have to. If you already have a schema in your database which contains tables that will be used while developing an Apex application, you can assign that schema to the workspace.
But OK - you chose to create a new schema.
As you can connect as SYS (which has to be AS SYSDBA), do so. Change MYSCHEMA's password by running
alter user myschema identified by some_password;
Then create a new connection in TOAD, using MYSCHEMA as username and SOME_PASSWORD as its password. That connection will be NORMAL.

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.

Connected to Pluggable Database - Cannot See Any Tables - SQL*PLUS

I am using sqlplus to connect to a pluggable database that is running on my localhost. However, when I connect I cannot see any of the tables from the major schemas.
Does anyone know how to trouble shoot this type of problem? When I connect using PL/SQL Developer however I am able to see the tables. I am connecting to the pluggable database using sql*plus like so:
sqlplus localhost:1521/services.domain as sysdba
When I try to select a table I see an error that the table or view does not exist. When I connect with PL/SQL developer like so, shown below in Figure 1, I do not have the problem of not being able to select any tables.
Figure 1: Logging into PL/SQL Developer

oracle 11g not able to connect with scott user, showing: invalid username/password; logon denied

whenever I'm trying to connect with scott it is showing invalid username/password,
tried this:
alter user scott account unlock;
SP2-0640: Not connected
alter user scott identified by tiger;
SP2-0640: Not connected
Go to the Installing path of the Oracle 11g In default it is present C: Drive, then move to C:\oraclexe\app\oracle\product\11.2.0\server\rdbms\admin
here you can find a file named scott.sql
Open the SQL Command Line and login as conn system/ (password set during the installation of oracle 11g)
Run the Below script (Note: File name is appended at the end)
# C:\oraclexe\app\oracle\product\11.2.0\server\rdbms\admin\scott.sql
Now you can query the SELECT * FROM all_users; to see the scott schema created
Alternatively you can do this by using SQL developer by creating a connection to SYSTEM and run the above script
After the creation the default username : SCOTT password: TIGER
In the comment part i especially asked for querying
select count(1) from dba_users where username = 'SCOTT';. I'd like to learn if user exists.
For the message you get ORA-01017,
the First possible reason is what message tells us(invalid
username/password).
Secondly, you may not have an account named SCOTT. i.e. the above
query gives 0(zero).
In this case :
you should create mentioned user ( when you're connected to system ):
SQL> conn system/pwd
Connected.
SQL> create user scott identified by tiger;
and grant related privileges :
SQL> grant connect to scott;
SQL> grant resource to scott;
and then you can connect by issuing :
SQL> conn scott/tiger
Connected.
Connect with a DBA Account and Issue an Alter User Command
The error you are seeing indicates you are no longer connected to the database. You were logged in as system#db, but when you tried to connect as scott#db, you no longer have a database connection.
Here I replicate your experience:
SYSTEM#db>conn system#db as sysdba
Enter password:
Connected.
SYS#db>conn scott#db
Enter password:
ERROR:
ORA-01017: invalid username/password; logon denied
#>alter user account scott unlock;
SP2-0640: Not connected
#>alter user scott identified by tiger;
SP2-0640: Not connected
Here I reconnect and then issue an alter user command to unlock the user account and set a new password.
#>conn system#db as sysdba
Enter password:
Connected.
SYS#db>ALTER USER scott IDENTIFIED BY tiger ACCOUNT UNLOCK;
User altered.
SYS#db>conn scott/tiger#db
Connected.
Addendum
My steps provided assumed you had the scott schema installed. If the scott schema does not exist, it would be good to see if the default 11g database sample schemas exist.
The schema account scott is no longer a default schema in the 11g database. The 11g documentation states:
"Oracle used the schema SCOTT with its two prominent tables EMP and
DEPT for many years. With advances in Oracle Database technology,
these tables have become inadequate to show even the most basic
features of Oracle Database and other Oracle products. "
I would recommend reviewing to see if the other default sample schemas are installed. The hr account is most similar to the scott schema.
Here is a list of common sample schema usernames:
username IN (
'HR',
'OE',
'PM',
'SH',
'IX'
)
Check to see if the person whom performed the installation used the database configuration assistant and opted to install the sample schemas.
If the schemas were not created at the time of installation, the document, "Oracle® Database Sample Schemas 11g Release 1 (11.1) B28328-03", describes the steps to do this in chapter 2, Installation.
Open Oracle sql developer.
In the sql developer paste the path of scott.sql file(C:\oraclexe\app\oracle\product\11.2.0\server\rdbms\admin\scott.sql) with '#' infront of it.
# C:\oraclexe\app\oracle\product\11.2.0\server\rdbms\admin\scott.sql
Run script
Script Output -> Connection created by CONNECT script command disconnected
Connect using SQL Command Line
conn scott/TIGER;

Resources