Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: SQL in perl/tk

by chacham (Prior)
on Jan 13, 2012 at 11:59 UTC ( [id://947733]=note: print w/replies, xml ) Need Help??


in reply to SQL in perl/tk

The query should be executed by Oracle, not by the driver, hence the complexity should not matter. As marto said, turn on error reporting.

BTW, you can rewrite "AND (gamm.PROCESS_NAME = 'SAM_Exact_Product_Search' OR gamm.APPLICATION_NAME = 'SAM_Exact_Product_Search')" as "AND 'SAM_Exact_Product_Search' IN (gamm.PROCESS_NAME, gamm.APPLICATION_NAME)"

. Get's rid of the OR and only requires the literal once.

trunc(gmz.testtime) will obviate the use of any INDEX on gmz.testtime, better to use AND gmz.testtime >= to_date('09/12/2011','MM/DD/YYYY') AND gmz.testtime < to_date('09/16/2011','MM/DD/YYYY')

IIUC, i don't think you need to specify TO_CHAR in the GROUP BY clause.

For formatting the query, so people can read it, try:

SELECT
	gamm.PROCESS_NAME,
	GAMM.APPLICATION_NAME,
	TO_CHAR(TRUNC(gmz.testtime - 7 / 24, 'DD'),'MM/DD/YYYY')
	Fiscal_Day,
	ROUND
	(
	 AVG
	 (
	  DECODE(total_response_time, 0, NULL, total_response_time)
	  / DECODE (total_page_count,0, 1,total_page_count)
	 )
	 / 1000,
	 2
	) Average_Response_time
FROM
	portal_gomez_bb_load		gmz,
	GOMEZ_APP_MAPPING_MASTER	gamm
WHERE
	gmz.monitor_id			= 3805260
  AND	'SAM_Exact_Product_Search'	IN (gamm.PROCESS_NAME, gamm.APPLICATION_NAME)
  AND	gmz.testtime			>= to_date('09/12/2011','MM/DD/YYYY')
  AND	gmz.testtime			< to_date('09/16/2011','MM/DD/YYYY')
  AND	success_flag			= 0
GROUP BY
	gamm.PROCESS_NAME,
	GAMM.APPLICATION_NAME,
	TRUNC (gmz.testtime - 7 / 24, 'DD');

Replies are listed 'Best First'.
Re^2: SQL in perl/tk
by vsurend (Novice) on Jan 16, 2012 at 06:33 UTC

    Hi All, Thanks a lot for all the replies. I have tried to include the piece of SQL code by inserting into my code. But this too is not giving any results. I am using the correct Userid/pwd/schema etc. for this. Please find the piece of code I have written.

    use strict; use Tk; use Tk::BrowseEntry; use Tk::LabFrame; use Tk::JPEG; use DBI; use DBD::Oracle; use Spreadsheet::WriteExcel; . . . . . . . sub generateDailyReport{ #Create Excel my $workbook = Spreadsheet::WriteExcel->new('Report.xls'); my $worksheet = $workbook->add_worksheet(); my $from_date = @_[0]; my $to_date = @_[1]; #Connect to DB my $dbh = DBI->connect("dbi:Oracle:cecdev9","asdm_dev","c1sc0pass" +) or die "cannot connect $DBI::errstr\n"; my $sth = $dbh->prepare("SELECT gamm.PROCESS_NAME, GAMM.APPLI +CATION_NAME, TO_CHAR (TRUNC (gmz.testtime - 7 / 24, 'DD'),'MM/DD/YYYY +') Fiscal_Day,ROUND (AVG(DECODE (total_response_time, 0, NULL, total_ +response_time) / DECODE (total_page_count,0, 1,total_page_count))/ 10 +00,2) Average_Response_time FROM portal_gomez_bb_load gmz, GOMEZ_AP +P_MAPPING_MASTER gamm WHERE gmz.monitor_id = 3805260 AND (gamm.PROC +ESS_NAME = 'SAM_Exact_Product_Search' OR gamm.APPLICATION_NAME = 'SAM +_Exact_Product_Search') AND trunc(gmz.testtime) BETWEEN to_date('09/1 +2/2011','MM/DD/YYYY') AND to_date('09/15/2011','MM/DD/YYYY') AND succ +ess_flag = 0 GROUP BY gamm.PROCESS_NAME,GAMM.APPLICATION_NAME,TO_CH +AR (TRUNC (gmz.testtime - 7 / 24, 'DD'),'MM/DD/YYYY')"); #execute the query $sth->execute(); my $i = "A1"; my $j = 1; while ( my @row = $sth->fetchrow_array( ) ) { print "@row\n"; $worksheet->write($i, \@row); $j=$j+1; $i="A$j"; open(FILE,'Report.xls'); } }
    Please help. Thanks, Vidya Surendran

      Did you read the replies you already have? I advised that you look at tracing, which you've not done in this example.

        Hi Marto, Yes I checked. But I am afraid, I dont know how to check the trace for DBD. Can you please help. :( Thanks, Vidya Surendran
      Check for an error: die $dbh->errstr if ! defined $msg;

      Not only after the DB connect, but after the statement is run.

        Hurray! got the issue... It was that wrong userid/pwd that eat up my days....Thanks a lot for all the valuable suggestions.....

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://947733]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-18 04:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found