GRANT SELECT ON view TO user using script on SQL developer, than SELECT * FROM that view in SQL Plus - oracle

My script on SQL dev:
**CREATE USER C##DG IDENTIFIED BY abc123;**
**CREATE VIEW DG1_VIEW**
AS SELECT m_pms.MaPMS, m_pms.MaDG, m_pms.SoLuong, m_s.MaSach, m_s.TenSach, m_ctpm.SL
FROM PhieuMuonSach m_pms, ChiTietPhieuMuon m_ctpm, Sach m_s
WHERE m_pms.MaDG = 1 AND m_pms.MaPMS = m_ctpm.Ma_PMS AND m_ctpm.Ma_Sach = m_s.MaSach**;**
**GRANT CREATE SESSION TO C##DG;
GRANT SELECT ON DG1_VIEW TO C##DG;**
On Sql Plus, i logged in as C##DG, typed '''SQL> SELECT * FROM DG1_VIEW;'''
and received 'ORA-00942: table or view does not exists'. But this view already had data.
What is my problem and how to fix it? I'd love to hear from you guys.

You need to either specify schema this view has been created in
select * from system.dg1_view;
or you may login as system again and create a public synonym for that view in order to make it available without specifying schema

Related

I found a function on DBViewer, but it doesn't present on PL/SQL

I'm new to PL/SQL and DBView.
I got below log after doing some action on front end application.
When I want to check on PL/SQL function/ procedure/ package, I can't find it using "find database objects" fiture.
Command : { ? = call ap_val_sb_prod_code (?,?,?,?,?,?)
I/P 1 is : 615
I/P 2 is : 9222
I/O 11 is 0
Please help.
You didn't say how you tried to find it.
Generally speaking, if it is your own schema, you'd query USER_OBJECTS, e.g.
select * from user_objects where upper(object_name) = 'AP_VAL_SB_PROD_CODE';
If you have privileges to view other users' objects, then query ALL_OBJECTS instead:
select * from all_objects where upper(object_name) = 'AP_VAL_SB_PROD_CODE';
Finally, to check the whole database, query DBA_OBJECTS (but you have to have privileges to do that):
select * from dba_objects where upper(object_name) = 'AP_VAL_SB_PROD_CODE';

Error ORA-00933 on create editioning view

I'm trying to create an editioning view in Oracle 11g and it's giving the error "ORA-00933 SQL command not properly ended", I ran it with the owner of schema and sys, but the error persists.
CREATE OR REPLACE FORCE EDITIONING VIEW "CEGASV3"."VE_COML_FACTIVEL"(
"PK_FACTIVEL", "FACTIVEL", "ENDERECO", "NOMECONTATO", "TELCONTATO01", "TELCONTATO02",
"EMAIL", "SEGMENTO", "DT_DIGIT", "RESPONSAVEL", "INFOUTEIS", "NOME_TABELA_HISTORICO",
"DATA_HORA","VPD_GEMPI","ORA_GEOMETRY","ORA_GEOMETRY_GOOGLE","STATUS"
) AS
SELECT F.PK_FACTIVEL, F.FACTIVEL, F.ENDERECO, F.NOMECONTATO, F.TELCONTATO01, F.TELCONTATO02,
F.EMAIL, F.SEGMENTO, F.DT_DIGIT, F.RESPONSAVEL, F.INFOUTEIS, F.NOME_TABELA_HISTORICO,
F.DATA_HORA, F.VPD_GEMPI, F.ORA_GEOMETRY, F.ORA_GEOMETRY_GOOGLE, F.STATUS
FROM CEGASV3.COML_FACTIVEL F
LEFT JOIN CEGASV3.COML_PROSPECT P ON P.FK_FACTIVEL = F.PK_FACTIVEL
WHERE P.PK_PROSPECT IS NULL;
You can not create complex view as editioning view. It means you can not use multiple tables as a query of the view, It must be a single table view.
Editioning views are a wrapper over the base table. It can only be a
straight query of the base table, but can display a subset of the
columns and give alias to them.
Read more about editioning view here.
Cheers!!

Access union all into new table

I have a saved query (MyUnion) for a union, appending monthly files (linked views):
select * from RawTrade1801
union all
select * from RawTrade1802
Trying to write this to a new table is proving problematic:
SELECT MyUnion.* into RawTrade2
FROM MyUnion
WHERE Field8 = 'ZAR';
I get an error: Cannot open database "
My aim is to once a month create a master table by appending every monthly file.
The following steps should generate a table from your UNION query:
Create a new query. In the SQL View, now type:
SELECT * FROM (SELECT * FROM RawTrade1801
UNION ALL
SELECT * FROM RawTrade1802);
Save the query. In its Design View click the Make Table button. Type in the table name (e.g. NewTable) that you want the output of this query to be.
Save and close the query.
The query icon will have changed. Double click on it and it should generate your table.
Access actually changes the SQL to
SELECT * INTO NewTable FROM
(SELECT * FROM RawTrade1801
UNION ALL
SELECT * FROM RawTrade1802) AS [%$###_Alias];
when you view the SQL after step 4.
Try using INSERT INTO ... SELECT:
INSERT INTO RawTrade2
SELECT * FROM RawTrade1801 WHERE Field8 = 'ZAR'
UNION ALL
SELECT * FROM RawTrade1802 WHERE Field8 = 'ZAR';
Of course, even if this works it still does not explain why your original query does not work. I expect it is a slight technical problem, though I don't know enough Access to see it immediately.
Create the Union query, save it with the name like 'qUnion'.
From menu open:
Create-->Query--> Make Table.
In Add Table Menu chose "Queries" and
Add your union query ('qUnion').
Select the fields that you need.
Open query.
Anew table will be created.

DBA_HIST_ACTIVE_SESS_HISTORY get sql by user and object schema

Hi I am learning ASH and AWR tables but any ideas as to how i can get list of sql, objects and schema owner accessed by a give user in last 30 days ? Basically get all SQL text, and then search within this SQL to see if a given object (table, package, function, view etc ) is accessed for a given schema and by which user ? Any ideas suggestion on where and how to start ?
You could join the following views -
DBA_HIST_ACTIVE_SESS_HISTORY
DBA_USERS
DBA_HIST_SQLTEXT
To filter the history for last 30 days, use sample_time of DBA_HIST_ACTIVE_SESS_HISTORY view.
Something like -
SELECT
h.sample_time,
u.username,
h.program,
h.module,
s.sql_text
FROM
DBA_HIST_ACTIVE_SESS_HISTORY h,
DBA_USERS u,
DBA_HIST_SQLTEXT s
WHERE sample_time >= SYSDATE - 30
AND h.user_id=u.user_id
AND h.sql_id = s.sql_iD
ORDER BY h.sample_time
/
The very best and simplest way to fetch related data using below query.
SELECT H.SAMPLE_TIME,
U.USERNAME,
H.PROGRAM,
H.MODULE,
S.SQL_TEXT,
H.SQL_ID,
H.TOP_LEVEL_SQL_ID,
H.BLOCKING_SESSION_STATUS
FROM DBA_HIST_ACTIVE_SESS_HISTORY H, DBA_USERS U, DBA_HIST_SQLTEXT S
WHERE H.SAMPLE_TIME >= SYSDATE - 30
AND H.SQL_ID = S.SQL_ID
--AND H.PROGRAM IN ('Toad.exe', 'SQL Developer')
--AND U.USERNAME ='YOUR_USERNAME'
ORDER BY H.SAMPLE_TIME DESC
In the above code you can also fetch data based on your requirements as below.
1. Custom user data: Just modify YOUR_USERNAME with your real username.
2. Program: Program name can be anything like SQL Developer or JDBC Thin client to identify from which client the queries are getting triggered, but optional.
Hope it will help and answer to your question. Thanks :)

Oracle select schema depending on select-statement

I have have two schemas with the same table. e.g schema1.adress and schema2.adress.
Both tables are identical.
Layout of table customer:
customerno: integer
name: varchar2(50)
Now I want to get the customers of schema 1 using something like
"select * from customer where schemaname = 1" or
"select * from customer where schemaname = 2"
Is there a mechanism in Oracle that can switch the schema depending on a criteria in a select-statement?
Before you ask: for a new project I have to query legacy schemas. I cannot change the schema, but I can set any permission on the schema / user.
Any ideas?
Thanks for any response,
Sven
You could create a private synonym for the user for the schema.table you want them to access,
create synonym user1.customer for schemaname1.customer;
create synonym user2.customer for schemaname2.customer;
Then your queries would always just be select * from customer;
So you are logged in as the same user both when you want to select from schema1.customer and select from schema2.customer?
A possible way can be something like:
select *
from (
select 'schema1' schema$name, c.* from schema1.customer c
union all
select 'schema2' schema$name, c.* from schema2.customer c
)
where schema$name = 'schema1'
If you can create views, it can be an idea to create a view like:
create or replace view customer_view as
select 'schema1' schema$name, c.* from schema1.customer c
union all
select 'schema2' schema$name, c.* from schema2.customer c
That makes it possible to do:
select *
from customer_view
where schema$name = 'schema1'
Whether you use view or not, Oracle optimizer can in most cases like this push the predicate "where schema$name = 'schema1'" into the UNION ALL and then it recognizes that it does not need to access schema2.customer at all.

Resources