Top parent query
Greetings,
I have a table with records of following fomat.
Parent Child
a b
b c
a d
I needed a query ,into which if I am passing b,c or d as a parameter,it will return its top parent a.
There is no row like (a,NULL) which would have made it easier for me to identify the top parent.
Any help is appreciated. Thanks in advance.
Regards
George
select parent
from t t1
where not exists (select null
from t t2
where t2.child = t1.parent)
start with child = 'c'
connect by prior parent = child;
Similar Messages
-
Top N query giving error for oracle 8.0.6
Dear All,
We are executing this query SELECT XBLNR, WERKS, MATNR, MDV01, BACKFLQUANT, STATUS, SAPTIMESTAMP, PITSTIMESTAMP, PMTIMESTAMP, BATCH FROM (SELECT XBLNR, WERKS, MATNR, MDV01, BACKFLQUANT, STATUS, SAPTIMESTAMP, PITSTIMESTAMP, PMTIMESTAMP, BATCH FROM PMBPITS.PITS_UNITY WHERE STATUS = '01' ORDER BY PMTIMESTAMP) WHERE ROWNUM < 20
on oracle 8.0.6 but this is giving the following error
ora - 00907 missing right parenthesis error
1. Is it that in the inner select we cannot use order by and where clause together.
2. We also found that if we remove order by from inner select then the query is not giving error
pls help . points will be awardedHi,
what ever the Aman said is correct. You check this is supported in 8.1.5, SQL allows you to embed the ORDER BY clause in a subquery and place the ROWNUM condition in the top-level query;
'Top-N query' is a ORACLE 8i feature which is supported in SQL. However,
Bug:855720 states the following:
"PL/SQL does not support top-N queries (ORDER BY in SUBSELECT/SUBQUERY
or VIEW. Since this feature is available in SQL, but not in PL/SQL,
it has been logged as a Bug that will be fixed in 8.1.6."
- Pavan Kumar N -
Top N query with INLIST Iterator performance problem
I have a top N query that is giving me problems on Oracle 11.2.0.3.
First of all, I have a query like the following (simplified from the real query, but produces the same problem):
select /*+ gather_plan_statistics */ * from
select rowid
from payer_subscription ps
where ps.subscription_status = :i_subscription_status
and ps.merchant_id = :merchant_id2
order by transaction_date desc
) where rownum <= :i_rowcount; This query works well. It can very efficiently find me the top 10 rows for a massive data set, using an index on merchant_id, subscription_status, transaction_date.
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
| 0 | SELECT STATEMENT | | 1 | | 10 |00:00:00.01 | 4 |
|* 1 | COUNT STOPKEY | | 1 | | 10 |00:00:00.01 | 4 |
| 2 | VIEW | | 1 | 11 | 10 |00:00:00.01 | 4 |
|* 3 | INDEX RANGE SCAN DESCENDING| SODTEST2_IX | 1 | 100 | 10 |00:00:00.01 | 4 |
-------------------------------------------------------------------------------------------------------As you can see the estimated actual rows at each stage are 10, which is correct.
Now, I have a requirement to get the top N records for a set of merchant_Ids, so if I change the query to include two merchant_ids, the performance tanks:
select /*+ gather_plan_statistics */ * from
select rowid
from payer_subscription ps
where ps.subscription_status = :i_subscription_status
and (ps.merchant_id = :merchant_id or
ps.merchant_id = :merchant_id2 )
order by transaction_date desc
) where rownum <= :i_rowcount;
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
| 0 | SELECT STATEMENT | | 1 | | 10 |00:00:00.17 | 178 | | | |
|* 1 | COUNT STOPKEY | | 1 | | 10 |00:00:00.17 | 178 | | | |
| 2 | VIEW | | 1 | 200 | 10 |00:00:00.17 | 178 | | | |
|* 3 | SORT ORDER BY STOPKEY| | 1 | 200 | 10 |00:00:00.17 | 178 | 2048 | 2048 | 2048 (0)|
| 4 | INLIST ITERATOR | | 1 | | 42385 |00:00:00.10 | 178 | | | |
|* 5 | INDEX RANGE SCAN | SODTEST2_IX | 2 | 200 | 42385 |00:00:00.06 | 178 | | | |Notice now that there are 42K rows coming out of the two index range scans - Oracle is no longer aborting the index range scan when it reaches 10 rows. What I thought would happen, is that Oracle would get at most 10 rows for each merchant_id, knowing that at most 10 rows are to be returned by the query. Then it would sort that 10 + 10 rows and output the top 10 based on the transaction date, but it refuses to do that.
Does anyone know how I can get the performance of the first query, when I need to pass a list of merchants into the query? I could probably get the performance using a union all, but the list of merchants is variable, and could be anywhere between 1 or 2 to several 100, so that makes that a bit unworkable.Across the two merchants_id's there are about 42K rows (this is in test, on Prod there could be several million). In the first query example, Oracle can answer the query in about 4 logical IOs and without even doing a sort as it uses the index to scan and get the relevant rows in Oracle.
In the second case, I hoped it would pull 10 rows for each merchant_id and then sort the resulting 20 rows to find the top 10 ordered by transaction_date, but instead it is scanning far more rows than it needs to.
In my example, it takes 4 logical IOs to answer the first query, but ~ 170 to answer the second, while I think it is achievable in 8 or so. For example, this query does what I want, but it is not a feasible option due to how many merchant_id's I may have to deal with:
select /*+ gather_plan_statistics */ *
from
select *
from
select * from
select merchant_id, transaction_date
from payer_subscription ps
where ps.subscription_status = :i_subscription_status
and ps.merchant_id = :merchant_id
order by transaction_date desc
) where rownum <= :i_rowcount
union all
select * from
select merchant_id, transaction_date
from payer_subscription ps
where ps.subscription_status = :i_subscription_status
and ps.merchant_id = :merchant_id2
order by transaction_date desc
) where rownum <= :i_rowcount
) order by transaction_date desc
) where rownum <= :i_rowcount;
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
| 0 | SELECT STATEMENT | | 1 | | 10 |00:00:00.01 | 6 | | | |
|* 1 | COUNT STOPKEY | | 1 | | 10 |00:00:00.01 | 6 | | | |
| 2 | VIEW | | 1 | 20 | 10 |00:00:00.01 | 6 | | | |
|* 3 | SORT ORDER BY STOPKEY | | 1 | 20 | 10 |00:00:00.01 | 6 | 2048 | 2048 | 2048 (0)|
| 4 | VIEW | | 1 | 20 | 20 |00:00:00.01 | 6 | | | |
| 5 | UNION-ALL | | 1 | | 20 |00:00:00.01 | 6 | | | |
|* 6 | COUNT STOPKEY | | 1 | | 10 |00:00:00.01 | 3 | | | |
| 7 | VIEW | | 1 | 100 | 10 |00:00:00.01 | 3 | | | |
|* 8 | INDEX RANGE SCAN DESCENDING| SODTEST2_IX | 1 | 100 | 10 |00:00:00.01 | 3 | | | |
|* 9 | COUNT STOPKEY | | 1 | | 10 |00:00:00.01 | 3 | | | |
| 10 | VIEW | | 1 | 11 | 10 |00:00:00.01 | 3 | | | |
|* 11 | INDEX RANGE SCAN DESCENDING| SODTEST2_IX | 1 | 100 | 10 |00:00:00.01 | 3 | | | |
---------------------------------------------------------------------------------------------------------------------------------------This UNION ALL query completes in 6 logical IOs - the original query I posted with 2 IDs takes 178 to return the same results. -
Can we hide filter in Search Master agreements standard top level query?
Hi Experts,
I have a requirement to hide flter in standard Search Master Agreements top level query. See below screen shot
I have an idea how to delete filter in query but when i have added that query to top level navigation i don't have any idea.
So i want to hide Business Unit & Region filter in Search Master Agreement query when it is in top level navigation.
If anyone have idea please share with me how to hide.
Thanks,
LavaHi Lava,
It is not a filter but this a Standard field which is coming from the Master Agreement.
So, you cannot hide or even delete any field.
But if it is a custom field you can hide it by inactivating the respective field in Extension Defination.
Please let me know if you need any assistance.
Thanks,
Raj. -
Subquery referencing parent query table????
Well my problem ( which I hope has a solution :) ) is the following:
I work on a little OS Advertising project.
When an advertiser wants to start a campaign, he must see the list of the publisher websites where he can advertise.
::::SELECT [...] FROM website wsite[...]
With their places count
::::[...]COUNT(place.id) AS placeCnt[...]INNER JOIN place ON place.website_id = wsite.id[...]
-Yes but the websites that have at least 1 place
::::[...]GROUP BY wsite.id HAVING COUNT(place.id)>0[...]
-And here comes my big dead end problem:
I would like to remove the websites where the advertiser can't advertiser.
I mean by there > if every ads of the advertiser are blacklisted for the site "google.com", he can't see "google.com" in the list because he won't be able to advertiser on in anyway.
however, if the advertiser has 4 ads, and all of it are blacklisted excepted the 4th, he must see "google.com" because he can advertise with the ad #4.
There is 2 types of blacklisting :
targetted ( by defining a website id on the blacklist line )
global ( by setting the website id = null , so for example if ad#1 is globally blacklisted by user #1, ad#1 couldn't be able to advertise on every websites of user#1 )
I thought I found a solutoin put it doesn't seem to work:
::::WHERE 0< (
SELECT COUNT(DISTINCT ad.id)
FROM ad
LEFT OUTER JOIN blacklist bl ON bl.ad_id =ad.id AND (bl.website_id=wsite.id OR bl.site_id IS NULL)
WHERE ad.user_id= $userid
AND bl.id IS NULL
A concrete scenario example: ( SQL included at the end of the post )
the user [email protected] ( userid = 2 ) has 3 ads.
-"my forbidden ad" ( id = 1)
-"my ad" ( id = 2 )
-"my unappreciated ad" ( id = 3 )
the user [email protected] ( userid = 1 ) has 3 websites
-google.com ( id = 1 )
-yahoo.com ( id = 2 )
[email protected] has blacklisted the following ads:
-"my unappreciated ad" ON yahoo.com, type targetted, ( website_id = 2, ad_id = 3 , publisher_id = 1)
-"my forbidden ad" type global, ( website_id = null , ad_id = 1 publisher_id = 1)
so the publisher websites we'll see with the resulting query should be ( as the the advertiser, user 2 ) :
google.com
yahoo.com
lol.com
WHY?
-Because the advertiser can advertise thanks to ad 2 ( ad2 is allowed to be advertised on each website )
-Even if "forbidden ad" is blacklisted globally, unapprediated ad remains for google.com
NOW, if the publisher adds another blacklist restriction
-"my ad" , type global ( website_id = null, ad_id = 2 , publisher_id = 1)
the result would be ( as the the advertiser, user 2 )
google.com
WHY?
-Because the advertiser do not have any ad to put on yahoo.com. Ad 1 and Ad 2 are blacklisted globally, ad 3 is blacklisted for yahoo.com
WELL, I thought I found the solution by this query but mysql returns an error > unknown colum on the subquery
THe only thing I want to is to LINK the parent query WITH the subquery ON bl.site_id=psite.id
Enfin bon, tout ça pour un truc qui semblait être possible avec cette requête mais qui renvoie donc une erreur de unknown column:
SELECT wsite.*,COUNT(place.id) AS placeCnt
FROM website wsite
INNER JOIN place ON place.website_id = wsite.id
WHERE 0< (
SELECT COUNT(DISTINCT ad.id)
FROM ad
LEFT OUTER JOIN blacklist bl ON bl.ad_id =ad.id AND (*bl.website_id=wsite.id* OR bl.website_id IS NULL)
WHERE ad.advertiser_id= 2
AND bl.id IS NULL
GROUP BY wsite.id
HAVING COUNT(place.id)>0
WELL THANKS A LOT to have read this post, AND THANK YOU EVEN MORE IF SOMEONE FIND A TRICK!
PS :
( the only solution I can see for the moment is a loop like )
foreach($publisher_sites as $s){
if(advertiserCanAdvertiser($s['id'])) $sites[]=$s
but the performances are really bad
I think the following would help :)
MySQL Data Transfer
Source Host: localhost
Source Database: orads
Target Host: localhost
Target Database: orads
Date: 10/20/2009 1:02:03 PM
SET FOREIGN_KEY_CHECKS=0;
-- Table structure for ad
DROP TABLE IF EXISTS `ad`;
CREATE TABLE `ad` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(32) NOT NULL,
`url` varchar(50) NOT NULL,
`advertiser_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
-- Table structure for blacklist
DROP TABLE IF EXISTS `blacklist`;
CREATE TABLE `blacklist` (
`id` int(11) NOT NULL auto_increment,
`ad_id` int(11) NOT NULL,
`website_id` int(11) default NULL,
`publisher_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
-- Table structure for place
DROP TABLE IF EXISTS `place`;
CREATE TABLE `place` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(32) NOT NULL,
`website_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
-- Table structure for user
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int(11) NOT NULL auto_increment,
`email` varchar(64) NOT NULL,
`password` varchar(16) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
-- Table structure for website
DROP TABLE IF EXISTS `website`;
CREATE TABLE `website` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(32) NOT NULL,
`url` varchar(32) NOT NULL,
`publisher_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
-- Records
INSERT INTO `ad` VALUES ('1', 'my forbidden ad 1', 'http://www.no.com', '2');
INSERT INTO `ad` VALUES ('2', 'my ad 2', 'http://www.lol.com', '2');
INSERT INTO `ad` VALUES ('3', 'my unappreciated ad 3', 'http://www.abc.com', '2');
INSERT INTO `blacklist` VALUES ('1', '1', null, '1');
INSERT INTO `blacklist` VALUES ('2', '3', '2', '1');
INSERT INTO `place` VALUES ('1', 'banner1', '1');
INSERT INTO `place` VALUES ('2', 'yahoo banner', '2');
INSERT INTO `user` VALUES ('1', '[email protected]', 'publisher');
INSERT INTO `user` VALUES ('2', '[email protected]', 'advertiser');
INSERT INTO `website` VALUES ('1', 'google', 'http://www.google.com', '1');
INSERT INTO `website` VALUES ('2', 'yahoo', 'http://www.yahoo.com', '1');
Edited by: user12086067 on Oct 20, 2009 4:51 AMHi,
Welcome to the forum!
Interesting problem!
Here's one way to do that in Oracle:
SELECT DISTINCT w.*
FROM website w
JOIN place p ON p.website_id = w.id
JOIN ad a ON w.publisher_id NOT IN (
SELECT b.publisher_id
FROM blacklist b
WHERE b.ad_id = a.id
AND COALESCE ( b.website_id
, w.id
) = w.id
WHERE a.advertiser_id = 2 -- parameter
;Thanks for posting the CREATE TABLE and INSERT statements. Since this is an Oracle forum, you should post statementts that will work in Oracle.
I don't know anything about MySQL, so I don't know if you'll need to change query above or not.
This doesn't quite produce the output you requested, since lol.com isn't in the website table. Do you need to get lol.com from the user table somehow? -
Top utilising Query in SQL server
Hi,
Is there any query to get the top utilization query of the day?Hi,
Top CPU utilizing query
--This might take some time to give result on busy systemselect top 10
sum(qs.total_worker_time) as total_cpu_time,
sum(qs.execution_count) as total_execution_count,
count(*) as number_of_statements,
t.text
from
sys.dm_exec_query_stats qs
cross apply sys.dm_exec_sql_text(qs.sql_handle) as t
group by t.text
order by sum(qs.total_worker_time) desc
For memory utilization there is no perfect way to find out if query has completed. but
sys.dm_exec_query_memory_grants would help you
SELECT mg.granted_memory_kb, mg.session_id, t.text, qp.query_plan
FROM sys.dm_exec_query_memory_grants AS mg
CROSS APPLY sys.dm_exec_sql_text(mg.sql_handle) AS t
CROSS APPLY sys.dm_exec_query_plan(mg.plan_handle) AS qp
ORDER BY 1 DESC OPTION (MAXDOP 1)
Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it.
My TechNet Wiki Articles -
FM to retrieve Summarized BOM (CS13) and get TOP parent
Hi Gurus,
I'd like to know what FM should I use to retrieve BOM so that I will have the same data generated if I run tcode CS13.
I tried to use CS_BOM_EXPL_MAT_V2 but the number or items returned was much bigger compared to CS13.
I'd also like to know if there's a way to get the TOP parent using select statements.
Thanks in advance.
DexterWhat about CS_BOM_EXPLOSION and leaving import parameter MEHRS = space?
-
Hi,
I want to show top 3 salary records from emp table and I am using below query in oracle * plus. However I am getting an error saying, "FROM keyword not found where expected". I am not getting what mistake I am doing while writing this query. Can someone plz advice?
Query:
Select top 3 sal from emp;
Thanks in advance.Hi,
In Oracle, there is no TOP keyword. The usual way to do a top-N query in Oracle is to use an analytic function, such as RANK:
WITH got_r_num AS
SELECT sal
, ename, empno, ... -- whatever columns you want
, RANK () OVER (ORDER BY sal DESC) AS r_num
FROM scott.emp
SELECT sal
, ename, empno, ... -- if wanted
, r_num -- if wanted
FROM got_r_num
WHERE r_num <= 3
ORDER BY sal
;Depending on how you want to handle ties, ypu may want to add tie-breaking columns to the end of the analytic ORDER BY clause, and/or use ROW_NUMBER instead of RANK. -
How to find top utilized query for last two months in oem
how to find top utilized query for last two months in oracle enterprise manager?
Can you mark the thread as Helpful and once marked the information can be reviewed by other customer for similar queries
Regards
Krishnan -
Creating a TOP N Query with a time reference
Hello,
how can i create a TOP 5 Query which is giving me the highest sales order changes in the sales amount during the last day.
Following structure:
Sales Order
Extraction point
Sales(Amount)
I have already created a Top 5 Query which is giving me the 5 highest Sales order with the highest sales. But now i need a query which is giving me the 5 highest sales order during the last extraction point.
Thanks for any advice
Best regardsHi please try the below steps:
1. create a formula variable on the extract point.
2. Create a query only on Extract point as Char in row & formula keyfigure (FKF1) on the extract point formula variable.
3. Create a condition of Top 5 on the FKF1 on the above query.
4.Now come to your original query create a variable on the extract point char use the replacement path & select the query which you just created as the background query for this variable.
So the background query will provide only the TOP 5 extract point values to your original query.
Regards
Mahendra -
Displaying the result of the TOP N query
Hi all,
we are facing a challenging task were we are going to build a query that gives the answer on the question:
How many different materials (of the top sold) represent 80% of the total sales in quantity?
The result should of the query should be very short:
2002 2003 2004
Nr of materials
reps 80% 432 453 499
The query is build on a CO-PA based cube, where each line corresponds to a billing item with material and quantity.
By using a Top 80% condition on the quantity sold keyfigure we get out the top 80% materials sold:
Year Material QTYSold QTYSold-Ranked
2002 Mtr0323 10000 1
Mtr0262 9000 2
Mtr0243 8700 3
Mtr0763 600 423
Result 932000 423
2003 Mtr0123 9700 1
Mtr0332 9100 2
Mtr0243 8700 3
Mtr0763 543 453
Result 912000 453
We would like to supress the materials and only show the result row (or the raked position of the last material).
The problem is that the 'Calculate Single Value As' properties of a formula (or keyfigure) only applies on Displayed Data values. All tests we have done so far with 'supression of zeros' & 'always hide' has messed up or counting / ranking functions.
Is there any function in within formulas that have same functionality like Count,Rank etc?
Is there any other way to supress materials and only show results?
Any suggestions are welcome!Irina,
Should be achievable using exception aggregation and pre-query.
Create a query that gives the list of material that account for 80% of the sales using condition on the sales column.
In the second query, using exception aggregation, count the number of materials that make up this set for the year. Create a new calculated key figure with the formula as qual to sales key figure. In the properties window, press the enhance button and select count of all values in the first drop down and material in the second drop down. Filter the query on material with a characteristic variable with processing as replacement path. In the variable point it to the first query. Drilldown for this will be year.
This will give you number of materials for one year. If you want comparitive for three years, then three pre-queries and three variables with the calculated key figure restricted to a variable pointing to one years query.
You can use pre-calculated value sets to improve the run for the result query.
Cheers
Aneesh -
Multiple SQL Update within Parent Query
I am tring to extract an image from within a MS SQL image field,
opening the image using JAI, getting the src.getWidth() & src.getHeight
() of each item within the database, and then writing the width and
height back into the database. Everything works except when I goto
write the values into the database - the page (when loading) continues
to work and work and work until I restart the tomcat service. I do not
understand why this would occur, and what is even stranger - I have
very similar code i used for resizing images in the database into a
thumbnail - display and original file sizes using a similar approach...
and that works with out a problem...
I have tried the code with out the inner update query - it works. I
tried with just the selection of a single specific item in the first
query and that works, but when I try multiple updates the second query
appears to stall.
The code is as follows.:
<%@ page language="java" import="javax.servlet.*,javax.servlet.http.*,java.io.*,java.util.*,java.sql.*,javax.media.jai.*,java.awt.*,java.awt.image.*,java.awt.Graphics.*,java.awt.geom.*,java.awt.image.renderable.*,javax.media.jai.widget.*,com.jspsmart.upload.*,java.net.*,com.sun.media.jai.codec.*"%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<%
// Variables
int count=0;
int width = 0;
int height = 0;
String vFileName = "";
String vFileExt = "";
String vFileID = "";
String format = "0";
// Connect to the database
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://206.152.227.62:1433;DatabaseName=WWWBBD;User=wwwbbd;Password=bbd1412");
//Create the statement
Statement sqlGetPics = con.createStatement();
Statement sqlUpdate = con.createStatement();
//build the query
String qryGetPics = "SELECT TOP 5 FileID, FileExt, FileName, AdjFile = CASE WHEN FullFile IS NULL THEN Display ELSE FullFile END FROM FileStore WHERE (UPPER(FileExt) = '.JPG' OR UPPER(FileExt) = '.TIF' OR UPPER(FileExt) = '.GIF' OR UPPER(FileExt) = '.BMP') AND (NOT Display IS NULL OR NOT FullFile IS NULL)";
//execute the query
ResultSet rsGetPics = sqlGetPics.executeQuery(qryGetPics);
// Initialization
SmartUpload uploader = new SmartUpload();
uploader.initialize(getServletConfig(),request,response);
mySmartUpload.initialize(getServletConfig(), request, response);
// Upload
mySmartUpload.upload();
while (rsGetPics.next()) {
vFileID = rsGetPics.getString("FileID");
vFileExt = rsGetPics.getString("FileExt");
vFileName = rsGetPics.getString("FileName") + vFileExt;
width = 0;
height = 0;
uploader.fieldToFile(rsGetPics, "AdjFile", "/upload/" + vFileName);
if (vFileExt.equalsIgnoreCase(".JPG") || vFileExt.equalsIgnoreCase(".JPEG"))
format = "JPEG";
else if (vFileExt.equalsIgnoreCase(".TIF") || vFileExt.equalsIgnoreCase(".TIFF"))
format = "TIFF";
else if (vFileExt.equalsIgnoreCase(".GIF"))
format = "JPEG";
else if (vFileExt.equalsIgnoreCase(".BMP"))
format = "BMP";
else
format = "0";
// update the width & height
if (format != "0")
try
//Opens the image
RenderedImage src = JAI.create("fileload","d:\\servers\\tomcat\\webapps\\jsp\\upload\\" + vFileName);
width = src.getWidth();
height = src.getHeight();
java.io.File imageFile = new java.io.File("d:\\servers\\tomcat\\webapps\\jsp\\upload\\" + vFileName);
InputStream is = new FileInputStream(imageFile);
//build the query
String qryUpdate = "UPDATE FileStore SET Width = " + width + ", Height = " + height + " WHERE FileID = " + vFileID;
//execute the query
ResultSet rsUpdate = sqlUpdate.executeQuery(qryUpdate);
%>[<%=width%>x<%=height%>:<%=vFileID%>:<%=qryUpdate%>]<BR><%
catch(Exception e)
{out.println("An error occurs : " + e.toString());}
count++;
//rsUpdate.close();
sqlUpdate.close();
%>
<HTML>
<HEAD>
<TITLE>Repair Files</TITLE>
</HEAD>
<BODY>
<%=count%> files updated in the database.
</BODY>
</HTML>BTW - I also tried this with a prepared statment query... no good.
-
Hi All,
If it possible in WEBI, Can we create query on the top of the query in WEBI. I checked in sub query but it is query in the query.
select distinct DESK.fintransact from
(select distinct Top.fintransact, (Top.credit - Top.debit) as Amount
From
Iowa.findetail Top
inner join Iowa.fintransact Bug on Bug.fintransact = Top.fintransact
where (Top.account='10690 30115075' or Iowa.SAPAccountCode(Top.account) = '30115075')
AND (Bug.SUBLEDGER <> 'CD' AND Bug.SUBLEDGER <> 'CR' AND Bug.SUBLEDGER <> 'AP' AND Top.TRANSACTIONTYPE <> 'AP')
and Bug.ACCTDATE BETWEEN to_date(@Prompt('Enter the Account Beginning Date (MM/DD/YYYY) ','A',,mono,free),'MM/DD/YYYY') AND to_date(@Prompt('Enter the Account Ending Date (MM/DD/YYYY) ','A',,mono,free),'MM/DD/YYYY')
and Bug.COMPANY IN @Prompt('Iowa Health Name(s) or * for All','A','Sales Recap\Company',multi,free) OR ('*' IN @Prompt('Iowa Health Name(s) or * for All','A','Sales Recap\Company',multi,free))
) DESK
group by DESK.fintransact having sum(DESK.amount) = 0
The issue is the Inside query contains 2 objects Top.fintransact, (Top.credit - Top.debit) as Amount with the following results for date range
Inside Query
Top.fintransact Amount
204213 0
204093 0
204091 99595.01
203431 32332.91
322452 0
342342 33516.88
65765 0
Top Query
Top.fintransact Amount
204213 0
204093 0
322452 0
65765 0
I tried different way like Result from another query. I should feed the Top query result to another query.Thanks a lot your query worked and I can see exact data.
Could please help me in the following code this bit different which is in Custom SQL. In the code in the From Clause there is a code which acts as Table . How can I achieve this in WEBI as a single .
SELECT DISTINCT
PENDETAIL.TRADE,
PENDETAIL.PRODUCT,
PENTRANSACT.ACCTDATE,
PENDETAIL.PENTRANSACT,
PENTRANSACT.SAP_DOCUMENT_NO,
PENDETAIL.ACCOUNT,
Iowa.SAPAccountCode(PENDETAIL.ACCOUNT) sapact,
PENDETAIL.COUNTERPARTY,
PENDETAIL.QUANTITY,
PENDETAIL.CREDIT,
PENDETAIL.DEBIT,
SHIPMENTPENDTL.VESSEL,
PENDETAIL.DESCRIPTION,
(( PENDETAIL.CREDIT ) - ( PENDETAIL.DEBIT )) amt,
COUNTERPARTY_PENCP.SIC,
Iowa.SAPProfitCenter(PENDETAIL.ACCOUNT) a,
PENTRANSACT.COMPANY,
PENDETAIL.SHIPMENT,
PENDETAIL.SUBLEDGER,
NVL(PENDETAIL.CONTRACT,DEV_GROSS_LENGTH_DETAIL.CONTRACT),
PENDETAIL.PENDETAIL,
PENDETAIL.QUANTITYSTATUS,
PENDETAIL.QUALITY
FROM
PENDETAIL,
PENTRANSACT,
SHIPMENT SHIPMENTPENDTL,
COUNTERPARTY COUNTERPARTY_PENCP,
(Select distinct shipment, contract from PENdetail where contract is not null) DEV_GROSS_LENGTH_DETAIL
WHERE
( PENTRANSACT.PENTRANSACT=PENDETAIL.PENTRANSACT )
AND ( SHIPMENTPENDTL.SHIPMENT(+)=PENDETAIL.SHIPMENT )
AND ( PENDETAIL.SHIPMENT = DEV_GROSS_LENGTH_DETAIL.SHIPMENT)
AND ( COUNTERPARTY_PENCP.COUNTERPARTY=PENTRANSACT.COMPANY )
AND (
PENTRANSACT.ACCTDATE BETWEEN @variable('Enter the Beginning Date (MM/DD/YYYY)') AND @variable('Enter the Ending Date (MM/DD/YYYY)')
AND Iowa.SAPAccountCode(PENDETAIL.ACCOUNT) IN ('30110075', '30115075', '40110075', '40115075')
AND PENTRANSACT.COMPANY IN @variable('Enter Company Name')
In the code the difference is in the FROM Clause which acts a table :
(Select distinct shipment, contract from PENdetail where contract is not null) DEV_GROSS_LENGTH_DETAIL
In Where clause:
AND ( PENDETAIL.SHIPMENT = DEV_GROSS_LENGTH_DETAIL.SHIPMENT)
Select Clause:
NVL(PENDETAIL.CONTRACT,DEV_GROSS_LENGTH_DETAIL.CONTRACT),
For some code I think there is no need of derived table I guess. -
Another quick question
Is there a way to hide and lock down the SQL statement on the top of a query so the users do not see it when they execute a query? And lock it down swo that they can not open the window?
Thanks in advance again!!
DanaThis is most of users needed function but not built in yet. We don't have any options to hide them.
You may post your request to the following forum:
/community [original link is broken]
Thanks,
Gordon -
Can you change the data model query dynamically based on its parent query
Hi
Question:
I have a data model query q1 and q2 is the child of q1
Say q1 returns 2 rows and and
for the first row
i want q2 to be select 1 from table1
for the second row
i want q2 to be select 1 from table2
Basically i want to build the q2 dynamically
for each row fetched in q1.
Can this be done?
If so where do i write the code to achieve this
Thanx in advance.
SureshOne simple (but not very realistic) example:
1. DATABASE TABLES AND DATA
CREATE TABLE dept_all (
deptno NUMBER (2),
dname VARCHAR2 (20),
in_usa CHAR (1) DEFAULT 'Y')
INSERT INTO dept_all VALUES (10, 'DEPT 10', 'Y');
INSERT INTO dept_all VALUES (20, 'DEPT 20', 'N');
INSERT INTO dept_all VALUES (30, 'DEPT 30', 'Y');
CREATE TABLE emp_usa (
empno NUMBER (4),
ename VARCHAR2 (20),
deptno NUMBER (2))
INSERT INTO emp_usa VALUES (1001, 'EMP 1001', 10);
INSERT INTO emp_usa VALUES (1002, 'EMP 1002', 10);
INSERT INTO emp_usa VALUES (3001, 'EMP 3001', 30);
INSERT INTO emp_usa VALUES (3002, 'EMP 3002', 30);
CREATE TABLE emp_non_usa (
empno NUMBER (4),
ename VARCHAR2 (20),
deptno NUMBER (2))
INSERT INTO emp_non_usa VALUES (2001, 'EMP 2001', 20);
INSERT INTO emp_non_usa VALUES (2002, 'EMP 2002', 20);
2. DATABASE PACKAGE
Note that Oracle Reports 3.0 / 6i needs 'static' ref cursor type for building Report Layout.
So, in package specification we must have both ref cursor types, static for Report Layout
and dynamic for ref cursor query.
CREATE OR REPLACE PACKAGE example IS
TYPE t_dept_static_rc IS REF CURSOR RETURN dept_all%ROWTYPE;
TYPE t_dept_rc IS REF CURSOR;
FUNCTION dept_query (p_where VARCHAR2) RETURN t_dept_rc;
TYPE t_emp_rec IS RECORD (
empno emp_usa.empno%TYPE,
ename emp_usa.ename%TYPE);
TYPE t_emp_static_rc IS REF CURSOR RETURN t_emp_rec;
TYPE t_emp_rc IS REF CURSOR;
FUNCTION emp_query (
p_in_usa dept_all.in_usa%TYPE,
p_deptno dept_all.deptno%TYPE)
RETURN t_emp_rc;
END;
CREATE OR REPLACE PACKAGE BODY example IS
FUNCTION dept_query (p_where VARCHAR2) RETURN t_dept_rc IS
l_dept_rc t_dept_rc;
BEGIN
OPEN l_dept_rc FOR
'SELECT * FROM dept_all WHERE ' || NVL (p_where, '1 = 1') || ' ORDER BY deptno';
RETURN l_dept_rc;
END;
FUNCTION emp_query (
p_in_usa dept_all.in_usa%TYPE,
p_deptno dept_all.deptno%TYPE)
RETURN t_emp_rc
IS
l_emp_rc t_emp_rc;
l_table VARCHAR2 (30);
BEGIN
IF p_in_usa = 'Y' THEN
l_table := 'emp_usa';
ELSE
l_table := 'emp_non_usa';
END IF;
OPEN l_emp_rc FOR
'SELECT * FROM ' || l_table || ' WHERE deptno = :p_deptno ORDER BY empno'
USING p_deptno;
RETURN l_emp_rc;
END;
END;
3. REPORT - QUERY FUNCTIONS AND DATA LINK
FUNCTION q_dept RETURN example.t_dept_static_rc IS
BEGIN
-- "p_where" is a User Parameter
RETURN example.dept_query (:p_where);
END;
FUNCTION q_emp RETURN example.t_emp_static_rc IS
BEGIN
-- "in_usa" and "deptno" are columns from Parent Group (G_DEPT)
RETURN example.emp_query (:in_usa, :deptno);
END;
Of course, we must create Data Link between Parent Group (G_DEPT) and Child Query (Q_EMP).
Regards
Zlatko Sirotic
Maybe you are looking for
-
Adobe Bridge to CS4 Batch Problem
I hope this is the correct forum for this post as I don't know if its a Bridge or CS4 problem. If I carry out various adjustments in ACR from within bridge, then select a number of the adjusted files and run the CS4 Batch from within Bridge. (I.e. To
-
An error occurred while attempting to change modules while starting up LR 4.1. New install on a new MBP first time trying to start up
-
Anyone back-up iTunes or iPhoto using new TC?
Just curious if anyone has used it to back up those applications. That is the main reason why I have bought the TC. Wireless access for the whole family to iPhoto and Itunes. ??
-
How to use english date spelling in german speaking countries
Hi I'm in a german speaking country, and use Numbers to create german and english spreadsheets. My problem is that i can't get Numbers to display weekdays in date-formatted cells in english, although my Mac is running english, and i'm using a US keyb
-
Launched Mail today and all items in DRAFTS are gone -- poof! Dozens and dozens of hours lost. Any way to get them back? Maybe by restoring a backup?