SQL & PL/SQL :: Time Based Select

May 24, 2010

The following query gives error.

select count(*)
from invoice
where inv_id in (SELECT inv_id FROM invoice_hist WHERE to_char(timestamp) between TO_char('05/12/2010 18:22:00', 'MM/DD/YYYY HH24:MM:SS') and
TO_char('05/21/2010 18:22:00', 'MM/DD/YYYY HH24:MM:SS'));.

Here timestamp is of type DATE in the invlice_hist table.

What change is needed?

View 9 Replies


ADVERTISEMENT

Security :: Login Based On Particular Time

Mar 15, 2011

How can we create a user such that he can login only at a particular time of the day . if he try's to login other than the Time assigned ,shouldn't allow.

Can we use oracle Security policy ?

View 5 Replies View Related

SQL & PL/SQL :: Select Whole Row Based On Max Value?

May 10, 2013

Suppose I have the following, what is the best way to select the whole row that has the highest (IDX+LEN desc, LEN desc)

IDIDXLEN
5109153
7273118
9165356

I currently have made the following two method, which work but I don't particularly care for.

WITH bob AS
(SELECT 9165 id, 35 idx, 6 len FROM DUAL
UNION
SELECT 5109 id, 15 idx, 3 len FROM DUAL
UNION
SELECT 7273 id, 11 idx, 8 len FROM DUAL)

[code]....

View 3 Replies View Related

Reports & Discoverer :: Retrieving Time Based Transactions?

Aug 6, 2010

I have some transactions in my table with date and time.

i want to pass from date, to date and from time , to time as parameter.

when i pass one date and two time parameters, it works fine. but when i try to pass from date and to date (two date parameters) and two time parameters then it does not work accurately.

e.g. i want to pass 05-Aug-2010 and 06-Aug-2010 and time from 08:00:00 and 14:00:00 then it only retrieves data of both dates having only this time range. however i need to get transaction of 05-aug-2010 from 08:00:00 to 06-aug-2010 14:00:00.

View 3 Replies View Related

PL/SQL :: Group By Data Based On Start And End Time In Range

Mar 28, 2013

formatting the data.I want to group the below table data based on the Grade column for a header_data with start_time and end_time displayed in range. I was trying with group by, partitions etc but no luck. I use version 10gr2.

create table rel_data_mf (header_data varchar2(10),start_time varchar2(100),end_time varchar2(100),grade varchar2(1));

--table rel_data_mf data as comma separated values
header_data,start_time,end_time,Grade
ENG,2013-03-29 00:00:00-05:00,2013-03-29 01:00:00-05:00,U
ENG,2013-03-29 01:00:00-05:00,2013-03-29 02:00:00-05:00,U

[Code]...

--Required output

header_data,start_time,end_time,Grade
ENG,2013-03-29 00:00:00-05:00,2013-03-29 03:00:00-05:00,U
ENG,2013-03-29 03:00:00-05:00,2013-03-29 07:00:00-05:00,A
ENG,2013-03-29 07:00:00-05:00,2013-03-29 10:00:00-05:00,U
MATH,2013-03-29 00:00:00-05:00,2013-03-29 03:00:00-05:00,U
MATH,2013-03-29 03:00:00-05:00,2013-03-29 07:00:00-05:00,B
MATH,2013-03-29 07:00:00-05:00,2013-03-29 13:00:00-05:00,U

View 6 Replies View Related

Select Data Based On Date

Apr 27, 2010

I have a script which is used to run a job based on the users choice. For example: I have two table, Files and Requests

User select the files to be executed for each request. This data will be stored in Requests table.

Table 1: Files
files
======
file-1
file-2
file-3
..
..
file-n

Table 2: Requests

request file lup_date
==================================
request-1 file1,file2,file3 04-JAN-2009
request-2 file1,file4,file5 06-JAN-2009
request-3 file6,file2 021-JAN-2009
request-4 file1,file2 04-FEB-2009
request-5 file1,file2 08-JAN-2009
request-6 file1,file2 04-MAR-2009
.......... ........... ................
request-n-1 file6,file2,file4 04-DEC-2009
request-n file6,file3,file4 04-DEC-2009

how to get the output in below format. Count how many times each file is selected in a month.

Output format should be like below..
==============================================
File_Name Jan Feb Mar Apr ---------- Dec
==============================================
file1 2 1 3 0 ---------- 2
file2 1 0 2 1 ---------- 3
file-n 8 2 3 0 ---------- 2

View 2 Replies View Related

SQL & PL/SQL :: Add Null In Select Based On Certain Condition?

Oct 20, 2011

I got a requirement to check if a particular range of values are present , if few values missing then have to add null for the values. This has to be a SQL statement.

table 1 :

fiscal_month_id, value1, value2
2010100028482848
2010110025712709.5
2010120027452721.3
2011010026052692.25
2011020026382681.4
2011030030992751
2011040027662753.14
2011050029732780.625

This is the table. the fiscal month id denotes that the values is from month Oct(20101000) to May (20110500). The fiscal year cycle for me is from OCT to SEP. Hence when we select this table, the select should retreive the below data

fiscal_month_id, value1, value2
2010100028482848
2010110025712709.5
2010120027452721.3
2011010026052692.25

[code].....

How to do this in a select statement ?

This fiscal_month_ID is actual from another table where all time level information are kept.

View 4 Replies View Related

SQL & PL/SQL :: Filtering SELECT Statement Based On Parameter?

May 26, 2010

Below is the code as currently written which works fine for Delta records processing (based on the field called activ_dt).

/*
Custom extract
Project: XYZ Price Data Extract
Product: EOWin 4.02 - Oracle database
Use : Script to create the above XYZ Extract and spool the results to a text file
Input Parameters:

[code]....

My problem is I am trying to add a 3rd parameter which will tell the extract to pull all of the data or just the deltas. So I added &3 to the comments and I have tried putting CASE or DECODE functions into the WHERE clause with no luck. I also tried to do a CASE or DECODE with two different SELECTS, again with no luck.

An example of my failed attempt to add &3 and handle F or D

/*
Custom extract
Project: XYZ Price Data Extract
Product: EOWin 4.02 - Oracle database
Use : Script to create the above XYZ Extract and spool the results to a text file
Input Parameters:

[code]....

View 16 Replies View Related

SQL & PL/SQL :: Show Or Select Data Based On 2 Criteria

Mar 23, 2013

I have a complex requirement to be resolved, i have one table of quantities from where i want to show or select the data based on 2 criteria.

1) if the ps_qty is greater than 1000 then there should be two lines , like the qty should not be displayed greater than 1000, instead it should be lesser than 1000.
2) The weight should not be more than 50,000, it should be less than 50000 if its more it should be displayed as 2 lines.

The following is the test case.

CREATE TABLE OW_STAG_SHIP (PS_CODE VARCHAR2(12),PS_DESC VARCHAR2(30),PS_QTY NUMBER,PS_WT NUMBER);
INSERT INTO OW_STAG_SHIP VALUES ('A','AAA',400,30000); -- this will be displayed as its because qty and wt are ok
INSERT INTO OW_STAG_SHIP VALUES ('B','BBB',1100,4000); --Need to be displaed in two lines as qty is more than 1000
INSERT INTO OW_STAG_SHIP VALUES ('C','CCC',2500,6000); --Need to be displayed in three lines as qty is more
INSERT INTO OW_STAG_SHIP VALUES ('D','DDD',600,60000); --Need to be displaed in two lines as wt is more.
select * from ow_stag_ship

PS_CODEPS_DESCPS_QTYPS_WT
AAAA40030000
BBBB11004000
CCCC25006000
DDDD60060000

Output what i want is as below

PS_CODEPS_DESCPS_QTYPS_WT
AAAA 40030000
BBBB10002000
BBBB 1002000
CCCC10002000
CCCC10002000
CCCC 5002000
DDDD 500 50000
DDDD 100 10000

View 16 Replies View Related

SQL & PL/SQL :: Filter Each Row In A Select Statement Based Upon A List?

May 18, 2011

Is it possible to filter each row in a select statement based upon a list that you loop through. For instance in a where clause having an in statement but rather than selecting any value in the in statement looping the main select through each value in the "in" filter.

Eg:

CREATE TABLE TRANSAC(
Item_id number ,
Transaction_Date DATE,
Category_id number
)

You could then write

SELECT MAX(Transaction_Date)
from TRANSAC
where category_id = '141'

and then where category_id = '142' then '143' etc.

I understand i could use an inline view instead of a where clause but the issue is that i already have the list of values I want to compare against.

View 5 Replies View Related

SQL & PL/SQL :: Select Query To Get Top Two Rows Based On Status Date

Oct 29, 2012

I want to get top two rows based on ACCT_UNIT & order by status_date, if there is only one row on acct_unit, get one row. IF more than two rows available, want to get the top two rows based on status_date.

SELECT ACTIVE_STATUS, ACCT_UNIT, DESCRIPTION, DIRECTOR, DIRECTOR2, STATUS_DATE, OBJ_ID, STATUS_FLAG, SUR_KEY
FROM STSI

View 10 Replies View Related

PL/SQL :: Select Records Based On First N Distinct Values Of Column

Sep 25, 2012

I need to write a query in plsql to select records for first 3 distinct values of a single column (below example, ID )and all the rows for next 3 distinct values of the column and so on till the end of count of distinct values of a column.

eg:
ID name age
1 abc 10
1 def 20
2 ghi 10
2 jkl 20
2 mno 60
3 pqr 10
4 rst 10
4 tuv 10
5 vwx 10
6 xyz 10
6 hij 10
7 lmn 10
.
.
.
so on... (till some count)
Result should be
Query 1 should result --->
ID name age
1 abc 10
1 def 20
2 ghi 10
2 jkl 20
2 mno 60
3 pqr 10

query 2 should result -->
4 rst 10
4 tuv 10
5 vwx 10
6 xyz 10
6 hij 10

query 3 should result -->
7 lmn 10
.
.
9 .. ..
so on..

How to write a query for this inside a loop.

View 5 Replies View Related

SQL & PL/SQL :: Create Select Query That Will Get Data From 18 Months Ago Based On Sysdate?

Sep 9, 2013

I have a table with columns job_id, jan, feb, mar ... , and year

I need to create a select query that will get the data from 18 months ago based on sysdate.

So something like:

Select to_char(add_months(sysdate, -18),'MON') from table1 where job_id = 56947 and year = to_char(add_months(sysdate, -18),'YYYY');

However I need the result of to_char(add_months(sysdate, -18),'MON') to actually act as a column name, not a string result.

View 23 Replies View Related

Application Express :: Automatic Row Fetch Based On Select List

Oct 27, 2013

db11gxe , apex 4.0 , firefox 24. I want to do automatic row fetch when the value of a select list changes ?but first i should ofcourse create a tabular form to fetch the data into it , but what i want is ,if i fetch 2 rows then the report contains only two rows , if i fetch 3 , the report contains only 3, if i fetch nothing , the report has nothing ? 

View 0 Replies View Related

Application Express :: Tabular Form (select List Query Based LOV)

Jul 10, 2012

I have this situation:

a tabular form with two "select list (query based LOV)" fields. The first one must affect elements in the second one. And so the second query based LOV field should has a "where attr1 = first_list_selected_value" in the query.

View 3 Replies View Related

PL/SQL :: Select Exists On Time

Sep 17, 2013

I have this sample:
the column data1 is datetime datatype  with
t as (   select 'SMITH' nom,to_date('21/09/2013 07:30:00') data1
from dual union all   select 'ALLEN',to_date('21/09/2013 07:40:00')
from dual union all   -- select 'WARD',to_date('21/09/2013 07:50:00')
from dual union all   
select 'JONES',to_date('21/09/2013 08:00:00')
from dual union all   

[Code]..

How can I write a select to check that If I input 10 minutes to nom 'ALLEN' it's ok because the time 07:40 + 10 minutes = 07:50 the row not exists, (the next)but If input 20 it exists because the sum = 08:00 and row  isn't free , indeed, there is 'JONES'?

View 4 Replies View Related

PL/SQL :: Select Time From Sysdate

Sep 20, 2013

I have to concatenate a date(not sysdate) with the system time and store it in a column having datatype as DATE... So I tried like this....

SELECT TO_CHAR (C_DATE, 'DD-MON-YYYY')      || ' '    || TO_CHAR (SYSDATE, 'HH:MI:SS PM')    FROM   DUAL; 

But while inserting the output of the above query in my table it throws error like this... ORA-01830: date format picture ends before converting entire input string Is there any possibility to achieve this.

View 6 Replies View Related

SQL & PL/SQL :: Conditional Select - Query To Returns Results Based On Both City And Country Passed

Sep 17, 2010

Table A

Id Country city
1 US
2 US Boston
3 Boston
4 US Newyork
5 London
6 Japan Tokyo

Im looking for a query which returns results based on both city and country passed.

If i pass country US and city Boston it should return row2 with US and Boston row
If i pass country null and city Boston it should return row3
If i pass country UK and city Boston it should return row3
If i pass country UK and city London it should return row5

i.e. If country/city combination exists in DB return that row Else city row should be returned.

View 5 Replies View Related

Last Date / Time When Index Used For Select

Jul 26, 2011

Is there a way I can find what the last date/time and index was used for a select...

I have a table with several indexes on them, which I beleive are not being accessed.

I use the following the query to find indexes that where not accessed in a while but this I believe is limited my my workload repository retention, which is set to 90 days.

select index_name from dba_indexes where table_name='<table name>'
and index_name not in (select c1 from(
select p.object_name c1, p.operation c2, p.options c3, count(1) c4
from dba_hist_sql_plan p, dba_hist_sqlstat s
where p.object_owner = 'MTAS' and p.operation like '%INDEX%' and p.sql_id = s.sql_id
group by p.object_name, p.operation, p.options
order by 1,2,3))

Without increasing my repository retention is there a way I can get the last date/time, which an index was used instead of just saying it has not been used in 90 days (retention setting). Is this information kept in the SQL plan?

View 2 Replies View Related

PL/SQL :: Select Data Which Is Inserted At Same Time?

Mar 20, 2013

I wanted to select data which is inserted on the same time.

Is that possible? I am trying with below query but facing isses.

SQL> SELECT a,b,c,d FROM tb;

no rows selected

SQL> SELECT a,b,c,d FROM (INSERT INTO tb VALUES(1,1,1,1));
SELECT a,b,c,d FROM (INSERT INTO tb VALUES(1,1,1,1))
*
ERROR at line 1:
ORA-00903: invalid table name

View 11 Replies View Related

Select Statement To Oracle DB - Time Converting?

Aug 27, 2009

My company use a sybase database that runs business jobs. Currently we run SQL queries from Perl to gather time information on the jobs. Now we have an application that is using Oracle. The server it is on, doesn't have perl, so I am using a shell script to login to sqlplus and run a query for a job and it's end time. I have accomplished this. However, here is the 2 problems I am having.

1. The query reults are returned in Scientific time, I'm able to convert that to EPOCH time in the SQL syntax, however, it comes back with a 13 digit time, instead of 10. The last 3 digits are zero. How can you remove the last 3 digits in the query or convert the 13 digits to Human Time. Right now when you see the select statement, I am doing a to_char to get it to EPOCH time.

2. How to only show the latest time in the query and not show ALL job end times from it's past runs.

Here is my shell script, and I do realize this maybe a select statement syntax solution to one or both, but the UNIX time stamp is puzzling.

#!/usr/bin/sh
sqlplus -S username/password@JAWSPROD <<eof> myfile
set heading off feedback off verify off
select JAWS_APP.JAWSJOB.JOBNAME, to_char(JAWS_APP.JOBRUN.ENDTIME) from JAWS_APP.JAWSJOB, JAWS_APP.JOBRUN where JAWS_APP.JAWSJOB.JOBID = JAWS_APP.JOBRUN.JOBID and JAWS_APP.JAWSJOB.JOBNAME in ('pa_box_settle');
exit

View 1 Replies View Related

Table Has No Rows - Select Taking Time

Aug 23, 2010

We were trying to insert approx 76 million records worth of approx 4 GB in a table when the insert operation failed with the archive log error.

The database was hanged, we re-started the database and currently there are no records in the table but when we are firing a select

select count(*)
from table

It's taking approx 2 mins to come out with the result.

We checked and found that there are no locks on the table currently.

what do we need to do to get the performance back

View 5 Replies View Related

Oracle 11.2.0.3.0 - Select Query Taking Time

Jan 24, 2013

My oracle database version is 11.2.0.3.0 where i am having one schema in that schema i am having 3 same tables with same structure same data but with different name.

but problem is in first table when i perform select query it takes 5 sec, in another table it is taking 0 sec and in third table it is taking 10 sec.

View 1 Replies View Related

Time Format - Way To Change My Select To Creation

Jul 18, 2012

when I select I have to using AND creation_dt>='17-JUL-12' is there a way to change my select to creation_dt='17-JUL-12' ?
on meantime my local format is 18-JUL-12(18-JUL-12) is thee anything I can do?

View 5 Replies View Related

Application Express :: Auto Populate Phone Number Based On Select List In Tabular Form

Dec 27, 2012

Ive a requirement which ive overlooked for a while now as below,

On my tabular form i have fields: Empid as Select List and when the value is picked from this Select List EmpID i want the associated/corresponding phone# displayed in its TEXT FIELD in that same row,

apex 4.1.1/Oracle 11gR2,

also i tried the below as a workaround but it doesnt fulfill my requirement, [URL]....

View 1 Replies View Related

SQLPLUS Select Statement To Get Last Failed Time From Each User

Aug 13, 2010

I'm new to the sqlplus,

User ID Failed_timestamp
----------------------------------
userA 20100801 11:22:33
userB 20100802 11:22:33
userA 20100802 12:22:44
userA 20100803 13:34:55
userC 20100803 20:21:23
userB 20100804 16:34:56

I wanna to get the last failed time from each user. what is the select statement?

my expected result will be:

userA 20100803 13:34:55
userB 20100804 16:34:56
userC 20100803 20:21:23

View 3 Replies View Related

IF EXISTS (Select) - Enter Into Table One Period At A Time?

Apr 21, 2011

I am trying to break down a row of data that has nine periods that I want to enter into a table one period at a time. I am trying to use "IF EXISTS ( SELECT * FROM TABLENAME WHERE FIELD1 IS NOT NULL) THEN" through all nine fields. It keeps returning lines that have a null column as well as not null columns. if there is a better way of doing this. Here is an example of what I am trying to do:

IF EXISTS (SELECT * FROM TABLE_NAME WHERE LAST_DT9 IS NOT NULL) THEN
SELECT NUMBER, 1COL9, 2COL9, 3COL9, FIRST_DT9, LAST_DT9, 4COL9
FROM TABLE_NAME;
ELSE IF EXISTS (SELECT * FROM TABLE_NAME WHERE LAST_DT8 IS NOT NULL) THEN

[code]...

View 1 Replies View Related

Performance Tuning :: Servers Will Be Running SELECT Which Returns Zero Rows All Time

Feb 11, 2011

Our application servers will be running a SELECT which returns zero rows all the time.This SELECT is put into a package and this package will be called by application servers very frequently which is causing unnecessary CPU.

Original query and plan

SQL> SELECT SEGMENT_JOB_ID, SEGMENT_SET_JOB_ID, SEGMENT_ID, TARGET_VERSION
FROM AIMUSER.SEGMENT_JOBS
WHERE SEGMENT_JOB_ID NOT IN
(SELECT SEGMENT_JOB_ID
FROM AIMUSER.SEGMENT_JOBS) 2 3 4 5 ;
[code]....

Which option will be better or do we have other options?They need to pass the column's with zero rows to a ref cursor.

View 6 Replies View Related

Performance Tuning :: Select Query Taking Time Even After Using Parallel Hint?

Sep 25, 2013

select
serialnumber from product where productid in
(select /*+ full parallel(producttask 16) */productid from producttask where
startedtimestamp > to_date('2013-07-04 00:00:00', 'YYYY-MM-DD HH24:MI:SS')
and startedtimestamp < to_date('2013-07-05 00:00:00', 'YYYY-MM-DD HH24:MI:SS')
and producttasktypeid in

[code]....

Explain plan output:

Plan hash value: 2779236890
-----------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name| Rows| Bytes | Cost (%CPU)| Time| Pstart| Pstop |
-----------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT || 1 | 29 | 9633M (8)|999:59:59 |||
|* 1 | FILTER |||| ||||
| 2 | PARTITION RANGE ALL || 738M| 19G| 6321K (1)| 21:04:17 | 1 | 6821 |

[code]....

Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter( EXISTS (<not feasible>)
4 - filter("PRODUCTID"=:B1)
5 - filter(ROWNUM<100)
12 - access("MODELID"=:B1)

[code]....

Note: - SQL profile "SYS_SQLPROF_014153616b850002" used for this statement

View 2 Replies View Related

Application Express :: Assigning Value To Select List Only First Time Page Loads

Jan 3, 2013

I am trying to set the intial value of "Select List" to APP_USER the only first time when the page loads and use it to filter the report, any other time once the page is loaded the user should select another value from the Select List then click the submit button to display the details in the report, i tried to achieve this by setting "select List" creating LOV for Select List then set default=APP_USER but now the problem any time you click the submit button it reset the "Select List" from selected value back to default so how can you achieve this to set the value of Select List only the first time the page loads?

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved