If you could assist with a query that returns number of end-users accessing the application.
The below query returns only the sessions
SQL> select count(*) from v$session where status='ACTIVE';
COUNT(*)
----------
67
SQL> select count(*) from v$session;
COUNT(*)
----------
140
Related
How to create a temporary table in oracle without knowing the number and name of columns.
For example:
Select columnA,columnB,* into temp_table from tableA.
Here,tableA maynot be a simple tablename but maybe derived from many queries.
How can this be achieved?Is there any alternative to this?
In Oracle, you have to first create a table, then insert into it. Or, create it directly (as in my example).
Note that I've created a "normal" table; if it were temporary, you could have chosen between a global or private (depending on database version you use).
For this discussion, I guess that it is just fine:
SQL> create table temp_table as
2 select a.*
3 from (select d.deptno, d.dname, e.ename --> this SELECT is your "tableA"
4 from emp e join dept d
5 on e.deptno = d.deptno
6 where job = 'CLERK'
7 ) a;
Table created.
SQL> select * from temp_table;
DEPTNO DNAME ENAME
---------- -------------------- ----------
10 ACCOUNTING MILLER
20 RESEARCH SMITH
20 RESEARCH ADAMS
30 SALES JAMES
SQL>
Alternatively, create a view and work with it:
SQL> create or replace view v_temp as
2 select d.deptno, d.dname, e.ename
3 from emp e join dept d
4 on e.deptno = d.deptno
5 where job = 'CLERK'
6 ;
View created.
SQL> select * from v_temp;
DEPTNO DNAME ENAME
---------- -------------------- ----------
10 ACCOUNTING MILLER
20 RESEARCH SMITH
20 RESEARCH ADAMS
30 SALES JAMES
SQL>
This statement creates temp_table which contains all columns and data from tableA and two other empty columns, varchar and numeric.
create table temp_table as
select cast (null as varchar2(10)) columnA,
cast (null as number(6)) columnB,
tableA.*
from tableA
If you need only structure, no data, then add:
where 1 = 0
I am not sure why you want to have a temp table as you do not know columns, but you can think of dynamic SQL to create table depending on columns required during your process and then drop it again. From my point of view I think it is not a good design.
I can suggest to think on using collection with 'x' number of columns with datatype as VARCHAR2. During transaction you can populate and process according to you need and it will also remain for that session.
When query the following table it returns zero records.
SQL> select count(*) from HZ_CUST_SITE_USES;
COUNT(*)
----------
0
SQL>
can you please help me some one
Per My Oracle Support (Doc ID 787677.1), You Have a Security Policy Enabled on the APPS Owned Synonym
This is a standard set-up associated with APPS#ERP owned synonyms in an Oracle R12 environment.
First, confirm that the APPS#ERP owned synonym when queried without setting an org specific security policy context will result in an empty set:
APPS#ERP>SELECT COUNT(1) FROM HZ_CUST_SITE_USES;
COUNT(1)
0
Next confirm that a security policy has been applied to this APPS#ERP owned synonym:
APPS#erp>SELECT object_name,
2 policy_group,
3 policy_name,
4 PACKAGE,
5 FUNCTION,
6 sel,
7 enable
8 FROM dba_policies
9 WHERE object_name = 'HZ_CUST_SITE_USES';
OBJECT_NAME POLICY_GROUP POLICY_NAME PACKAGE FUNCTION SEL ENABLE
HZ_CUST_SITE_USES SYS_DEFAULT ORG_SEC MO_GLOBAL ORG_SECURITY YES YES
Just confirm that the object type is a synonym:
APPS#erp>SELECT owner,
2 object_name,
3 object_type
4 FROM DBA_OBJECTS
5 WHERE 1 =1
6 AND OBJECT_NAME = 'HZ_CUST_SITE_USES';
OWNER OBJECT_NAME OBJECT_TYPE
APPS HZ_CUST_SITE_USES SYNONYM
Query the APPS#ERP view associated with the AR owned table, HZ_CUST_SITE_USES_ALL:
APPS#erp>--APPS owned view r12.2
APPS#erp>SELECT ORG_ID, COUNT(1) FROM HZ_CUST_SITE_USES_ALL GROUP BY ORG_ID;
ORG_ID COUNT(1)
123 458
456 2658
789 1210
Once the context is set for a session (org_id is 456), one can query results for that org_id:
APPS#erp>--set policy
APPS#erp>EXEC mo_global.set_policy_context('S', 456);
PL/SQL procedure successfully completed.
APPS#erp>SELECT COUNT(1) FROM HZ_CUST_SITE_USES;
COUNT(1)
2658
I have used mysql database in my application, but I want to migrate to Oracle.
The problem is in that query:
select * from users limit ?,1;"
That query returns every row one by one depending on ?.
How can i do that in oracle?
On Oracle 12c, you could use the row limiting feature using FETCH FIRST clause.
SQL> SELECT empno, sal, deptno FROM emp ORDER BY empno DESC
2 FETCH FIRST 1 ROWS ONLY;
EMPNO SAL DEPTNO
---------- ---------- ----------
7934 1300 10
SQL>
Prior 12c solution is ROWNUM, however, if you want the row to be first sorted, then you need to do it in a sub-query -
SQL> SELECT empno, sal, deptno FROM
2 ( SELECT * FROM emp ORDER BY empno DESC
3 ) WHERE ROWNUM = 1;
EMPNO SAL DEPTNO
---------- ---------- ----------
7934 1300 10
SQL>
If the order doesn't matter to you, if you just want any random row, simply use ROWNUM.
Depending on your requirement, you could also use ANALYTIC functions such as ROW_NUMBER, RANK, DENSE_RANK.
select * from (select rownum r, u.* from users u ) where r=1;
or if you want it sorted (replace x by columnnumber or columnname):
select * from (select rownum r, u.* from users u order by x) where r=1;
After creating the partition and added rows to the table in oracle. NUM_ROWS are not showing the expected answer?
SQL> SELECT num_rows, partition_name,table_name FROM DBA_TAB_PARTITIONS
WHERE table_name='AUDITS';`
NUM_ROWS PARTITION_NAME TABLE_NAME
---------- ------------------------------ ------------------------------
P2 AUDITS
P3 AUDITS
SQL> SELECT count(*) FROM audits;
COUNT(*)
----------
98
SQL>
`
If you view the oracle documentation for ALL_TABLES, you will see this note
Note:
Columns marked with an asterisk (*) are populated only if you collect statistics on the table with the DBMS_STATS package.
and further down,
NUM_ROWS*
There is no such note for DBA_TAB_PARTITIONS, but I think it should be the same.
In SQL server I can print out the value of something with a select statement.
SELECT 'xyz'
SELECT GetDate()
Can I do something similar in Oracle without adding FROM <tablename>?
This is the purpose of the dual table. Oracle supplies the Dual in every database and it's accessible, by default, to everyone that connects. It's a single-row, single column table that is useful for testing expressions and pseuducolumns against. Example
SELECT 'xyz' from dual;
SQL> select user,sysdate,lower(user) loweruser, 10*1023 from dual;
USER SYSDATE LOWERUSER 10*1023
---------- ---------- ---------- ----------
NKODNER 22-NOV-11 nkodner 10230
There is a dual dummy table in Oracle, so try:
SELECT GetDate() FROM dual
You can't. You must use DUAL fictious table
To get current system date, you would type
SELECT SYSDATE FROM DUAL