Tagged Questions
3
votes
1answer
73 views
Index on foreign key makes query extremely slow
We are recently experiencing a tremendous query slowdown with spilled over temp tablespace. A specific query causes this problem.
The queried table (table3) has an indexed PK, three FK with indexes ...
0
votes
1answer
61 views
Different dates Oracle 11g with TOAD
I have the following queries:
SELECT to_date(to_char(to_date('01-FEB-1949'))) FROM DUAL;
/*this returns 2/1/2049. */
SELECT to_date(to_char(to_date('01-FEB-1949'),'dd-MON-yyyy')) FROM DUAL;
...
0
votes
1answer
51 views
Efficient way to perform approximated search?
I have to perform a join between table_a and table_b, using three fields as key being one of them the date of the event, say, both tables have id1, id2 and evnt_time for eache record.
As it happens ...
5
votes
2answers
168 views
Defining constraints in `CREATE TABLE` statements
Recently I have been using a Database Abstraction Layer built by a Python web-framework called web2py (click for their DAL syntax). They include the option to include your constraints within the ...
1
vote
1answer
69 views
Strange behaviour of a query with order by and rownum on Oracle's Exadata server
I am executing the following query on two different database servers:
SELECT start_date,
end_date,
resort_id
FROM employee_activity
WHERE employee_id = 27
AND start_date < ...
1
vote
2answers
108 views
Count events on “user based” sliding window
So, if I wanted to know how many events a certain user bought in certain timeframe windows. I will use 7 for the example, but the query should accept this number of days as a parameter, which will be ...
1
vote
2answers
223 views
Factoring out subselect (with clause) ends in ORA-00904
I am trying fo factor a repetitive subquery with with but getting ORA-00904 over and over again.
This is my base query which works quite well:
select tka.id, tka.name, txt.text as langname, ...
0
votes
1answer
156 views
Difference between chained and migrated rows
What is the difference between chained and migrated rows? Also what query should be used to display these rows? (I'm using Oracle 11gR2 database)
1
vote
2answers
286 views
Why does my query run faster after I force full table scan?
I have a MERGE statement that took forever to execute the select as the table it is running from (SUB_DATA) is rather big (read 1.4 Tb, 700 million rows). My SELECT looks like this.
SELECT ...
1
vote
0answers
90 views
Use of hash functions in group by?
I'd use a listagg() to generate a list of components a certain customer has and compare it to another list generated the same way somewhere else to detect inconsistencies. The problem is that ...
2
votes
1answer
588 views
Why Is oracle ignoring my index?
This query is not too complex:
select
trunc(created_date, 'MONTH') as created_date,
al.op_name,
al.region,
al.alarm_type,
COUNT(1) as total_new,
SUM(
(SELECT
...
3
votes
1answer
53 views
INDEX on a table where I'm only filtering on a row_number()
I've got the following table (scaled down to a MWE):
Fiddle here.
CREATE TABLE weekly
( yearnum int,
weeknum int,
location varchar2(5),
weekly_count int,
weekly_sum int);
INSERT INTO weekly ...
0
votes
1answer
53 views
Verify if I can use a given directory
Admin creates an Oracle directory:
CREATE OR REPLACE DIRECTORY EXAMPLE AS '\\server\share\test';
GRANT READ, WRITE ON DIRECTORY EXAMPLE TO JOHN;
Admin can test whether the directory exists:
SELECT ...
5
votes
2answers
4k views
Learning to Optimize SQL Queries and Understand Execution Plans - Resources?
I find myself writing more and more SQL queries at work (mostly Oracle 11g, but some SQL Server 2005-2008) and have started creating some pretty complex views for the rest of the analyst team.
They ...
1
vote
1answer
197 views
how to see multiple column values in new line [duplicate]
Possible Duplicate:
how to query multiple row data in single column in oracle?
my table structure is given bellow
deptid ename
------ ------
10 CLARK,KING,MILLER
20 ...
4
votes
3answers
4k views
Execute a script with SQLPlus containing blanks, semi-colons, and forward slashes
Occasionally I will get a script that will run fine in SQL Developer or Toad, but requires modification in order to be run successfully from SQL*Plus. Here is a worst case example containing multiple ...
1
vote
2answers
559 views
Sum values from two tables ORACLE
I want to use two values, in two different tables, to be used as a total in a third table.
For instance:
table accommodation and flight
Add value from acc_price with value from flight_price
Add ...
5
votes
2answers
113 views
Product of n Rows
From this data (assuming the number of rows is not known in advance):
with q1 as (select mod(ora_hash(level),5) c1 from dual connect by level <=4)
select * from q1;
/*
C1
--
2
1
4
1
*/
I ...
2
votes
1answer
233 views
Table Statistics Affect Index Only Query?
We have a query that was getting poor performance. The root of the problem could be reproduced using a simple query accessing only one index to retrieve one column (the indexed column) from eight ...
2
votes
1answer
241 views
Virtual Column - Using it in view (Oracle)
I have made a virtual column in Oracle, using the following code.
CREATE OR REPLACE function email_address (ID_ varchar2)
return varchar2
deterministic
as
lname varchar2 (256);
snumber varchar2 ...
2
votes
1answer
574 views
Differing results from gv$session
The following query returns no results, yet it seems like it should.
SELECT * FROM gv$session where SID = SYS_CONTEXT('USERENV','SID');
In my 11.2.0.2 Standard Edition RAC environment the above ...
2
votes
1answer
1k views
How to display a number with fixed number of digits before the decimal?
I am looking for result 0123.56 and the following query should have worked.
SQL> select to_number(123.56,'0999.99') from dual;
select to_number(123.56,'0999.99') from dual
*
ERROR ...
4
votes
1answer
3k views
oracle format specifiers: to_number vs to_char
SQL> select TO_NUMBER(123.56,'999.9') from dual;
select TO_NUMBER(123.56,'999.9') from dual
*
ERROR at line 1:
ORA-01722: invalid number
SQL> select TO_CHAR(123.56,'999.9') ...
2
votes
2answers
2k views
Why can't we specify group functions in Oracle in the where clause?
SQL> desc tab1
Name Null? Type
----------------------------------------- -------- ----------------------------
ID ...
8
votes
2answers
410 views
LNNVL Justification
LNNVL is an oracle built in function that returns TRUE for conditions evaluating to FALSE or UNKNOWN, and returns FALSE for conditions evaluating to TRUE. My question is what would be the benefit of ...
3
votes
1answer
426 views
Oracle query against SQL Server database giving inconsistent results
We have multiple Oracle 11.2.0.2 databases with og4odbc database links to a SQL Server 2008 database. A particular table in the SQL Server database has two Varchar(36) columns. The following ...
4
votes
2answers
612 views
Updating rows conditionally with a gapless ascending value
A user has a table they would like to update. Depending on the data in other columns they want a particular column to be updated with an ascending value starting from 1 that is gap-less. The rows ...
4
votes
1answer
400 views
Help with Query Tuning
EDIT - drachenstern: see this question for more information on this problem and on the source of his query below:
Group data by non-unique keys by distinct time range
Can someone please advise ...
2
votes
2answers
2k views
In Oracle, how to globally enable parallel execution?
In Oracle 11g, is there a way to tell the database to use parallel execution whenever possible by setting a flag etc, rather than using PARALLEL hints with every SQL statement?
1
vote
1answer
6k views
Where all can the /*+ PARALLEL */ hint be used?
It works with SELECT and UPDATE statements.
Are there some more statements with which it works?
I was able to use it with create, but am not sure if the hint was actually considered.
SQL> create ...
6
votes
3answers
2k views
How to differentiate between SQL and PL/SQL?
I know the question might sound too stupid, but I never understood this part.
SQL*Plus works with both SQL and
PL/SQL. How do I know whether some
code is SQL or PL/SQL? If my code has
a for ...
13
votes
9answers
16k views
Eliminate duplicates in ListAgg (Oracle)
Prior to Oracle 11.2 I was using a custom aggregate function to concatenate a column into a row. 11.2 Added the LISTAGG function, so I am trying to use that instead. My problem is that I need to ...
5
votes
1answer
578 views
Case Behavior Changed Between 11.2.0.1 and 11.2.0.2
I have a case open with Oracle and they say they can't reproduce this. Running the following in 11.2.0.1 or lower produces two rows from both of these queries, but in 11.2.0.2 the second query ...
12
votes
4answers
1k views
What is the significance of a semicolon at the end of SQL*Plus commands?
Some statements like create table, insert into etc take a semicolon at the end:
CREATE TABLE employees_demo
( employee_id NUMBER(6)
, first_name VARCHAR2(20)
, last_name ...
