Finding constraints enforced across multiple tables in oracle [closed] - oracle

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have a database with the following tables EMP, DEPT, CLIENT and PURCHASE. I am using Oracle 11g express edition
I have executed the following SQL statement to find out constraints on table : EMP
SELECT * FROM USER_CONSTRAINTS WHERE TABLE_NAME = 'EMP'
Is there a way to find out what constraints are currently enforced upon this database across multiple table in one statement?
E.g. EMP AND CLIENT AND etc something like that.

You might try something like
SELECT *
FROM USER_CONSTRAINTS
ORDER BY TABLE_NAME,
CONSTRAINT_NAME
which will let you browse through all constraints in the database. If you've got a subset of tables you're interested in you can toss in a WHERE clause such as
SELECT *
FROM USER_CONSTRAINTS
WHERE TABLE_NAME IN ('EMP',
'CLIENT',
'OTHER_TABLE',
'OTHER_TABLE2',
'YET_ANOTHER_TABLE')
ORDER BY TABLE_NAME,
CONSTRAINT_NAME
or
...
WHERE TABLE_NAME = 'EMP' OR
TABLE_NAME = 'CLIENT' OR
TABLE_NAME = 'OTHER_TABLE' OR
TABLE_NAME = 'OTHER_TABLE2' OR
TABLE_NAME = 'YET_ANOTHER_TABLE'
...
The two WHERE clauses above are equivalent - the first is just a bit more compact.
Share and enjoy.

Related

Select data from 2 tables and match on 2 fields (oracle sql developer) [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have two tables
TABLE1
-DATADATE
-ISIN
-INDEXNAME
TABLE2
-AS_OF_DATE
-ISSUER_ISIN
-GPSCORE
-SPSCORE
I would like to merge the two tables by matching on:
AS_OF_DATE = DATADATE
and
ISIN = ISSUER_ISIN
Try this one:
SELECT * FROM TABLE1 tb1
INNER JOIN TABLE2 tb2
ON tb1.DATADATE = tb2.AS_OF_DATE
AND tb1.ISIN = tb2.ISSUER_ISIN

How to identify unused tables from the oracle database [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a production database with 1500 tables. Want to cleanup few tables that are created for testing purpose. Is there any process to identify unused tables.
Note: Auditing is not enabled in the database
You need to take snapshots of v$segment_statistics on a regular basis and then compare the data over time.
Something like:
create table usage_statistics
(
as_of timestamp,
table_name varchar(30),
table_owner varchar(30),
num_logical_reads number,
num_physical_reads number,
num_full_scans
);
Then create e.g. a cron or dbms_scheduler job to run the following
insert into usage_statistics (as_of, table_name, table_owner, num_logical_reads, num_physical_reads, num_full_scans)
select current_timestamp,
object_name,
owner,
sum(case when statistic_name = 'logical reads' then value end),
sum(case when statistic_name = 'physical reads' then value end),
sum(case when statistic_name = 'segment scans' then value end),
from v$segment_statistics
where owner in ('USER_NAME_1', 'USER_NAME_2')
and object_type = 'TABLE'
group by object_type, object_name
order by object_type, object_name;
Of course you will need to adjust the names of the owners you want to monitor.
The above statement only checks for three statistics. Use the view V$SEGSTAT_NAME to see a list of all available statistic names in v$segment_statistics
Then after a while you can compare the changes in the reads for each table.
I started from this:
select table_name, last_analyzed
from user_tables
order by last_analyzed desc;
select table_name, last_analyzed
from all_tables
order by last_analyzed desc;
I ask programmers and I droped the oldest tables.

why inline view is different from other views?what is the use of naming it as a view [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
As i know inline view is not a database object and it is just like writing a sub query in from clause so what is the use of naming it as a view .Simply we can call as a sub query.
It is Oracle naming convention. From Inline View and Subquery:
An inline view is a SELECT statement in the FROM-clause of another SELECT statement. In-line views are commonly used to simplify complex queries by removing join operations and condensing several separate queries into a single query.
This feature is commonly referred to in the MSSQL community as a derived table, and in the Postgres community simply refers to it as a subselect (subselects are inline views + subqueries in Oracle nomenclature).
A subquery (sub-query) is a SELECT statement in the WHERE- or HAVING-clause of another SELECT statement.
So when you used it with FROM it is called inline view:
SELECT *
FROM ( SELECT deptno, count(*) emp_count
FROM emp
GROUP BY deptno ) emp,
dept
WHERE dept.deptno = emp.deptno;
And when you used it with WHERE/HAVING it is called subquery:
SELECT ename, deptno
FROM emp
WHERE deptno = (SELECT deptno
FROM emp
WHERE ename = 'TAYLOR');

Unable to insert date to table [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to insert a date into oracle table using below
SQL> insert into temp (tst,thistime) values ('test3',TO_DATE('MM/DD/YYYY HH24:MI
:SS','01/01/2014 16:45:45') );
but its giving below error
ERROR at line 1:
ORA-01821: date format not recognized
Below is the description of table
SQL> describe temp;
Name Null? Type
----------------------------------------- -------- ---------------------------
TST VARCHAR2(10)
THISTIME DATE
Use the insert . . . select form of insert:
insert into temp (tst, thistime)
select 'test3', TO_DATE('01/01/2014 16:45:45', 'MM/DD/YYYY HH24:MI:SS')
from dual;
In addition to having the arguments backwards for to_date(), values doesn't evaluate expressions that belong in a select statement.

Convert Row into columns [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
how can I convert rows of my table as column value
for eg I have a table a
emp id
1
2
3
4
and I want my output as
1 2 3 4
i am also using pivot in oracle and crosstab in postgres but not able to get desired solution as shown above.
Check the listagg function. Note you need at least Oracle 11 for this.
Use this script and change it to your values to get desired results
SELECT * FROM (SELECT emp_id, emp_points
FROM emp_data)
PIVOT (
SUM(emp_points) AS sum_emp_points
FOR (emp_id) IN (1 AS [1], 2 AS [2],3 AS [3],4 AS [4])
);
select * from (select empno from t7) pivot(min(empno) for empno in (1,2,3,4));

Resources