How to determine number of records in recordset returned by stored procedure?
In TestStand 3.0 I am calling an SQL stored procedure where the stored
procedure returns a recordset. Everything appears to work (I can
iterate through the recordset and see that the data is valid).
However, I can not figure out how to easilly determine how many
records are actually in the recordset. Unlike the 'Open SQL
Statement' step, in the 'Data Operation' step that actually invokes
the stored procedure, there is no 'Number of Records Selected' option
to specify a TestStand variable to accept this value. I know I could
iterate through the returned recordset incrementing a counter until a
Fetch fails, but for larger recordsets, traversing the table multiple
times would be quite time consuming
. I am hoping to avoid this if
possible. Is there an easier way to get the number of records in a
recordset returned from a stored procedure call?
Bob
Bob -
The cursor type of the ADO Recordset object affects whether the number of records can be determined. The Recordset.RecordCount property will return -1 for a forward-only cursor; the actual count for a static or keyset cursor; and either -1 or the actual count for a dynamic cursor, depending on the data source.
Because ADO does not let me set the cursor type for command objects which is what a stored procedure requires, it is up to the data source to determine the type of cursor and the support for record count.
Scott Richardson (NI)
Scott Richardson
National Instruments
Similar Messages
-
How to get an updatable ADODB Recordset from a Stored Procedure?
In VB6 I have this code to get a disconnected ADODB Recordset from a Oracle 9i database (the Oracle Client is 10g):
Dim conSQL As ADODB.Connection
Dim comSQL As ADODB.Command
Dim recSQL As ADODB.Recordset
Set conSQL = New ADODB.Connection
With conSQL
.ConnectionString = "Provider=OraOLEDB.Oracle;Password=<pwd>;Persist Security Info=True;User ID=<uid>;Data Source=<dsn>"
.CursorLocation = adUseClientBatch
.Open
End With
Set comSQL = New ADODB.Command
With comSQL
.ActiveConnection = conSQL
.CommandType = adCmdStoredProc
.CommandText = "P_PARAM.GETALLPARAM"
.Properties("PLSQLRSet").Value = True
End With
Set recSQL = New ADODB.Recordset
With recSQL
Set .Source = comSQL
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOptimistic
.Open
.ActiveConnection = Nothing
End With
The PL/SQL Procedure is returning a REF CURSOR like this:
PROCEDURE GetAllParam(op_PARAMRecCur IN OUT P_PARAM.PARAMRecCur)
IS
BEGIN
OPEN op_PARAMRecCur FOR
SELECT *
FROM PARAM
ORDER BY ANNPARAM DESC;
END GetAllParam;
When I try to update some values in the ADODB Recordset (still disconnected), I get the following error:
Err.Description: Multiple-step operation generated errors. Check each status value.
Err.Number: -2147217887 (80040E21)
Err.Source: Microsoft Cursor Engine
The following properties on the Command object doesn't change anything:
.Properties("IRowsetChange") = True
.Properties("Updatability") = 7
How can I get an updatable ADODB Recordset from a Stored Procedure?4 years later...
I was having then same problem.
Finally, I've found how to "touch" the requierd bits.
Obviously, it's hardcore, but since some stupid at microsoft cannot understand the use of a disconnected recordset in the real world, there is no other choice.
Reference: http://download.microsoft.com/downlo...MS-ADTG%5D.pdf
http://msdn.microsoft.com/en-us/library/cc221950.aspx
http://www.xtremevbtalk.com/showthread.php?t=165799
Solution (VB6):
<pre>
Dim Rst As Recordset
Rst.Open "select 1 as C1, '5CHARS' as C5, sysdate as C6, NVL(null,15) as C7, null as C8 from DUAL", yourconnection, adOpenKeyset, adLockBatchOptimistic
Set Rst.ActiveConnection = Nothing
Dim S As New ADODB.Stream
Rst.Save S, adPersistADTG
Rst.Close
Set Rst = Nothing
With S
'Debug.Print .Size
Dim Bytes() As Byte
Dim WordVal As Integer
Dim LongVal As Long
Bytes = .Read(2)
If Bytes(0) <> 1 Then Err.Raise 5, , "ADTG byte 0, se esperaba: 1 (header)"
.Position = 2 + Bytes(1)
Bytes = .Read(3)
If Bytes(0) <> 2 Then Err.Raise 5, , "ADTG byte 9, se esperaba: 2 (handler)"
LongVal = Bytes(1) + Bytes(2) * 256 ' handler size
.Position = .Position + LongVal
Bytes = .Read(3)
If Bytes(0) <> 3 Then Err.Raise 5, , "ADTG, se esperaba: 3 (result descriptor)"
LongVal = Bytes(1) + Bytes(2) * 256 ' result descriptor size
.Position = .Position + LongVal
Bytes = .Read(3)
If Bytes(0) <> 16 Then Err.Raise 5, , "ADTG, se esperaba: 16 (adtgRecordSetContext)"
LongVal = Bytes(1) + Bytes(2) * 256 ' token size
.Position = .Position + LongVal
Bytes = .Read(3)
If Bytes(0) <> 5 Then Err.Raise 5, , "ADTG, se esperaba: 5 (adtgTableDescriptor)"
LongVal = Bytes(1) + Bytes(2) * 256 ' token size
.Position = .Position + LongVal
Bytes = .Read(1)
If Bytes(0) <> 6 Then Err.Raise 5, , "ADTG, se esperaba: 6 (adtgTokenColumnDescriptor)"
Do ' For each Field
Bytes = .Read(2)
LongVal = Bytes(0) + Bytes(1) * 256 ' token size
Dim NextTokenPos As Long
NextTokenPos = .Position + LongVal
Dim PresenceMap As Long
Bytes = .Read(3)
PresenceMap = Val("&H" & Right$("0" & Hex$(Bytes(0)), 2) & Right$("0" & Hex$(Bytes(1)), 2) & Right$("0" & Hex$(Bytes(2)), 2))
Bytes = .Read(2) 'ColumnOrdinal
'WordVal = Val("&H" & Right$("0" & Hex$(Bytes(0)), 2) & Right$("0" & Hex$(bytes(1)), 2))
'Aca pueden venir: friendly_columnname, basetable_ordinal,basetab_column_ordinal,basetab_colname
If PresenceMap And &H800000 Then 'friendly_columnname
Bytes = .Read(2) 'Size
LongVal = Bytes(0) + Bytes(1) * 256 ' Size
.Position = .Position + LongVal * 2 '*2 debido a UNICODE
End If
If PresenceMap And &H400000 Then 'basetable_ordinal
.Position = .Position + 2 ' 2 bytes
End If
If PresenceMap And &H200000 Then 'basetab_column_ordinal
.Position = .Position + 2 ' 2 bytes
End If
If PresenceMap And &H100000 Then 'basetab_colname
Bytes = .Read(2) 'Size
LongVal = Bytes(0) + Bytes(1) * 256 ' Size
.Position = .Position + LongVal * 2 '*2 debido a UNICODE
End If
Bytes = .Read(2) 'adtgColumnDBType
'WordVal = Val("&H" & Right$("0" & Hex$(Bytes(0)), 2) & Right$("0" & Hex$(bytes(1)), 2))
Bytes = .Read(4) 'adtgColumnMaxLength
'LongVal = Val("&H" & Right$("0" & Hex$(Bytes(3)), 2) & Right$("0" & Hex$(Bytes(2)), 2) & Right$("0" & Hex$(Bytes(1)), 2) & Right$("0" & Hex$(Bytes(0)), 2))
Bytes = .Read(4) 'Precision
'LongVal = Val("&H" & Right$("0" & Hex$(Bytes(3)), 2) & Right$("0" & Hex$(Bytes(2)), 2) & Right$("0" & Hex$(Bytes(1)), 2) & Right$("0" & Hex$(Bytes(0)), 2))
Bytes = .Read(4) 'Scale
'LongVal = Val("&H" & Right$("0" & Hex$(Bytes(3)), 2) & Right$("0" & Hex$(Bytes(2)), 2) & Right$("0" & Hex$(Bytes(1)), 2) & Right$("0" & Hex$(Bytes(0)), 2))
Dim ColumnFlags() As Byte, NewFlag0 As Byte
ColumnFlags = .Read(1) 'DBCOLUMNFLAGS, First Byte only (DBCOLUMNFLAGS=4 bytes total)
NewFlag0 = ColumnFlags(0)
If (NewFlag0 And &H4) = 0 Then 'DBCOLUMNFLAGS_WRITE (bit 2) esta OFF
'Lo pongo en ON, ya que quiero escribir esta columna LOCALMENTE en el rst DESCONECTADO
NewFlag0 = (NewFlag0 Or &H4)
End If
If (NewFlag0 And &H8) <> 0 Then 'DBCOLUMNFLAGS_WRITEUNKNOWN (bit 3) esta ON
'Lo pongo en OFF, ya que no me importa si NO sabes si se puede updatear no, yo lo se, no te preocupes
'ya que quiero escribir esta columna LOCALMENTE en el rst DESCONECTADO
NewFlag0 = (NewFlag0 And Not &H8)
End If
If (NewFlag0 And &H20) <> 0 Then 'DBCOLUMNFLAGS_ISNULLABLE (bit 5) esta OFF
'Lo pongo en ON, ya que siendo un RST DESCONECTADO, si le quiero poner NULL, le pongo y listo
NewFlag0 = (NewFlag0 Or &H20)
End If
If NewFlag0 <> ColumnFlags(0) Then
ColumnFlags(0) = NewFlag0
.Position = .Position - 1
.Write ColumnFlags
End If
.Position = NextTokenPos
Bytes = .Read(1)
Loop While Bytes(0) = 6
'Reconstruyo el Rst desde el stream
S.Position = 0
Set Rst = New Recordset
Rst.Open S
End With
'TEST IT
On Error Resume Next
Rst!C1 = 15
Rst!C5 = "MUCHOS CHARS"
Rst!C7 = 23423
If Err.Number = 0 Then
MsgBox "OK"
Else
MsgBox Err.Description
End If
</pre> -
How i get number of record in repet frame?
Hi,
How i get number of record in repet frame?
Regards
JomarJomar,
you can use Summary Columns in the Data Modell. Create them on group higher that your wished group (so on the pane for an first group of a query), use as Source the primary column and as reset at the group, where the summary column is located.
If you hide some instances via format triggers, that you could use a counter inside the format triggers to count the rows.
Regards
Rainer -
How to determine number of photos I have?
I cannot find anywhere in Photoshop Elements where it tells the total of photographs I have in my collection. The old version told this number in the lower right hand corner. Is there somewhere in this newer version where I can find how many photos I have without having to count them? Please help. Thanks.
Thanks so much Neale!!!
In a message dated 2/19/2014 7:05:52 P.M. Eastern Standard Time,
[email protected] writes:
Re: How to determine number of photos I have?
created by nealeh (http://forums.adobe.com/people/nealeh) in Photoshop
Elements - View the full discussion
(http://forums.adobe.com/message/6137888#6137888) -
How to determine number range for billing document based on company code ..
Hi Friends!!
can anybody tell me how to determine number range for billing document based on company code & tax departure country if required??
Amit...plz help me!!Hi Amit,
1. Define different Billing Document number ranges in SPRO -> Sales & Dist -> Billing -> Define number ranges for billing docs. (VN01). Make sure that all are internal number ranges.
e.g.
NO. From number To Number Current number Ext
A1 0930000000 0930999999
A2 0940000000 0940999999
A3 0950000000 0950999999
2. Define a Ztable ZNUMB_RANGE as follows
Comp. Code | Tax departure country | Billing Doc Type | Number Range
100 IN F2 A1
200 IN F2 A2
200 US F2 A3
3. In user exit RV60AFZZ (USEREXIT_NUMBER_RANGE)
Read table ZNUMB_RANGE for Number Range with Comp. Code, Tax country and Billing Doc.
If found pass this number range value to us_range_intern.
us_range_intern is a standard SAP variable which tells program which number range use to create the current document which is under process.
Let me know if you are clear.
Thanks,
Mandar -
How many number of input/output arguments allowed in Stored procedure
Please let me know how may input and output arguments are allowed in Oracle stored procedure.
I wan't to writer one generic SP and for that I need to know the limitation on the number of arguments. I am using Oracle 8.0.5.The output from the BPEL process will be in XML format.
Your requirement is not clear, please state it properly what are you trying to do.
-Yatan -
Howto:pass an ado.recordset to a stored procedure
Hi,
I need to pass an adodb.recordset to a stored procedure in Oracle 8.0.5.
I am programming with visualbasic 6, an exe application.
I don4t know how to setting the parameter for the adodb.command which execute the procedure.
Any idea??
Thanks,
Cesar,Hi,
You can't do this using an OLEDB provider. There is no such a provider with this feature.
Yuancai (Charlie) Ye
See 30 real well-tested advanced OLEDB samples
Use of free SocketPro for creating super client and server application with numerous samples
www.udaparts.com -
How to find the columns and tables used in a stored procedure?
Hi,
Can someone suggest how to find the columns and tables used within a stored procedure?
Thanks
VBKFor example:
SQL> create or replace
2 procedure p1
3 is
4 cnt number;
5 begin
6 select count(*) into cnt from emp;
7 end;
8 /
Procedure created.
SQL> select referenced_owner,
2 referenced_name
3 from dba_dependencies
4 where owner = 'SCOTT'
5 and name = 'P1'
6 and referenced_type = 'TABLE'
7 /
REFERENCED_OWNER REFERENCED_NAME
SCOTT EMP
SQL> SY. -
Updateable recordset from a stored procedure
I would like to retrieve an updateable recordset from a stored procedure using the oracle 9.2.0.2.0
oledb provider
I am using the sample code/tables provided from Oracle.
Does anyone have an example or has actually created an updatedable recordset from a stored procedure ?Assuming your stored procedure is returning a REF CURSOR, it cannot be done. Oracle's REF CURSORS are read only constructs.
Justin -
How to count number of records for a field based on condition?
Hi guys,
I want to know how to find count of records coming from the database for a particular field based on some condition.
I need to use this count to suppress some headers. Because of this i am not able to use running totals. Is there any other way?
Ex scenario:
I have account number and currency fields, those are coming from database. And i need to count the number of accounts whose currency is not Euro.
Thanks in advance,
Vijay.A simple formula can do that:
//Formula begin
if {your account field}<>"Euro" then 1
//Formula end
This formula can be summarized. (by group or report)
Bryan Tsou@Taiwan -
How to find number of records in a cube and ODS....
Hi,
How do we find total number of records in a cube and ODS?
Is there any Tcode for this ?
From the content it is difficult to get the number of records, if it is more in number.
Thanks,
JeetuHello ,
Please check the following thread,
Number of records in a infocube
hope it helps,
assign points if helpful. -
How to get number of records in all user tables in one select
Please advise how to retrieve the number of records in all user tables in one select. I would likt to extract the data to excel file.
Many thanks,
AndrewYou could always analyze the tables:
declare
begin
for X in (select owner, table_name from all_tables
minus
select owner, table_name from all_external_tables) LOOP
dbms_stats.Gather_Table_Stats(X.Owner, X.Table_Name) ;
end loop;
end;
/Then: Select Owner, Table_Name, Num_Rows from All_Tables ; -
Hi Gurus! how to count number of records in any column of ALV Grid report
Hi Guys!
I want to know how can we count the number of records in any column selected by the user. Like for oe customer there might be 20 sale order that means for 10 customer there will be 200 Sale order. So if i select cutomer number column ti should give 10 out put and whern select sale order it should give 200 as output.
-Anurag JainHi,
Either you can use the hotspot_click event or double_click to show the Pop-up info of the Sales Order count or customer Count depending on the selection.
In the hotspot_click event method you have E_ROW_ID E_COLUMN_ID..using these you can find the Sales Ordert or customer Number.. Loop the internal table and find the Count.
In the double_click event method you have E_ROW E_COLUMN..using these you can find the Sales Ordert or customer Number.. Loop the internal table and find the Count. -
How to control number of records in batch insert by eclipselink
Hi,
We are using eclipselink(2.2) to persist objects and we use following configuration -
<property name="eclipselink.jdbc.batch-writing" value="Oracle-JDBC" />
<property name="eclipselink.jdbc.batch-writing.size" value="5" />
however the number of records inserted is much more than 5( I have seen 5000 records being inserted ). How can we control the number of records inserted once?
Thanks.Binding can be configured using the "eclipselink.jdbc.bind-parameters" property, and is on by default - it should be on for jdbc batch writing.
Batch writing defaults to 100 statements, so I am not sure why it would include all statements in one batch unless it is not batching at all. If you set the logs to finest or all it should print of the values it is using for each property, and also show the SQL and statments it is executing. Can you turn on logging and post portions of the logs, particularly the part showing the transaction in question (though maybe only 6 lines of consecutive inserts).
Logging is controlled through the "eclipselink.logging.level" properties.
Best Regards,
Chris -
How to find number of records retrieved
hi everyone,
suppose you made tap canvas and 2 tab page one for dept table and one for emp table and you make non database text item in the emp tab page. i need when i press in row on dept page navigate to emp page and display the number of records retrieved in this text item
any help i greatly appreciated
thanksHello,
What happens if you create one text item (non database) with numeric datatype in the emp block and set the property No. of display records to 1.
Then set the Calculation Mode to Summary.
Then Set the Summary Function to Count.
Then Choose the Summarized Block from list as EMP block and choose any column from the Summarized Items list.
The run the form.
-Ammad
Maybe you are looking for
-
Procedure entry point kguuseg could not be located....
..in dynamic link library oraclient10.dll. Error I get when trying to run reports. 10gR2 on win 2003 server, standalone OC4J Anyone have any idea what this means? I've tried adjusting PATH env variable and other suggestions I've found but cannot reso
-
JSP and Sending User-entered information to MySQL Database
I am trying to send user information to my database that I created in MySQL. I made a DB java class, which basically handles my connection to the database, which I know works since I also use it to log into my site. The problem is after I have entere
-
I create a page about a year ago that includes an uploaded video. I now realize I've lost the original file and want to use it elsewhere. Any clues on how I can get access to the file within the wonderful world of iWeb? Thanks
-
Unable to use elements 11 which I purchased in october
I am unable to use element 11 which I purchased in Oct the trail version keeps poping up asking me to purchase what can I do
-
FiX lot size & minimum sale order qty .
hi all We maintained minimum order quantity for material ; can we put massage sale oraganization wise ie for SO IN01 Massage type is 'E" & for IN02 massage type is 'W" If my minimum order qty. is 10 then SAP will accept the sale order qty. with mult