:APP_USER usage in SQL query. Oracle Application Express (Apex) 5.0.4 - oracle

I want to use session variable :APP_USER in query in selection database statement like this:
select * from :APP_USER.data
I have users john.doe and johny.b.
I have table john.doe.data and i want to get all data from this table. Also i have table johny.b.data and when johny.b will login in, I want to get data from table johny.b.data.
I hope you understand my plan, so it is like every user have own data table and I want to display table according to logged in user. What will be the right way to do this?

I would say this would be possible but shouldn't be done. You'd be better off doing select * from apex_user.table (prefix not needed) where column = :APP_USER and having them all in one big table or having a different table (but same apex_schema) per user. How you'd go about creating this table is up to you - you could select a pseudo-table from dual and then only create it when necessary to prefent any table not found issues.
You'll no doubt run into tablespace permission issues down the line or worse - give the apex user more security permissions than it requires if you go down your intended route which will make exporting and importing a nightmare.

Related

Oracle: Query table in tablespace

I have a tablespace, ts, that contains table1.
How do I query the contents of table1?
I've tried the following without success:
SELECT COUNT (*)
FROM table1
WHERE tablespace_name = 'ts';
2 tablespaces were created for our application. The application created 3 users, admin, user and read_only and created the required tables etc in the 2 created tablespaces. The issue I'm going to run into is that more than 1 instance of the application is going to connect to Oracle 19c and I need to be able to query the tables on each tablespace for each instance of our application.
Each of the three users can have tables in either or both tablespaces. Once a table has been created it usually doesn't matter much which tablespace it is in - that is an administration issue, not something users generally need to be aware of.
All of the users can all have tables with the same names. That's fine. Each table will belong to a user (schema), and the names have to be unique within that schema, but not globally.
I fear all instances of our application will write to the same tables.
There are a couple of basic approaches.
Each instance of the application can connect as a different user and look only at that user's tables. If the connection is made as admin then select * from table would return data from admin's version of the table.
Each instance could connect as the same user, which owns no tables itself, and then specify which other user's (schema's) tables it wants to access. It can do that by querying say select * from admin.table1, or as part of the connection set-up do alter session set current_schema = admin and then just select * from table1 will look as admin's table by default.

ORA-00942: Table or View not exist connecting with another user

in Oracle SQL developer I got error ORA-00942: Table or View not exist connecting with another user when I do the following:
CREATE USER marta IDENTIFIED BY 'marta';
GRANT SELECT, INSERT ON myTable TO marta;
so then, executing:
CONNECT marta/marta;
INSERT INTO myTable VALUES ('1', 'foo', bar');
got the ORA-00942...
Obviusly, If I use system user I can insert row with no issues.
I searched other answers but I couldnt solve this... what is wrong
Obviusly, If I use system user I can insert row with no issues.
Uh-oh. There's nothing obvious about that. The SYSTEM user should not own a table called MY_TABLE (or whatever application table that is actually named). The SYSTEM user is part of the Oracle database, its schema is governed by Oracle and using it for our own application objects is really bad practice.
But it seems you have created a table in that schema and user MARTA can't see it. That's standard. By default users can only see their own objects. They can only see objects in other schemas if the object's owner (or a power user) grants privileges on that object to the other user.
So, as SYSTEM
grant select on my_table to marta;
Then, as MARTA
select * from system.my_table;
To avoid prefixing the owning schema MARTA can create a synonym:
create or replace synonym my_table for system.my_table;
select * from my_table;
But really, you need to stop using SYSTEM for your own tables.

How to configure jenkins to choose the schema by default?

I get the a query file and commit it but I have to choose the schema before it, to not get the following error; do you have any idea how to do it?
Thanks for your interest.
INSERT INTO LEAD_ACTV_CONFIG (
*
ERROR at line 1:
ORA-00942: table or view does not exist
I don't know jenkins so I hope the following makes sense. Sorry if it does not.
In order for INSERT to work, you must be connected to a database (i.e. one of its users). That user should contain LEAD_ACTV_CONFIG table, or it must be available to it (which means that some other user, who owns it, has granted the current user access privileges).
Now, if LEAD_ACTV_CONFIG is your own table, then your INSERT INTO would work properly; you don't need any additional privileges as you own the table so you can do anything with it.
If it is someone else's table, then either precede table name with owner name, such as INSERT INTO littlefoot.lead_actv_config (as if I own it), or create a synonym for that table in your schema:
create synonym lead_actv_config for littlefoot.lead_actv_config;
and access it just as you've posted in your question: insert into lead_actv_config

List of usernames in oracle

I need to get a list of all users and their tables and details.
For Example : https://www.google.com/search?q=oracle+user&source=lnms&tbm=isch&sa=X&ved=0ahUKEwi-td2pjcPMAhXEFh4KHdMAAVcQ_AUIBygB&biw=1175&bih=621#tbm=isch&q=oracle+user++sql+developer&imgrc=Qvmfp57HchgwgM%3A
In the above screen towards left there is red color symbol (User) , SO i need the username, associated tables(under that user) and atrributes in that table. Is this possible. for all users.
Thanks
Addy
ALL USERS, ALL TABLES, 'and details'
So do you really want ALL the users? Because many users are system users - users that own objects that the database itself uses, SYS being the biggest example. You could have dozens of these accounts. I'm guessing you don't want them.
All tables, tables in the recycle bin, tables there for materialized views, do you want those too?
And 'details'. Do you want their created date, their columns, their storage parameters? The more you want, the bigger and uglier your query is going to get.
All that being said, you pointed to a screenshot of Oracle SQL Developer. It contains a data modeling feature. Use it. Reverse engineer the users you really want into a data model. And then use the data dictionary reports it offers to give you the info you want.
You have to figure out what you REALLY want first though.
I talk about how to do the RE in the data modeler here.
You can start from this:
select *
from dba_tables t
inner join dba_tab_columns
using(owner, table_name)
This will give all the tables and columns, with some informations about tablespace, the type of the columns, and so on
This shows all the users and all their tables except for SYS and SYSTEM
SELECT owner, table_name
FROM All_All_Tables
WHERE owner NOT IN ('SYS','SYSTEM')
ORDER BY 1,2
Runs on Oracle 10, 11

What happened to my table in my oracle database?

I have a situation where yesterday my code was working ok, but today I find that my code fails because a SQL query fails on my Oracle database. The query fails because the table used in the query does not exists. I am no Oracle expert so I am reaching out to you Oracle experts out there. Is there a way to see in a log file or log table when my table disappeared and who dropped my table?
Thanks
Depending on previous configuration one would hope that a production database would have auditing turned on. Try
select * from sys.AUD$
The audit table can log almost every user action including dropping tables or revoking grants but has to be configured.
Assuming you have the recyclebin turned on in your database, you might be able to restore the dropped table. As the user who owns the table, you can run this query:
select * from USER_RECYCLEBIN
or if you have SYS access you can check the query:
SELECT * from DBA_RECYCLEBIN;
Then as a user owns the table, run this FLASHBACK command to restore it:
FLASHBACK TABLE <your table name> TO BEFORE DROP;
If you get ORA-38305 you might have a tablespace issue - either run it as a different user or make sure it using a locally managed tablespace.

Resources