How to write the given query using 'ANY ' operator
Hi,
How to write the given query using 'ANY ' operator , I dont need to fetch to grade_master table twice in database, just need to fetch within the result set.
SELECT dsg_code,dsg_name,dsg_grade FROM designation_master WHERE dsg_orgn='&&Orgn' and dsg_ctry='&&ctry'
And dsg_loc ='&&loc' And dsg_oru = '&&oru' and dsg_grade in decode('&&radio_group',
1, SELECT grd_code FROM grade_master WHERE grd_osm_code in (Select grd_osm_code FROM grade_master WHERE grd_orgn='&&Orgn' and grd_ctry='&&ctry' And grd_loc ='&&loc' And grd_oru = '&&oru' and grd_code ='&&emp_grade'),
2, SELECT grd_code FROM grade_master WHERE grd_osm_code > (Select grd_osm_code FROM grade_master WHERE grd_orgn='&&orgn' and grd_ctry='&&ctry' and grd_loc ='&&loc' And grd_oru = '&&oru' and grd_code),
3, SELECT grd_code FROM grade_master WHERE grd_osm_code < (Select grd_osm_code FROM grade_master WHERE grd_orgn='&&orgn' and grd_ctry='&&ctry' And grd_loc ='&&loc' And grd_oru = '&&oru' and grd_code ='&&emp_grade'))
thanks
rincy
Hi,
One thing I understood my your issue is you want to perform, execution of query once or fetch the results sets my minimizing the number of times executions of queries. It would be hard for us to check in this way, atleast provide some temporary data and some business rules. Only I can IN, >, < (queries logical conditons on inner query)
- Pavan Kumar N
- ORACLE OCP - 9i/10g
https://www.oracleinternals.blogspot.com
Similar Messages
-
To re-write query using 'ANY' operator
Hi,
How to write the given query using 'ANY ' operator , I dont need to fetch to grade_master table twice in database, just need to fetch within the result set.
SELECT dsg_code,dsg_name,dsg_grade FROM designation_master WHERE dsg_orgn='&&Orgn' and dsg_ctry='&&ctry'
And dsg_loc ='&&loc' And dsg_oru = '&&oru' and dsg_grade in decode('&&radio_group',
1, SELECT grd_code FROM grade_master WHERE grd_osm_code in (Select grd_osm_code FROM grade_master WHERE grd_orgn='&&Orgn' and grd_ctry='&&ctry' And grd_loc ='&&loc' And grd_oru = '&&oru' and grd_code ='&&emp_grade'),
2, SELECT grd_code FROM grade_master WHERE grd_osm_code > (Select grd_osm_code FROM grade_master WHERE grd_orgn='&&orgn' and grd_ctry='&&ctry' and grd_loc ='&&loc' And grd_oru = '&&oru' and grd_code),
3, SELECT grd_code FROM grade_master WHERE grd_osm_code < (Select grd_osm_code FROM grade_master WHERE grd_orgn='&&orgn' and grd_ctry='&&ctry' And grd_loc ='&&loc' And grd_oru = '&&oru' and grd_code ='&&emp_grade'))
thanks
rincyTubby is correct that data and create statements are required to analyze it correctly.
Still I worked on it and created something using WITH clause
with grd_query
as
(Select grd_osm_code FROM grade_master WHERE grd_orgn='&&orgn' and grd_ctry='&&ctry' and grd_loc ='&&loc' And grd_oru = '&&oru' and grd_code ='&&emp_grade')
,grd_mst_query
as
(SELECT grd_code, grd_osm_code FROM grade_master)
SELECT dsg_code, dsg_name, dsg_grade
FROM designation_master
WHERE dsg_orgn = '&&Orgn'
AND dsg_ctry = '&&ctry'
AND dsg_loc = '&&loc'
AND dsg_oru = '&&oru'
AND dsg_grade in
decode('&&radio_group',1, (SELECT grd_code FROM grd_mst_query WHERE grd_osm_code in (select * from grd_query)),
2, (SELECT grd_code FROM grd_mst_query WHERE grd_osm_code > (select * from grd_query)),
3, (SELECT grd_code FROM grd_mst_query WHERE grd_osm_code < (select * from grd_query)))this should avoid multiple scans on same table.
thanks -
Write the following query using JOIN keyword ?
Qest:
Write the following query using JOIN keyword ?
select ID_category from category_master X
where Exist(select 1 from sub_category Y where
X.ID_category=Y.ID_category)Edited by: 799660 on Oct 3, 2010 6:05 AMselect X.ID_category
from category_master X join (select distinct ID_category from sub_category) Y
on (X.ID_category=Y.ID_category)
/SY. -
How to write the select query with complex where condition
Hi all,
Can u help me in writing following select query.
select * from zu1cd_corr where time_stamp between firstday and lastday .
In the above query time_stamp contains the date and time.
where as firstday and lastday contains the dates.
I need to compare the date in the time_stamp with the firstday and lastday.
But time_stamp contains the time also and it is char of 14 characters length.Hi,
If that is the case u can do as advait specified....
if the firstday and secondday are select-options then declare two more variables having 14 character length and then concatenate '000000' to firstday variable and '240000' to last day variable and then write ur query.
CLEAR : lv_firstday,
lv_lastday.
concatenate firstday '000000' to lv_firstday.
concatenate lastday '240000' to lv_lastday.
ranges : r_Date for zu1cd_corr-time_stamp.
r_date-sign = 'I'.
r_date-option = 'BT'.
r_Date-low = lv_firstday.
r_Date-high = lv_lastday.
append r_date.
select * from zu1cd_corr into table it_zu1cd_corr where time_stamp in r_Date.
I hope it helps.
Regards,
Nagaraj -
How to write the SQL query for generating triangular numbers
Hi,
I have a table ..which stores the sequence number like this
Seq :
1000
1200
1300
1500
1800
1900
Now i want to get a result like this
1000 1000
1200 2200
1300 3500
1500 5000
1800 6800
1900 8700
how can it be achieved. I tried using Lead and lag. but only I can add the n+1 or n-1 results. Please help.I've never heard it called 'triangular numbers' before but I think you're looking for a 'running total':
SQL> WITH data AS
2 (
3 SELECT 1000 AS num FROM dual UNION ALL
4 SELECT 1200 AS num FROM dual UNION ALL
5 SELECT 1300 AS num FROM dual UNION ALL
6 SELECT 1500 AS num FROM dual UNION ALL
7 SELECT 1800 AS num FROM dual UNION ALL
8 SELECT 1900 AS num FROM dual
9 )
10 /* END SAMPLE DATA */
11 SELECT num, SUM(num) OVER (ORDER BY num) AS running_total
12 FROM data
13 ORDER BY 1
14 ;
NUM RUNNING_TOTAL
1000 1000
1200 2200
1300 3500
1500 5000
1800 6800
1900 8700
6 rows selected. -
How to write the below query with parameter and is null
Hi, I need to retrive the data if the parameter is passed on the field, else retrive all records whose field is null
Example
CREATE TABLE DEPT
(DEPTNO NUMBER(2),
DNAME VARCHAR2(14),
LOC VARCHAR2(13) );
INSERT INTO DEPT VALUES (10, 'ACCOUNTING', 'NEW YORK');
INSERT INTO DEPT VALUES (20, 'RESEARCH', 'DALLAS');
insert into dept values (30, 'SALES', 'CHICAGO');
INSERT INTO DEPT VALUES (40, 'OPERATIONS', 'BOSTON');
alter table dept add(object_id number);
insert into dept values (50, 'OPERATIONS', 'BOSTON',1);
insert into dept values (60, 'OPERATIONS', 'BOSTON',1);
INSERT INTO DEPT VALUES (70, 'OPERATIONS', 'BOSTON',2);
select * from dept where object_id =:p_object_id
If i pass the object_id as 1 , it shloud retrive the values of dept with object_id 1, but if i dont pass the object_id, it should retrive all the records whose object_id is null
IF 1 is passed, as object id , it should retrive, 50, 60, if 1 is not passed as object_id it should retive 10,20,30,40
It works fine for me seperately as,
select * from dept where object_id =:p_object_id -- 1
select * from dept where object_id is null;
Is this possible to do in single query.
ThanksSELECT *
FROM dept
WHERE object_id = :p_object_id
OR (object_id is null and :p_object_id is null)
is one approach. It's a bit verbose but the meaning is clear. If you can identify a value that would never appear in the data (-1 for example)
WHERE nvl( object_id, -1 ) = nvl(p_object_id, -1 );
Justin -
Re-write query with ANY operator
Hi,
How to write the given query using 'ANY ' operator , I dont need to fetch to grade_master table twice in database, just need to fetch within the result set.
SELECT dsg_code,dsg_name,dsg_grade FROM designation_master WHERE dsg_orgn='&&Orgn' and dsg_ctry='&&ctry'
And dsg_loc ='&&loc' And dsg_oru = '&&oru' and dsg_grade in decode('&&radio_group',
1, SELECT grd_code FROM grade_master WHERE grd_osm_code in (Select grd_osm_code FROM grade_master WHERE grd_orgn='&&Orgn' and grd_ctry='&&ctry' And grd_loc ='&&loc' And grd_oru = '&&oru' and grd_code ='&&emp_grade'),
2, SELECT grd_code FROM grade_master WHERE grd_osm_code > (Select grd_osm_code FROM grade_master WHERE grd_orgn='&&orgn' and grd_ctry='&&ctry' and grd_loc ='&&loc' And grd_oru = '&&oru' and grd_code),
3, SELECT grd_code FROM grade_master WHERE grd_osm_code < (Select grd_osm_code FROM grade_master WHERE grd_orgn='&&orgn' and grd_ctry='&&ctry' And grd_loc ='&&loc' And grd_oru = '&&oru' and grd_code ='&&emp_grade'))
thanks
rincyplease post your question in separate SQL and PL/SQL section this is FORMS section
-
How to resolve the error while using user defined function.
EPN Assembly file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xmlns:wlevs="http://www.bea.com/ns/wlevs/spring"
xmlns:jdbc="http://www.oracle.com/ns/ocep/jdbc"
xmlns:spatial="http://www.oracle.com/ns/ocep/spatial"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd
http://www.bea.com/ns/wlevs/spring
http://www.bea.com/ns/wlevs/spring/spring-wlevs-v11_1_1_3.xsd
http://www.oracle.com/ns/ocep/jdbc
http://www.oracle.com/ns/ocep/jdbc/ocep-jdbc.xsd
http://www.oracle.com/ns/ocep/spatial
http://www.oracle.com/ns/ocep/spatial/ocep-spatial.xsd">
<wlevs:event-type-repository>
<wlevs:event-type type-name="TestEvent">
<wlevs:class>com.bea.wlevs.event.example.FunctionCEP.TestEvent</wlevs:class>
</wlevs:event-type>
</wlevs:event-type-repository>
<wlevs:adapter id="InputAdapter"
class="com.bea.wlevs.adapter.example.FunctionCEP.InputAdapter">
<wlevs:listener ref="inputStream" />
</wlevs:adapter>
<wlevs:channel id="inputStream" event-type="TestEvent">
<wlevs:listener ref="processor" />
</wlevs:channel>
<wlevs:processor id="processor">
<wlevs:listener ref="outputStream" />
<wlevs:function function-name="sum_fxn" exec-method="execute">
<bean>com.bea.wlevs.example.FunctionCEP.TestFunction</bean>
</wlevs:function>
</wlevs:processor>
<wlevs:channel id="outputStream" event-type="TestEvent">
<wlevs:listener ref="bean" />
</wlevs:channel>
<bean id="bean" class="com.bea.wlevs.example.FunctionCEP.OutputBean">
</bean>
</beans>
Event class
package com.bea.wlevs.event.example.FunctionCEP;
public class TestEvent {
private int num_1;
private int num_2;
private int sum_num;
public int getSum_num() {
return sum_num;
public void setSum_num(int sumNum) {
sum_num = sumNum;
public int getNum_1() {
return num_1;
public void setNum_1(int num_1) {
this.num_1 = num_1;
public int getNum_2() {
return num_2;
public void setNum_2(int num_2) {
this.num_2 = num_2;
Adapter class
package com.bea.wlevs.adapter.example.FunctionCEP;
import com.bea.wlevs.ede.api.RunnableBean;
import com.bea.wlevs.ede.api.StreamSender;
import com.bea.wlevs.ede.api.StreamSource;
import com.bea.wlevs.event.example.FunctionCEP.TestEvent;
public class InputAdapter implements RunnableBean, StreamSource {
private StreamSender eventSender;
public InputAdapter() {
super();
public void run() {
generateMessage();
private void generateMessage() {
TestEvent event = new TestEvent();
event.setNum_1(10);
event.setNum_2(20);
eventSender.sendInsertEvent(event);
public void setEventSender(StreamSender sender) {
eventSender = sender;
public synchronized void suspend() {
Output Bean class
package com.bea.wlevs.example.FunctionCEP;
import com.bea.wlevs.ede.api.StreamSink;
import com.bea.wlevs.event.example.FunctionCEP.TestEvent;
import com.bea.wlevs.util.Service;
public class OutputBean implements StreamSink {
public void onInsertEvent(Object event) {
System.out.println("In Output Bean");
TestEvent event1 = new TestEvent();
System.out.println("Num_1 is :: " + event1.getNum_1());
System.out.println("Num_2 is :: " +event1.getNum_2());
System.out.println("Sum of the numbers is :: " +event1.getSum_num());
Function Class
package com.bea.wlevs.example.FunctionCEP;
public class TestFunction {
public Object execute(int num_1, int num_2)
return (num_1 + num_2);
config.xml file
<?xml version="1.0" encoding="UTF-8"?>
<wlevs:config xmlns:wlevs="http://www.bea.com/ns/wlevs/config/application"
xmlns:jdbc="http://www.oracle.com/ns/ocep/config/jdbc">
<processor>
<name>processor</name>
<rules>
<view id="v1" schema="num_1 num_2">
<![CDATA[
select num_1, num_2 from inputStream
]]>
</view>
<view id="v2" schema="num_1 num_2">
<![CDATA[
select sum_fxn(num_1,num_2), num_2 from inputStream // I am getting error when i am trying to call this function
]]>
</view>
<query id="q1">
<![CDATA[
select from v2[now] as num_2* // Showing error while accessing the view also ]]>
</query>
</rules>
</processor>
</wlevs:config>
Error I am getting is :
Invalid statement: "select >>sum_fxn<<(num_1,num_2),age from inputStream"
Description: Invalid call to function or constructor: sum_fxn
Cause: Probable causes are: Function name sum_fxn(int,int) provided is invalid, or arguments are of
the wrong type., or Error while handling member access to complex type. Constructor sum_fxn of type
sum_fxn not found. or Probable causes are: Function name sum_fxn(int,int) provided is invalid, or
arguments are of the wrong type., or Error while handling member access to complex type.
Constructor sum_fxn of type sum_fxn not found.
Action: Verify function or constructor for complex type exists, is not ambiguous, and has the correct
number of parameters.
I have made a user defined function in a java class and configured this function in the EPN assembly file under the processor tag.
But when i am trying to access the function in the config.xml file , it is giving me an error in the query.
Please provide urgent help that how to write the exact query.Hi,
In the EPN Assembly file use
<bean class="com.bea.wlevs.example.FunctionCEP.TestFunction"/>
instead of
<bean>com.bea.wlevs.example.FunctionCEP.TestFunction</bean>
Best Regards,
Sandeep -
How to write a sql query to retrieve data entered in the past 2 weeks
Hi,
I have file names and last accessed date(java.sql.Date format) stored in my database table, I would like to know how I can write a query to get the name of files accessed in the past 2 weeks,I use open sql server at the back end.
Thanks in advance.This has essentially nothing to do with JDBC. JDBC is just an API to execute the SQL language using Java and thus interact with the databases.
Your problem is related to the SQL language, you don't know how to write the SQL language. I suggest you to go through a SQL tutorial (there is one at w3schools.com) and to read the SQL documentation which come along with the database in question. A decent database manfacturer has a website and probably also a discussion forum / mailinglist as well.
I'll give you a hint: you can just use equality operators in SQL like everywhere. For example: "WHERE date < somedate". -
In DBI , how to find out the Source Query used for the Report
Hi All,
How to find out the Source Query used to display the data in the DBI Reports or Dashboards. We can get it in Apps Front end by Going to Help and Record Histroty. But DBI Runs in Internet Explorer so i dont know how to get the source query ( SELECT Query ) Used.
In IE we have View --> Source . But that does not help since it gives the HTML Coding and not the SELECT Query used.
If anyone has ever worked on it...Please help me in finding it.
Thanks,
Neeraj ShrivastavaHi neeraj,
You can see the query used to display reports.Follow these steps to get the query.
1)Login to oracle apps
2)Select "Daily Business Intelligence Administrator" responsiblity.
3)Now click on "Enable/Disable Debugging" (Now u enabled debugging)
4)now open the report which you want to see the query of
5)In view source it displays query along with the bind varilables.
Feel free to ping me if you have any doubts
thanks
kittu -
How to find the processing time of any query?
im using oracle express edition, can anyone help me, how to find the processing time of any query?
Trace the query and tkprof the generated trace file.
http://download.oracle.com/docs/cd/E11882_01/server.112/e16638/sqltrace.htm#PFGRF01010 -
How can i write the below code using "For all entries"
Hi
How can we write the below code using "for all entries" and need to avoid joins...
Please help
SELECT aaufnr aobjnr aauart atxjcd a~pspel
agstrp awerks carbpl cwerks
INTO TABLE t_caufv
FROM caufv AS a
INNER JOIN afih AS b
ON aaufnr = baufnr
INNER JOIN crhd AS c
ON bgewrk = cobjid
AND c~objty = 'D'
WHERE ( a~pspel = space
OR a~txjcd = space
OR NOT a~objnr IN
( select OBJNR from COBRB AS e
WHERE objnr = a~objnr ) )
AND a~werks IN s_plant
AND a~auart IN s_wtype
AND NOT a~objnr IN
( select OBJNR from JEST AS d
WHERE objnr = a~objnr
AND ( dstat = 'A0081'OR dstat = 'A0018' )
AND d~inact 'X' ).
Reward points for all helpfull answers
Thanks
Ammi.Hi,
SELECT objnr objid aufnr
from afih
into table t_afih.
SELECT objnr
from JEST
into table t_JEST
where stat = 'A0045'
OR stat = 'A0046'
AND inact 'X'.
SELECT objnr
from COBRB
into table t_cobrb.
SELECT arbpl werks objid objty
from crhd
INTO table it_crhd
FOR ALL ENTRIES IN it_afih
WHERE objty eq 'D'
AND gewrk = it_afih-objid.
SELECT aufnr objnr auart txjcd pspel gstrp werks aufnr
FROM caufv
INTO table t_caufv
FOR ALL ENTRIES IN it_afih
WHERE aufnr = it_afih-aufnr
And pspel = ' '
AND txjcd = ' '
ANd objnr ne it_crhd-objnr
AND auart in s_wtype
AND werks in s_plant.
AND objnr ne it_jest-objnr.
dont use NE in the select statements, it may effect performance also. Instead use if statements inside
loops.
loop at t_caufv.
read table it_chrd............
if t_caufv-objnr ne it_chrd-objnr.
read table it_jest..........
if if t_caufv-objnr ne it_jest-objnr.
(proceed further).
endif.
endif.
endloop.
hope this helps.
Reward if useful.
Regards,
Anu -
How to write the query for year revenue and avg
Hello Team
I have the table
create table sale (sale_id varchar2(32) not null, sale_epoch_microsec numeric(18,0)
not null, sale_amount_cents numeric(18,0) not null, customer_id varchar2(32)
not null, industry_id varchar2(32) not null, product_id varchar2(32) not null)The industry the customer is considered to be in can change from sale to sale. sale_epoch_microsec is microseconds since epoch; sale_amount_cents is the value of the sale in pennies.
The data in this is:
Insert into SALE
(SALE_ID, SALE_EPOCH_MICROSEC, SALE_AMOUNT_CENTS, CUSTOMER_ID, INDUSTRY_ID,
PRODUCT_ID)
Values
('s1', 200000000, 69985484589459, 'c1', 'i1',
'p1');
Insert into SALE
(SALE_ID, SALE_EPOCH_MICROSEC, SALE_AMOUNT_CENTS, CUSTOMER_ID, INDUSTRY_ID,
PRODUCT_ID)
Values
('s2', 200000000, 69985484589459, 'c2', 'i2',
'p2');
Insert into SALE
(SALE_ID, SALE_EPOCH_MICROSEC, SALE_AMOUNT_CENTS, CUSTOMER_ID, INDUSTRY_ID,
PRODUCT_ID)
Values
('s3', 6579000000, 6.99675342390895E16, 'c3', 'i3',
'p3');
Insert into SALE
(SALE_ID, SALE_EPOCH_MICROSEC, SALE_AMOUNT_CENTS, CUSTOMER_ID, INDUSTRY_ID,
PRODUCT_ID)
Values
('s4', 6.5866459684979E17, 6.99675343454391E17, 'c4', 'i4',
'p4');
1.) SQL: Write the SQL query to determine, year-over-year, the total revenue and avg. per-product revenue from customers in the 'Gaming' industry.josh1612 wrote:
As in the question it's mentioned that the date is in microseconds,
So i need the guidence to convert that to the date .Convert microseconds to seconds and then you may be able to use the function below which was found here:
http://www.oracle.com/technology/pub/articles/oracle_php_cookbook/fuecks_dates.html
CREATE OR REPLACE
FUNCTION unixts_to_date(unixts IN PLS_INTEGER) RETURN DATE IS
* Converts a UNIX timestamp into an Oracle DATE
unix_epoch DATE := TO_DATE('19700101000000','YYYYMMDDHH24MISS');
max_ts PLS_INTEGER := 2145916799; -- 2938-12-31 23:59:59
min_ts PLS_INTEGER := -2114380800; -- 1903-01-01 00:00:00
oracle_date DATE;
BEGIN
IF unixts > max_ts THEN
RAISE_APPLICATION_ERROR(
-20901,
'UNIX timestamp too large for 32 bit limit'
ELSIF unixts < min_ts THEN
RAISE_APPLICATION_ERROR(
-20901,
'UNIX timestamp too small for 32 bit limit' );
ELSE
oracle_date := unix_epoch + NUMTODSINTERVAL(unixts, 'SECOND');
END IF;
RETURN (oracle_date);
END; -
Can u write the following query without using group by clause
select sp.sid, p.pid, p.name from product p, supp_prod sp
where sp.pid= p.pid and
sp.sid = ( select sid from supp_prod group by sid
having count(*) =(select count(*) from product));
thru this, we retrieving all the products delivered by the supplier.
Can you write the following query without using the group by clauseselect sp.sid, p.pid, p.name
from product p, supp_prod sp
where sp.pid= p.pid the above query will still retrieve all the products supplied by the supplier. sub-query is not necessary.
maybe if you can post some sample data and output will help us understand what you want to achieve. -
Can any one tell me how to write the properites files and how to acces
can any one tell me how to write the properites files and how to acces thoose files
plz let me no
thanks in advancehttp://www.exampledepot.com/egs/java.util/Props.html
Maybe you are looking for
-
I'm looking for this font to use with final cut pro 6.0.1: http://img223.imageshack.us/img223/9837/fonthk4.png where can I download it?
-
Security for Advanced Editing Options
I work in a regulated environment and need to remove the ability for all end users to access the TouchUp Text Tool in the Advanced Editing Menu. NOTE WE ARE USING ACROBAT STANDARD V6.0.1. Can I make a change in the registry to remove this option? Any
-
Cannot select objects in Adobe Fireworks
I suddenly could not select objects in Adobe Fireworks on my MacBook Pro. I was using a Magic Mouse. I replace the mouse, but the problem persisted - it wasn't the mouse I restarted Fireworks, but the problem persisted - it wasn't Fireworks I searche
-
I cannot authorize my Kobo.
My computer is authorized in my Adobe digital editions, but when I go to open a file on my Kobo, I get a message that the content I am trying to view is locked and than a message to use my adobe id to autorize my ereader with the Adobe Digital Editio
-
I have an updated imac G3 with 10.3.9 installed - the Appleworks updater always says that it needs the original US discs - I have used one of the many discs we have ( Australian ?). The programme runs until you use the paint or draw tools then it qui