Get Recordcount of last Query
Hi,is it possible to get the number of records of the last SQL-Query inside a Stored Procedure.
I´m trying to get my Stored Procedure faster and the problem is, that there are many code snippets like the following:
--check if there are any records
Select count(*) INTO v_cnt FROM XXX WHERE XXXX=XXXX;
--if there are records
IF v_cnt > 0 THEN
--get the data of this records
SELECT a,b,c INTO v_a,v_b,v_c FROM XXX WHERE XXXX=XXXX;
END IF;
Now i want to solve this with one SQL-Statement.
BEGIN
SELECT a,b,c INTO v_a,v_b,v_c FROM XXX WHERE XXXX=XXXX;
--Catch the "No data found"-Exception
EXCEPTION WHEN OTHERS THEN
NULL;
END;
IF (??theglobalvariablethatisearch??) > 0 THEN
END IF;
Is there such a "global Variable" in Oracle SQL??
Thanks
Why not eliminate the IF altogether? If NO_DATA_FOUND isn't raised, the number of rows must be > 0
BEGIN
SELECT a,b,c
INTO v_a,v_b,v_c
FROM XXX
WHERE XXXX=XXXX;
<<contents of the THEN clause of your IF statement>>
--Catch the "No data found"-Exception
EXCEPTION
WHEN OTHERS
THEN
NULL;
END;Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC
Similar Messages
-
Last query refresh failde due to internal errors ?
Hi gurus
we are working on SRM 7.0 with PPS,
when Bidder tries to open his login page and wants to see the Rfx raised against him, He is getting error message,
" Last query refresh failed due to internal error" , some time this is due to another session witht he same query is open , but
I am getting the same error in the following situation,
suppose bidder has submittted his response and after submission he is trying to change the response and couldn't submit before the submission dead line then the version of the response will be c1, and which is not interpreted by the system, and so the error is .
Any help or advice on the issue is highly appreciated.
Regards
NITIN
Edited by: nitinkk on Jan 12, 2012 7:55 AMDear Rahul,
Thanks for replay,
I have checked it but the issue comes with the discribe procedure.
and we have solved it now.
Regards
NITIN -
How to get the recordcount of a query in a array
I have an array called "sums" that holds 4 query's, each
query has a different number of records.
Then i use this code to loop the records of the query inside
the array:
<cfloop index="x" from="1" to="#arrayLen(sums)#">
<cfloop index="i" from="1" to="#sums[x].recordcount#">
data to loop
</cfloop>
</cfloop>
This results in 4 times 4 records, of course as i now use the
array length in the inner loop.
My question is, how can i get the recordcount of a query in a
array so i can use that for the inner loop "to" value.
Thanks.quote:
Originally posted by:
MarcovandenOever
Does sums[x]recordcount point to the first query in the array
sums when i use it like this?
In the array there are four query's, i want to loop the
array, then i want to loop the records of each query.
<cfloop index="x" from="1" to="#arrayLen(sums)#">
<cfloop index="i" from="1" to="#sums[x].recordcount#">
data to loop
</cfloop>
</cfloop>
No. It points to each query in turn. So if you have four
queries, the first time it will point to sum[1]. Then next time
sum[2], etcetera. It should work exactly the way you want "as is".
If you are having a problem, it is probably related to the code
inside your inner loop. -
Get the last query from the current user
Is there a way to get the last query of the current user, so every query could be log with a database trigger?
Let's just say I execute:
DELETE xxxx;
I tried :
SELECT T.SQL_TEXT FROM V$SQLAREA T where ADDRESS=(SELECT prev_sql_addr FROM v$session where audsid=userenv('sessionid'));
But the result of this query is :
'SELECT T.SQL_TEXT FROM V$SQLAREA T where ADDRESS=(SELECT prev_sql_addr FROM v$session where audsid=userenv('sessionid'))'
Is there a way to execute a query that would return :
'DELETE xxxx'
ThanksYou could join SQL_ADDR in v$session with ADDRESS in v$sqlarea to determine the SID that executed that SQL statement last. Note that PREV_SQL_ADDR in v$session will indicate the previous SQL he executed. Though you would have to look at these tables very often to get all SQL statements issued. One note here, I think if a different user ran the SAME SQL with just bind var differences the SQL_AREA will only show the last userâs information that executed it.
BTW - it will show deletes also... -
It is required to get the result set from the last query.
I need this SP to return the result set from the last query.
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
alter proc spQ_GetASCBillingRateIDs2
@ScheduleID CHAR(15),
@startdate smalldatetime,
@enddate smalldatetime
as
set nocount on
truncate table tbltmpgroup
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tbltmptbltest]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tbltmptbltest]
exec sp_CreateTblTmpGroup
insert into tbltmpgroup
SELECT DISTINCT
case when pd.billparent = 'N' then org.eligibleorgid
else isnull(af.parentid, org.eligibleorgid) end as billorgid,
pd.individualbill , pd.cobrabill, pd.billparent,
org.eligibleorgid, org.polid, org.orgpolicyid,
pp.planid, pp.rateid,
ps.ascinvoicedate,
case when ps.ascclaimfromdate > @startdate then ps.ascclaimfromdate
else @startdate end as premiumrundayFrom,
case when ps.ascclaimtodate < @enddate then ps.ascclaimtodate
else @enddate end as premiumrundayTo,
fts.effdate, fts.termdate,
case when fts.effdate > @startdate then fts.EffDate
else @startdate end as ascStartDate,
case when fts.termdate < @enddate then fts.termdate
else @enddate end as ascEndDate
FROM premiumschedule ps (nolock)
inner join orgpolicy org (nolock)
on org.ascinvoicerungroup between ps.premiumrundayfrom and ps.premiumrundayto
inner join FundingTypeStatus fts
on fts.orgpolicyid = org.orgpolicyid
and fts.fundtype = 'ASC'
and ((fts.effdate between @startdate and @enddate)
or (fts.termdate between @startdate and @enddate)
or (fts.effdate < @startdate and fts.termdate > @enddate))
inner join eligibilityorg o (nolock)
on org.eligibleorgid = o.eligibleorgid
inner join policydef pd (nolock)
on pd.polid = org.polid
inner join policyplans pp (nolock)
on pp.polid = org.polid
inner join program p (nolock)
on pd.programid = p.programid
left join orgaffiliation af with (nolock)
on org.eligibleorgid = af.childid
WHERE ps.premiumscheduleid = @ScheduleID
AND org.orgpolicyid <> ''
go
SELECT DISTINCT z.rateid, e.enrollid, z.ascstartdate, z.ascenddate
into tbltmptbltest FROM enrollment E (nolock)
inner join tbltmpgroup z
on e.rateid = z.rateid
go
CREATE UNIQUE CLUSTERED INDEX IDXTempTable ON tbltmptbltest(enrollid)
create index IDXTemptableDates on tbltmptbltest(ascstartdate,ascenddate)
go
select distinct t.*
from tbltmpgroup t
where rateid in (
select distinct t.rateid from VW_ASC_Billing)
order by billorgid
set nocount off
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GOPlease post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules (you have no idea).
Temporal data should use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect.
What you did post is bad SQL.
The prefix “tbl-” is a design flaw called tibbling and we do not do it. We seldom use temp tables in RDBMS; it is how magnetic tape file programmers fake scratch tapes.
If the schema is correct, then SELECT DISTINCT is almost never used.
Your “bill_parent” looks like a assembly language bit flag; we never use those flags in SQL.
“Funding_Type_Status” is an absurd name for a table. A status is a state of being, not an entity. A type is an attribute property. So this table ought to be column that is either a “funding_type” or “funding_status” (with the time period for the state of being
shown in other columns). But this hybrid is not possible in a valid data model.
Want to try again, with DDL and some specs?
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
How can I get only the last 2 rows?
How can I narrow down a query to get only the last two rows in a table ?
Thanks,
MohanThanks a lot Ram for your suggestion but already I have a query which returns a set of rows, of which I would like to further filter and get the last two rows
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Ramanuj Bangad ([email protected]):
try out something like this if it helps.
Example:
select * from users
where rownum <= (select count(*) from users)
minus
select * from users
where rownum <= (select count(*) -2 from users )
<HR></BLOCKQUOTE>
null -
Get the second last occurrence of character
Hi
I want to get the second last occurrence of "_" from the following string and then take the 3 characters before this.
Does anyone know how to do it in a simple query?
The string is
ALS_AKM-G-2500_BASED_pre_paid_akm_mis_stv1user2360027 wrote:
I wanted a simple query. The regular expressions are too much for me to understand :-)Not difficult at all:
regexp_replace(txt, '.*(.{3})_[^_]*_.*$', '\1')
\------------------/ \/\----/|\---/|\/| \--/
| | | | | || | |
| | | | | || | and replace that found matching pattern with what is in backreference 1
| | | | | || | (the 3 characters found in the pattern)
| | | | | || followed by the end of the string
| | | | | ||
| | | | | |followed by any characters
| | | | | |
| | | | | followed by an "_" character
| | | | |
| | | | followed by any number of non "_" characters
| | | |
| | | followed by an "_" character
| | |
| | followed by any 3 characters (mark as a back reference using brackets)
| |
| where it matches any number of characters
|
replace the section of string txt -
Displaying the Last Query Refresh date/time
Hello,
on a Webi report, is there a way to display the date/time that the underlying info provider was refreshed?
Thanks,
Nikhi1.- Create Formula in Query (columns - Create Formula)
2.- Create Formula Variable for this Formula (Type Customer EXIT) as individual and optional.
3.- Define the code for customer exits for variables.
*-- To get Timestamp for last load of data to cube
WHEN 'ZLSTLOADDT'.
DATA: lt_tab_1 TYPE TABLE OF rsdcubemulti,
ls_tab_1 TYPE rsdcubemulti,
lt_tab_2 TYPE TABLE OF rsmonicdp,
ls_tab_2 TYPE rsmonicdp.
DATA: l_calday TYPE d,
l_time TYPE sy-uzeit,
l_tzone TYPE ttzz-tzone,
l_string TYPE char20.
SELECT * FROM rsdcubemulti INTO TABLE lt_tab_1
WHERE infocube = i_s_cob_pro-infoprov
AND objvers = 'A'.
SORT lt_tab_1 DESCENDING.
CLEAR ls_tab_1.
READ TABLE lt_tab_1 INTO ls_tab_1 INDEX 1.
REFRESH lt_tab_2.
SELECT * FROM rsmonicdp INTO TABLE lt_tab_2
WHERE icube = ls_tab_1-partcube.
SORT lt_tab_2 DESCENDING.
CLEAR ls_tab_2.
READ TABLE lt_tab_2 INTO ls_tab_2 INDEX 1.
l_tzone = 'INDIA'. "CET, UTC...
CONVERT TIME STAMP ls_tab_2-timestamp TIME ZONE l_tzone
INTO DATE l_calday "aaaammdd
TIME l_time. "hhmmss
l_s_range-low = l_calday.
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
APPEND l_s_range TO e_t_range.
EXIT.
WHEN 'ZLSTLOADTM'.
DATA: lt_tab_1 TYPE TABLE OF rsdcubemulti,
ls_tab_1 TYPE rsdcubemulti,
lt_tab_2 TYPE TABLE OF rsmonicdp,
ls_tab_2 TYPE rsmonicdp.
DATA: l_calday TYPE d,
l_time TYPE sy-uzeit,
l_tzone TYPE ttzz-tzone,
l_string TYPE char20.
SELECT * FROM rsdcubemulti INTO TABLE lt_tab_1
WHERE infocube = i_s_cob_pro-infoprov
AND objvers = 'A'.
SORT lt_tab_1 DESCENDING.
CLEAR ls_tab_1.
READ TABLE lt_tab_1 INTO ls_tab_1 INDEX 1.
REFRESH lt_tab_2.
SELECT * FROM rsmonicdp INTO TABLE lt_tab_2
WHERE icube = ls_tab_1-partcube.
SORT lt_tab_2 DESCENDING.
CLEAR ls_tab_2.
READ TABLE lt_tab_2 INTO ls_tab_2 INDEX 1.
l_tzone = 'INDIA'. "CET, UTC...
CONVERT TIME STAMP ls_tab_2-timestamp TIME ZONE l_tzone
INTO DATE l_calday "aaaammdd
TIME l_time. "hhmmss
l_s_range-low = l_time.
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
APPEND l_s_range TO e_t_range.
EXIT. -
Get dates of last week - Please Help !
Hi All,
I have to make a query for retrieving the data for the last one week from a table say "Orderdata".
So can anybody please tell me how to retrieve date of last weak from the current date. I mean if current date is 12/08/2004 (mm/dd/yyyy) then I would be needing date as :--
12/01/2004 (mm/dd/yyyy) to 12/07/2004 (mm/dd/yyyy).
To more clear, here is the query that am using :
select * from orderdata where orderdate between 12/01/2004 AND 12/07/2004
I know I would be needing java.sql.timestamp class to set date . but it is the last thing to do .
First I have to get date of last weak...........
Here is the code----------that i have just start to write ..
Calendar cal;
TimeZone tz;
String estTimezone="GMT-05:00";
tz=TimeZone.getTimeZone(estTimezone);
cal=new GregorianCalendar(tz);
cal.setTimeZone(tz);
String currentdate=String.valueOf(cal.get(Calendar.MONTH)+1);
currentdate+="/"+String.valueOf(cal.get(Calendar.DAY_OF_MONTH)-1);
currentdate+="/"+String.valueOf(cal.get(Calendar.YEAR));
out.println(currentdate);And assume if current date is 12/1/2004 (mm/dd/yyyy) then subtracting -1 form the current date will give 12/00/2004 so not getting the correct result .
Hope it is clear to all................
Please Help !
amitindiaHi All,
Thanks chirag813 for your coding. and thanks to all.
By the way I have to change time in EST and also required start date and end date of last weak. So my final coding is as:
Please have a look into the code and tell me whether the code is correct / fine or not.
Do I need to call the getInstance() method in my code as you (chirag813) have put in your code
Calendar calendar = Calendar.getInstance();
Is my code fine ?
Please Answer..................
String startdate;
String enddate;
Calendar cal;
TimeZone tz;
String estTimezone="GMT-05:00";
// is this line correct to get startdate
SimpleDateFormat sdfStartdate= new SimpleDateFormat("yyyy-MM-dd 00:00:00");
// is this line correct to get enddate
SimpleDateFormat sdfEnddate= new SimpleDateFormat("yyyy-MM-dd 23:59:59");
tz=TimeZone.getTimeZone(estTimezone);
cal=new GregorianCalendar(tz);
cal.setTimeZone(tz);
cal.add(Calendar.DATE,-7);
startdate=sdfStartdate.format(cal.getTime());
cal.add(Calendar.DATE,6);
enddate=sdfEnddate.format(cal.getTime());
Timestamp t1=Timestamp.valueOf(startdate);
Timestamp t2=Timestamp.valueOf(enddate);
out.println(t1);
out.println("<br>"+t2);
And finally I have used Timestamp class to change the date (String) to Timestampt.
Thanks !
amitindia
SCJP 1.2 -
Filters not getting passed in MDX query while using SAP BW with OBIEE
Hello,
I've been working on OBIEE with SAP BW as back-end. I've created some reports & those are working fine when there is less amount of data. But when I try to run a report with 3 dimensions & 1 fact it throws an error saying "No more storage space available for extending an internal table". When I checked MDX query, I found that the filters that I had applied to request & also selected from prompts are not getting passed in that query. So, I tried running a simple request using a simple filter in Answers. Although this request returns results but I can't see filter conditions in query. MDX query always show crossjoin but I can't see filter conditions anywhere.
Is it the normal OBIEE behaviour OR am I doing something wrong in there? Can you please help me out with this?
Thanks,
RockyHello Sainath,
We tried those things. But it is still giving same error.
State: HY00. Code: 10058. [NQODBC][SQL_STATE:HY000][nQSError: 10058] A general error has occurred. XML/A error returned from the server: Fault code: "XMLAnalysisError.0X80000005". Fault string: "The XML for Analysis provider encountered an error: MDX result contains too many cells (more than 1 million)". (HY000)
The problem here, I think, is the filter parameters are not getting passed in the MDX query. Any idea why would that happen? Is there any setting to do so?
Thanks in advance for help.
Regards,
Rocky -
When I try to sync my iPad and iPhone it will get within the last 3 pictures then stop giving me an APPCRASH error message. Then iTunes will shut down. No matter what I do to increase or decrease the number of pictures it always stops 3rd from the last.
Problem Event Name: APPCRASH
Application Name: iTunes.exe
Application Version: 10.4.0.80
Application Timestamp: 4e262cfr
Fault Module Name: QuickTime.qts
Fault Module Version: 7.70.80.34
Exception Code: c0000005
Exception Offset: 00146b30
OS Version 1033
Locale ID:
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information4: 0a9e372d3b4ad19135b953a78882e789
Any assistance I can get will be greatly appreciated.Thank you iTunes for fixing the problem of downloading my pictures to my iPad and iPhone with the update 10.5.0.142
-
How to get Current month last year sale in report
HI,
I would like to compare the sale value of a month for any year.
ie sale of the march month for this year ,previous year and a year before ..like that
at least for two years..ie current and prvious year.
how can i get it done in query?
thnxCreate three restricted key figures.
In one restrict month by current month.
In other use offset of -12 and -24 while restricting current month. -
How to get material's last posting date of issuing to production order?
Hi,
In my scenario, I need to get material's last posting date of issuing to production order (e.g. mov. typ. 261).
I tried to select the material documents whose movement type is 261, and restrict the posting date from month to month each time, until the first material document is selected.
But this method seems quite inefficient.
What kind of algorithm is more effient to do this?
Thanks
WesleyHi,
select max( budat )
from mkpf
into gv_budat
where mblnr in ( select mblnr
from aufm
where aufnr = gv_aufnr "(Prod. Order)
and matnr = gv_matnr "(Issued Material)
and bwart = '261' ).
Edited by: Azeem Ahmed Matte on Mar 12, 2010 12:33 PM -
My laptop is stolen and hasn't showed up in my cloud for the past week but the name of it is changed. How do I get it's last known location?
That"s part of my problem, I dont get that option.
I get iTunes store and that's about it.
I've thought about "erasing/resetting" all settings but I'm afraid to do it. Or am I
missing something in iTunes?
Help please!
Joanne -
How can i now the number of rows afected by the last query?
how can i now the number of rows afected by the last query?
For example:
i made this update :
update trl_trial set status = 1 /* Validation */
where trial_id = cobject_id
and status = 0; /* Initial */
if NUMBERS_OF_ROWS = 0 then
end if;
how can i do this?
thank u!!!!how can i now the number of rows afected by the last query?
For example:
i made this update :
update trl_trial set status = 1 /* Validation */
where trial_id = cobject_id
and status = 0; /* Initial */
if NUMBERS_OF_ROWS = 0 then
end if;
how can i do this?
thank u!!!! Do the following :
update trl_trial set status = 1 /* Validation */
where trial_id = cobject_id
and status = 0; /* Initial */
if(SQL%ROWCOUNT = 0 ) then
else
end if;
you can also declare a variable and do
myvar := SQL%ROWCOUNT;
SQL%ROWCOUNT returna the # of rows afected by any sql
statement, like DELETE, UPDATE
Maybe you are looking for
-
How can i take out the glitches
the video i recorded has glitches. how can i take out the glitches. or minimize them.
-
Please reply ASAP-Discoverer and BI Publisher
Hi, Could some one please list the pros and cons from switching from Discoverer to BI Publisher? I know it seems kinda vague but anything you have experienced would be helpful. New to both tools at this moment. Thanks so much!
-
Downloading Acrobat Reader Sharon Avisar - 02:18pm Jan 19, 2009 Pacific Good Evening, I've been tried to download "acrobat reader 9" so many times without success. In addition, I've tried few weeks ago to download this program to another computer. Pl
-
How to uninstall DNG converter5.6 on windows 7 before installing 6.6 version
how to uninstall DNG converter 5.6 version on windows 7 before install 6.6 version
-
Unable to stop (deallocate) virtual machines
I have two Azure Virtual Machines that seem to be stuck in a "Stopped" state. Since they're not "Stopped (deallocated) this means I'm still being charged as if they're running (as I understand it). When I attempt to shut them down with the Azure Ma