SQL & PL/SQL :: Get Difference In Values From Two Subqueries

Jul 1, 2013

I have a scenario where I need to get field name upc_id that do not exist in other subquery.

q-1)WITH INITIALKEYCAT AS (SELECT UPC_ID,SALE_LOCATION_ID,MIN(APPROVAL_DATE) AS INITIALDATE
FROM ITEM_KEYCAT
WHERE APPROVAL_DATE IS NOT NULL
GROUP BY UPC_ID,SALE_LOCATION_ID
having MIN(APPROVAL_DATE)>=to_date('2011/01/01', 'yyyy/mm/dd')
AND MIN(APPROVAL_DATE)<to_date ('2011/04/01','yyyy/mm/dd'))

[Code]....

Now from Q-2) I want to get UPC_ID that do not exist in UPC_ID of Q-1).How can I write this.

View 4 Replies


ADVERTISEMENT

Counting Rows - Difference In Values That Are Returned?

Sep 26, 2010

difference in the values that are returned?

select count(*) from aaa;
COUNT(*)
----------
1000001

select num_rows from dba_tables where table_name = 'AAA';
NUM_ROWS
----------
994202

View 5 Replies View Related

Using Subqueries In JOINS

Sep 30, 2011

In mys store procedure I am using a subquery with INNER JOIN. This subquery calls a user defined function which takes main query fields as parameter values. But i am facing issue for accessing main query fields. my query is like below:

SELECT
ID, Name, sub.Desc, sub.Date
FROM MainTable main
INNER JOIN
(
SELECT * FROM RMF_GetData(main.ID)
) sub
ON main.ContactID = sub.ContactID

I need data from a function in a table format based on some case conditions. Hence i need to join it with main table. But here oracle gives error as "invalid identifier" for main.ID parameter.

View 1 Replies View Related

Updating Using Subqueries

Oct 26, 2010

i was just working on one of my SQL assignments from my database management course, and thus far, this is the first that I just can't figure out. The question is:

Quote: Increase the credit limit of any customer who has any order that exceeds their credit limit. The new credit limit should be set to their maximim order amount plus $1,000. This must be done in 1 SQL statement

The bolded part is what I'm having trouble with.

What I have thus far:

UPDATE Customers
SET    CreditLimit = 1000 + (SELECT MAX(Amount) FROM Orders,  Customers WHERE Cust = CustNum)
WHERE CustNum IN (   
                   SELECT Cust
                   FROM Orders
                   WHERE Cust = CustNum
                   AND CreditLimit < Amount); 

So there's two tables that I'll be working with, Customers (the table I'm updating), and Orders (the table where the order amount is found). With the code I have so far, it does seem to be updating the correct tables at the very least, but not with the correct values. It's essentially updating the CreditLimit column with the new value of 1000 + the maximum amount in the order table, which is very close to what I want it to do, but I want it to be 1000 + the maximum amount for that specific customer.

CustNum is the primary key for the Customers table, and Cust is the foreign key that links each together.

(about the formatting, it looked much prettier in SQL Worksheet Plus)

View 8 Replies View Related

Restriction On Scalar Subqueries

Feb 21, 2013

I would like to pass my 1Z0-047 certification, but I don't understand the limitation on the scalar subqueries, especially for the having clause.

Here is my scalar subquery because it returns only one value.

CODEselect avg(list_price)
from product_information

I use it in a having clause as a scalar subquery and it works

CODEselect status ,avg(list_price)
from product_information
group by status
having (select avg(list_price)
from product_information)
>= avg(list_price);

but it is documented that it can't works :

QUOTE There are also important restrictions on scalar subqueries. Scalar subqueries can�t be used for:
Default values for columns
RETURNING clauses
Hash expressions for clusters
Functional index expressions
CHECK constraints on columns
WHEN condition of triggers
GROUP BY and HAVING clauses
START WITH and CONNECT BY clauses

I probably don't understand the limitation .

View 10 Replies View Related

SQL & PL/SQL :: Conditional Insert With Multiple Subqueries

Oct 9, 2012

We have multiple environments and our dev and UAT ones are now different from staging and live (I know, but I am not in a position to get this fixed). I have a set of updates that need to go through to live and in some cases they reference rows that do not exist in the UAT environment, and yet they have to (rigid, dumb process) go through that environment.

Basically, the insert I need to do takes info from two tables and does an insert into a third. That target table has a not null constraint on the affected fields, so the insert fails, quite rightly.

There's lots of info available on how to do conditional inserts with single sub-queries, using DUAL and EXISTS (or rather NOT EXISTS, but that's easy to swap), but those don't seem to easily translate for this one.

The sql that works when everything exists is:

insert into wmcontent.wm_manda_corpserv_companies
(wm_manda_company_code, wm_corp_company_code)
values
( (select wm_company_code from wmcontent.wm_m_and_a_company where wm_company = 'SW'), (select min(oid) from wmcontent.wx_category where content_type = 2 and name = 'SW') );

In desperation I even tried using "log errors reject limit unlimited" but, no doubt due to my misunderstanding of how that works, I ended up getting the error "ORA-06550: line 38, column 1: PL/SQL: ORA-00972: identifier is too long" as a result.

View 8 Replies View Related

SQL & PL/SQL :: Nesting Subqueries To Sum Data In Different Ways

Feb 18, 2013

I'm trying to create a query based upon an IAL (I'm using IFS). The IAL contains sales, grouped by month, for each customer. The output of the query should be as follows:

Cust_No
Spend in Month
Spend in Quarter
Spend in Year

My first thought was to have three subqueries, summing data from the IAL where the month of sale was last month, in the last 3 months, and in the last 12 months. Is this the right way to go? And what is the syntax?

View 7 Replies View Related

PL/SQL :: Calculate Difference By Which Day Count Of Difference Is Going?

Oct 17, 2012

Detail table will look like below:

Product_id issue_date action_date Force_date
1 10/10/2012 10/10/2012 10/10/2012
2 10/10/2012 10/10/2012 10/10/2012
3 10/10/2012 13/10/2012 15/10/2012
[code]....

Need the data like

Issue_date count_action_date count_Force_date (diff(action_date,force_date) 1 2 3 4 5 6(days since over)

10/10/2012 3 4 1 4 2 1 0 0

How to get the data like this? automatically how to get 123.... and how to calculate the difference by which day the count of difference is going?

View 3 Replies View Related

Application Express :: Assign Values In Many Rows Based On Search Values?

Jul 25, 2013

I used Region, Process by to search the report which appears as shown above. Then I use Choose Auditors column to select my Auditor and copy paste it into the report under To be Audited By col. Is there a way to automate the process. I am here using a tabular form in APEX. My main aim is to assign auditors based on Region, not equal to Processed by. 

View 4 Replies View Related

Replacing Null Values Of Outer Join With Meaningful Values

Dec 3, 2010

I have a scenario where I have to get all the available dates of a resource. I am using the below query to get it.

Select Avail_Date AS MONTH
, Resource_Id
FROM res_tsk
, (SELECT Rownum - 1 + TRUNC (sysdate) avail_date
FROM Dual
[code].......

The result of this is:

Month Dates Resource_ID
12/3/10 0:00 NULL
12/4/10 0:00 NULL
12/5/10 0:00 NULL
12/6/10 0:00 100033868

As I am doing a outer join, if the resource is not available on a particular day the resource_id is coming as NULL as it is not available. Is there any way to populate this NULL resource_id with the original resource_id as the resource_id is same for all the result set.

I need the output to be

Month Dates Resource_ID
12/3/10 0:00 100033868
12/4/10 0:00 100033868
12/5/10 0:00 100033868
12/6/10 0:00 100033868

View 3 Replies View Related

SQL & PL/SQL :: How To Insert Values Into Another Column By Comparing Values Of Two Columns Of Same Table

Dec 23, 2010

My scenario is to insert values into 'out' column by comparing 's' and 'IP' columns of temp table.The exact situation is at first need to go to ip column,take a value and then go to source column and check for the same value of ip which is taken previously.Then after corresponding ip of that source column should be inserted back in previous source column.

The situation is marked clearly in file which i am attaching with '--' comments at respective places.I am also pasting the code which i tried out,unfortunately it is giving error as exact fetch returns more than requested number of rows since there are duplicates in the table.I tried it using nested for loops.Also implemented using rowid,but it didnt work.

fixing the errors or if there is any new logic that can be implemented.

DECLARE
i_e NUMBER(10);
BEGIN
FOR cur_1 IN(SELECT IP from temp where IP IS NOT NULL)
LOOP
FOR cur_2 IN(SELECT IP from temp where s=cur_1.IP)

[Code]...

View 9 Replies View Related

SQL & PL/SQL :: Ad Hoc MINUS - Compare Values In Code To Values In Table

Oct 28, 2013

I am searching the simplest way for ad hoc MINUS.I do:

SELECT *
FROM uam_rss_user_XXXXXXX
WHERE host_name IN
('XXX0349',
'XXX0362',
'XXX0363',
'XXX0343',
'XXX0342',
'XXX0499',
[code]....

and look in the table which values are missing (values that are in host_name IN but not in actual table).is there a simpler way for doing an ad hoc MINUS? I know to insert values in temp. Table. How are experienced Oracle pros doing this task?

View 6 Replies View Related

PL/SQL :: How To Fetch Values From Two Columns Using Values From One Column

Jul 25, 2013

From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?

View 2 Replies View Related

PL/SQL :: ORA-00947 - Not Enough Values But Enough Values Are Being Returned

Dec 18, 2012

I created a package with some types, and every was compiling fine. However, when I ran the new function, I got an error: ORA-21700: object does not exist or is marked for delete

After a little research, I realized that the types would have to be declared outside the package. As soon as I did that, I suddenly started getting the "not enough values" errors on all my types. I compared the number of columns being returned, and the number of columns in the type, and they match.Here is my type code:

CREATE OR REPLACE TYPE  TSA_CUSTOM.Lost_Plan as object (
   LP_Key number,  -- The member key of the plan that is going away
   LP_Type varchar2(20),
   LP_Dept varchar2(12),
   LP_SubDept varchar2(12),
   LP_Class varchar2(12),
   LP_VendorName varchar2(50)
[code]...

View 2 Replies View Related

SQL & PL/SQL :: Get Max Difference Where Each Value Can Look At Only Next?

May 28, 2013

How do I get the max difference where each value can look at only the next value(ordered by date asc) on any particular day
example first row on 20090902 is 501.25 (earliest date)

756.2 - 501.25
4735.83 - 501.25
35.83 - 501.25

[code]....

View 19 Replies View Related

How To Get Date Difference

Jul 20, 2007

How one can get date difference in days between two dates in Oracle reports ?

View 2 Replies View Related

SQL & PL/SQL :: Difference Between Dates

Jan 23, 2013

I am looking to subtract two columns and get the difference.

select to_char('06-NOV-2012 20:00','DD-MON-YYYY HH24:MI') - to_char(systimestamp,'DD-MON-YY HH24:MI') from dual;
select to_char('06-NOV-2012 20:00','DD-MON-YYYY HH24:MI') - to_char(systimestamp,'DD-MON-YY HH24:MI') from dual
*
ERROR at line 1:

ORA-01722: invalid number

View 9 Replies View Related

SQL & PL/SQL :: ORA-00923 - Difference Between 9i And 10g

Aug 25, 2010

I encountered this problem when we recently migrated to 10g. The table nametab has two columns roll(number datatype) and name(varchar2(10) datatype).Following are the queries used and I have deliberately not given space between the "select" clause and the "from" clause.

In 9i
SELECT name,1FROM nametab where rownum < 2
NAME 1
---------- ----------
Bharath 1

Same query in 10g
SELECT name,1FROM nametab where rownum < 2
ORA-00923: FROM keyword not found where expected

Here, I have interchanged the select columns.

In 9i
SELECT 1,nameFROM nametab where rownum < 2
ORA-00923: FROM keyword not found where expected

In 10g
SELECT 1,nameFROM nametab where rownum < 2
ORA-00923: FROM keyword not found where expected

View 7 Replies View Related

SQL & PL/SQL :: Difference Between Oracle 9i And 10g?

Apr 25, 2013

what are difference in between oracle 9i and 10g regarding with Sql queries?

View 1 Replies View Related

SQL & PL/SQL :: Difference Between Using MINUS And NOT IN

Sep 28, 2011

I am looking for an explanation for having the following query:

SELECT PK_SERIAL_NUMBER FROM TABLE1 MINUS (SELECT FK_SERIAL_NUMBER FROM TABLE2);

Which normally returns the values of SERIAL_NUMBER that are not passed to the child table TABLE2

and the query:

SELECT PK_SERIAL_NUMBER FROM TABLE1 WHERE PK_SERIAL_NUMBER
NOT IN
(
SELECT FK_SERIAL_NUMBER FROM TABLE2
);

which returns 0 rows!

View 6 Replies View Related

Difference Between V$sql And Dba_hist_sqlstat?

May 30, 2011

1. difference between v$sql and dba_hist_sqlstat?

2. as of i have understood, dba_hist_sqlstat gets refreshed from v$sql.

if i run this below query i get different outputs.. how?

by using v$sql table

WITH t AS
(SELECT force_matching_signature ,
SUM(executions_delta) executions,
COUNT(*) cnt ,
parsing_schema_name ,
MIN(MODILE1) MODULE1

[code].......

View 2 Replies View Related

SQL & PL/SQL :: Difference Between Oracle 8i And 11g

Sep 22, 2011

I listen that there is a big diff B/W indexing in oracle 8i and oracle 11g.

what way the indexing is different B/W 8i and 11g.

View 3 Replies View Related

PL/SQL :: Difference Between 2 Dates

Sep 24, 2012

for the below table

create table RM_TR_INVESTMENT
(
  AS_ON_DT                DATE not null,
  EXP_ID                  NUMBER(10) not null,
  BO_REF_ID               VARCHAR2(30),
  FO_REF_ID               VARCHAR2(30),
  BK_PRODUCT_ID           VARCHAR2(20),
  BK_INV_TYPE_ID          VARCHAR2(20),
 [code]....

I want to find the sum of NP_AMT_CCY where difference between Start_Dt and Maturity_Dt >= 14 days and <=28 days.How can I build the query for the above statement ?

View 6 Replies View Related

PL/SQL :: Difference Between Oracle DB 11.2.0.1.0 And 11.2.0.3.0?

Dec 18, 2012

When I use this sql: CREATE USER testuser IDENTIFIED BY "welcome1 " to create user in Oracle DB 11.2.0.1.0. I can login with testuser/welcome1, please notice the welcome1 is not end of black space in login.

But when I do the same thing in Oracle DB 11.2.0.3.0. I can't use this user login with any password. I tried welcome1, "welcome1 " but all failed.

Why there are this difference between 11.2.0.1.0 and 11.2.0.3.0, and since in 11.2.0.3.0 the create sql are success, what password is correct when login?

View 7 Replies View Related

SQL & PL/SQL :: How To Get Difference From Hh24:mi

Aug 17, 2013

I have two columns StartTime and EndTIme.

I have data like this

EndTime StartTime Diff(endtime-StartTime)
23:00 20:00 03:00
22:00 21:30 00:30

How can i get Diff(endtime-StartTime) from hh24:mi format

View 2 Replies View Related

SQL & PL/SQL :: Displaying Multiple Row Values As Multiple Column And Row Values

May 4, 2010

find the Test Case below.

--Creation of Table

create table tb1
(ID number(4),
event varchar2(20),
vdate date);

--Inserting Values into the Table.

INSERT ALL INTO tb1 (ID, event, vdate) VALUES (01, 'V1', '01-JAN-2009')
INTO tb1 (ID, event, vdate) VALUES (01, 'V2', '02-FEB-2009')
INTO tb1 (ID, event, vdate) VALUES (01, 'V3', '04-MAR-2009')
INTO tb1 (ID, event, vdate) VALUES (01, 'V4', '03-APR-2009')
INTO tb1 (ID, event, vdate) VALUES (01, 'V5', '05-MAY-2009')

[Code]...

--Selecting data from Table.

SELECT * FROM TB1;

ID EVENT VDATE
---------- -------------------- ---------
1 V1 01-JAN-09
1 V2 02-FEB-09
1 V3 04-MAR-09
1 V4 03-APR-09
1 V5 05-MAY-09
2 V1 01-JAN-10
2 V2 02-FEB-10
2 V3 04-MAR-10
2 V4 03-APR-10
2 V5 05-MAY-10

10 rows selected.

how can i display the data as below format using Oracle 9i SQL.

IDV1 V2 V3 V4 V5
--- ---------------- ------------ --------------- -------------- ------------
11-Jan-092-Feb-094-Mar-093-Apr-095-May-09
21-Jan-102-Feb-104-Mar-103-Apr-105-May-10

View 4 Replies View Related

Difference Between Database Or SID Upgrade

Oct 19, 2012

i want to know is there any difference between upgradation of SID and database. while upgrading my database from oracle 11.2.0.2 to 11.2.0.3 in DBUA it shows my SID is upgrading (ORCL) but i have few other databases ex (test and prod).

is it enough if we upgrade the SID or we must perform any other actions..

and
2nd QUERY :

i have 2 oracle homes in my server with different versions like (11.2.0.2 and 11.2.0.3)and i have few databases and there tablespaces. how to determine which database is created on which version and which database is upgraded from 11.2.0.2 to 11.2.0.3.

View 3 Replies View Related

Difference Between ADD DISK And ADD VOLUME

May 27, 2013

I have a question about the ADD VOLUME command, I can't understand the difference between ADD DISK and ADD VOLUME.What are the difference between them?When should I use each one?How can I control the stripping and mirroring (NORMAL and HIGH) adding VOLUMES in a DISKGROUP?Can I add a volume to a fail group?

View 1 Replies View Related

Difference Between Coalesce And Defragmentation?

Sep 1, 2012

What are all the differences between Coalesce and De-fragmentation? When i need to use Coalesce?

View 4 Replies View Related

Difference Between Oracle Version 10.2.0.3 And 10.2.03?

May 28, 2008

difference between oracle version 10.2.0.3 and 10.2.03.I searched a lots of sites to get the details about these versions but unable to collect.

Oracle released both version or 10.2.0.3 and 10.2.03 are same versions treated by oracle.

View 2 Replies View Related







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