Oracle - unable to create DB link - oracle

I am unable to create the DB link as it's throwing ORA - 01031 insufficient privileges error.
Let's say I have database DB1 and schema name as s1 and second database as DB2 with schema t1.
I am trying to create the DB link by sysdba user by running below -
alter session set current_schema=s1;
Create database_link dblinkname connect to t1 identified by password using DB2;
But this is giving me error. I tried giving privileges also to s1 but no luck. Any leads. I don't have the schema password for s1 and I can't reset it as it's production environment.

I had the same issue a several years ago.
Assuming, you don't want to create a public database link...
You can do this:
Grant privilege create database link to target schema.
Create a stored procedure in your target schema, which creates database link per execute immediate
Call this procedure
Finally drop this procedure.

Related

Oracle Role for liquibase user

I am working on adding liquibase in my spring boot app which connects to an oracle DB. I don't feel comfortable using the schema ID in my application. So I would like to create another user id that will be used to connect to the DB from my app. Since I am using liquibase this new user id will need to have create, drop, select, insert, update, delete on all table in that schema.
In Mysql I can ran the following command:
GRANT CREATE, DROP, SELECT, INSERT, UPDATE, DELETE ON SCHEMA_NAME.* TO 'liquidbase_local_usr'#'localhost';
is there a similar query in Oracle?
I did this with the Datical product that was built on Liquibase.
First I created a role called DATICAL_PACKAGER_ROLE and assigned it to the user $DaticalUser:
CREATE ROLE DATICAL_PACKAGER_ROLE NOT IDENTIFIED;
-- When using the tracefileLocation=REMOTE, you will need to setup the following permissions.
-- Note: These permissions are only required on schemas running the Convert SQL Scripts command. This is only needed on the packaging / reference database.
GRANT EXECUTE ANY PROCEDURE TO DATICAL_PACKAGER_ROLE;
GRANT ALTER SESSION TO DATICAL_PACKAGER_ROLE;
GRANT CREATE ANY DIRECTORY TO DATICAL_PACKAGER_ROLE;
GRANT DROP ANY DIRECTORY TO DATICAL_PACKAGER_ROLE;
-- The following permissions are needed for backing up and restoring the database. This is only needed on the packaging / reference database.
GRANT EXP_FULL_DATABASE TO DATICAL_PACKAGER_ROLE;
GRANT IMP_FULL_DATABASE TO DATICAL_PACKAGER_ROLE;
-- The following must be run as sysdba
-- SQL > conn / as sysdba
GRANT EXECUTE on SYS.UTL_FILE TO DATICAL_PACKAGER_ROLE;
-- Grant the new role to the Datical User
GRANT DATICAL_PACKAGER_ROLE to $DaticalUser;
Then I granted the role to the schema I wanted:
GRANT DATICAL_PACKAGER_ROLE to <yourschema>;

How to query tables and pull data into an Oracle APEX application from another schema?

I am working in an Oracle APEX application and am trying to query tables in another schema (that another Oracle APEX application sits on) to pull in data to my application.
The applications are hosted within the same APEX workspace and on the same Oracle 11g instance. Our application have tables that are structurally the same as the tables we're trying to query in the other schema.
Using the schema prefix (SELECT * FROM "SCHEMA2".TABLE1;) when querying is throwing an error that the tables do not exist (ORA-00942: table or view does not exist)
The second thing I tried is creating a database link between the two schemas, but when trying to establish the connection I'm getting the following error: ORA-01031: insufficient privileges
Can someone identify where I'm going wrong here / help me figure out how to query the other schema?
Database link is used when there are different databases involved; your schemas reside in the same database which means that the first attempt was correct: prefixing table name with its owner, e.g.
SELECT * FROM SCHEMA2.TABLE1
However, first connect as schema2 user and issue
grant select on table1 to schema1;
Otherwise, schema1 can't see the table. If schema1 is supposed to do something else with that table, you'll have to grant additional privileges, such as insert, update, delete, ....

How to create a database in Oracle using JDBC?

I want to create a new database on an Oracle server via JDBC. I cannot seem to connect to the database without providing an SID: using a URL like jdbc:oracle:thin:#//[IP]:1521 results in an error of "ORA-12504, TNS:listener was not given the SID in CONNECT_DATA"
Alternatively, if I log into a specific SID, I can run most DDL commands except for CREATE DATABASE foo which fails with an error of "ORA-01100: database already mounted"
How am I supposed to create a database if I cannot connect to the server without specifying a specific database and cannot create a database if I am already logged into a specific database?
AFAIK creating a database needs an internal and direct connection which can only be done by logging in directly on the server (normally a user account called 'oracle').
One reason for that: users are stored in the database itself. No database = no user to connect to by an external client.
Please also note Justin's comment about oracles database schemas. This is probably what you are looking for
What you need are following commands:
CREATE TABLESPACE CREATE USER and few GRANT ... TO ... -- to have rights to connect and create objects, at least

Oracle Global Temporary table - Privileges for other instances

I have created Global Temporary table in oracle and inserting the data through my application, and its working fine for me when i connect to database with "system" as the username. Where as i have created one more user in the database with "user1" and have given "Grant all" privileges to this user also. Now when am connecting to database with "User1" as the username and running the application, the data is not inserting into Global temporary table.
But when i try to insert data from sql developer tool its inserting.
With system user through application also working, whereas with user1 its not inserting. Am not getting whats behind going as am not that much DB expert.
Please have any idea suggest me. I have all privileges also. Thanks in advance.
Fist, the table MUST be in other schema than SYS or SYSTEM. Create it on "User1".
Second, you must be sure that you select from the same table. Prefix the table with the schema when inserting and also when reading.
Also be sure that you are not in the situation of table created with ON COMMIT DELETE ROWS and some AUTOCOMMIT ON in Sql Developer.

Oracle XE Suit - Where's the ON switch?

I'm not a DBA, but I have some basic understanding about how SQL Server is supposed to work. I'm having trouble translating this knowledge into getting a working Oracle XE database, so my girlfriend can play around with her bookstore coursework.
So, I installed Oracle XE database, and downloaded Oracle SQL Developer. I supplied a password, during installation, and using this password in conjunction with sys login in sysdba-mode, I'm able to connect and browse the database, which I can only assume is the master database, since there are numerous tables that have nothing to do with future bookstores.
I want to create a new - empty database, and I don't much care about how it's configured. It's a playpen for coursework. So I happily stab with:
create database bookstore
and recieve an error to the effect of:
ORA-01100: database already mounted
I just want to create a new database, so that if something goes wrong i can do a drop database bookstore instead of manually deleting tables and such. In SQL Server Management Studio you execute these statements on the master database, and then connect to the specific database you want to play with.
A SQL Server database is roughly equivalent to a schema in Oracle. And a schema in Oracle is a collection of objects owned by a particular user.
Given that, it appears that you want to do something like
Create a user
CREATE USER bookstore IDENTIFIED BY bookstore;
Grant privileges to the user
GRANT CREATE SESSION TO bookstore;
GRANT UNLIMITED TABLESPACE TO bookstore;
GRANT CREATE TABLE TO bookstore;
GRANT CREATE VIEW TO bookstore;
GRANT CREATE TYPE TO bookstore;
GRANT CREATE SYNONYM TO bookstore;
GRANT CREATE PROCEDURE TO bookstore;
GRANT CREATE SEQUENCE TO bookstore;
GRANT CREATE MATERIALIZED VIEW TO bookstore;
Now, you should be able to connect to the bookstore schema in the XE database and create whatever tables, views, triggers, etc. you want.
You just need to create a schema in the database you already have. A schema in Oracle is sort of roughly equivalent to database in SQL Server, in some ways. Your girlfriend would use that schema as her playpen and you could drop it and recreate it easily. You should also create a user for her, which I think automatically creates a schema with same name as the user. But I would still create a dedicated coursework schema.
Oracle has extensive online documentation. Here's the master index for 10g. It's a bit daunting but you'll get to know your way around it.

Resources