Select count(*) statement in ABAP
Hi,
Im writing following statement in my Function module,
select count(*) into l_count
from user_master
where username = l_username and
process_type = processtype and
password = oldpassword.
And there is one entry in table user_master.
But still, I'm getting l_count as zero..
Can somebody help me with this.
Regards,
Amey
select count(*) into l_count
from user_master
where username = l_username and
process_type = processtype and
password = oldpassword.
Use group by option...
Like this....
select count(*) into l_count
from user_master
where username = l_username and
process_type = processtype and
password = oldpassword group by username.
Similar Messages
-
Getting Long time to execute select count(*) statement.
Hi all,
My table have 40 columns and it doesn't have the primary key column. it contain more than 5M records. it's taking long time to execute simple sql statement.
Such as select (*) take 1min and 30 sec. If i use select count(index_colunm) then it finished with in 3s. i did the following workarounds.
Analyzed the table.
created required indexes.
yet getting the same performance issues. please help me to solve this issue
ThanksBlueDiamond wrote:
COUNT(*) counts the number of rows produced by the query, whereas COUNT(1) counts the number of 1 values.Would you care to show details that prove that?
In fact, if you use count(1) then the optimizer actually re-writes that internally as count(*).
Count(*) and Count(1) are have identical executions.
Re: Count(*)/Count(1)
http://asktom.oracle.com/pls/asktom/f?p=100:11:6346014113972638::::P11_QUESTION_ID:1156159920245 -
What's wrong with my SELECT/COUNT(*) statement?
I am trying to get a total count of records related to a single master record within one table, and if I test this in the DW recordset wizard, I get the results I need. By testing it, I mean if I enter something other than the default -1, where there are results related to another 'master record', then I end up with the correct amount of rows, but when I test it in a browser, all I am getting is '0' for all records.
This bit of code is setting the 'master record ID' to which others will relate to:
<?php $_GET['trcount'] = $row_rs_replycount['fld_fID'] ?>
This is my recordset which is inline with the code which is inside a repeat region:
<?php
$threadreplys_rs_replycount = "3";
if (isset($_GET['trcount'])) {
$threadreplys_rs_replycount = $_GET['trcount'];
mysql_select_db($database_conn_mrs, $conn_mrs);
$query_rs_replycount = sprintf("SELECT *, COUNT(*) AS countTOT FROM tbl_forumPOSTS WHERE fld_fTHREADID = %s ORDER BY fld_fID DESC", GetSQLValueString($threadreplys_rs_replycount, "int"));
$rs_replycount = mysql_query($query_rs_replycount, $conn_mrs) or die(mysql_error());
$row_rs_replycount = mysql_fetch_assoc($rs_replycount);
$totalRows_rs_replycount = mysql_num_rows($rs_replycount);
?>
And this is the code to display the total number of records that are related
<?php echo $row_rs_replycount['countTOT']; ?>
As I say, I have it working when testing different default values in the recordset wizard, but not live on a page.
Thanks.>"SELECT *, COUNT(*) AS countTOT FROM tbl_forumPOSTS WHERE....
That SQL is not valid - at least not by SQL standards. If your query contains an aggregate, then all columns that are not aggregated must be in a group by clause. It's possible that MySQL implicitly adds all non-aggreated columns to a group by, but you should probably fix it anyway. If you don't need to use the other columns from that table in the recordset, then just remove the * from the select list.
"SELECT COUNT(*) AS countTOT FROM tbl_forumPOSTS WHERE....
If you still have a problem, then output the value in $totalRows_rs_replycount to see if you are getting any rows returned from your query.
Next, comment out these lines:
if (isset($_GET['trcount'])) {
$threadreplys_rs_replycount = $_GET['trcount'];
to make sure any value in trcount is not interfering with the default value of '3' and see if that returns any results. -
How to determine package size dynamically for select - endselect statement in ABAP
Hi All,
I was using select- edselect with package size but i have hard coding the package size. Can any one tell me the the process to determine dynamic package size so that i can use in parallel processing.Hi,
If you are looking to determine or set the value of package size dynamically then use below code for reference.
DATA: itab TYPE TABLE OF spfli,
wa like LINE OF itab,
n TYPE i.
n = 10.
SELECT carrid connid
FROM spfli
INTO CORRESPONDING FIELDS OF TABLE itab
PACKAGE SIZE n.
LOOP AT itab INTO wa.
WRITE: / wa-carrid, wa-connid.
ENDLOOP.
ENDSELECT.
If you are concerned about the performance then either use SELECT with OPEN CURSOR and CLOSE CURSOR.
Let me know if it helped?
Regards,
Zuber -
Hi,
I have an odd situation where "select count(*) from my_view where some_clause" returns 0, but the exact same query fetching the data (ie "select * from my_view where some_clause") works fine and fetches, correctly, 4000+ records.
I have tried dropping and recreating the view, and collecting DB stats again, but the problem persists.
I had a look at the explain plans and they are very different, but both the SQL statements work fine on a copy of the database taken with impdp.
Does anyone have any suggestions on what might be going on here ?
Any help would be appreciated, I've run out of ideas !
Dave
Edited by: user10281551 on 18-Sep-2008 00:43
Edited by: user10281551 on 18-Sep-2008 00:44Maybe it's the bug that a function based index is present and gets incorrectly used in the select count(*) statement?
If that's not the case, then please show us more details, like the statement and both execution plans.
Regards,
Rob. -
Select count(*) on sql statement returning zero when a matching row exists.
Our account has an ANSI C application that checks for the existence a row on an Oracle table(s) by using the following SQL:
int iCount = 0;
EXEC SQL
SELECT count(rownum) INTO :iCount
FROM sys.all_tab_columns
WHERE table_name IN
(SELECT table_name FROM
sys.all_synonyms
WHERE upper(synonym_name) = upper(:szDestTable))
AND upper(column_name) = upper(:szColumnName)
AND owner = 'DBAUSER';
The bind variables szDestTable and szColumnName are populated with values parsed from columns on another database table. This application is executed through out the day. Occasionally, the application will report a zero in the iCount when there should be a match. I have verified the szDestTable and szColumnName are populated with the correct values which would find a match and they are correct. To make matters even stranger, the application will parse the same input values and find a match (as it should). At some point during the day, and it can be at any time, the application will NOT find a match on the same file, same values. Every subsequent execution of this application will not find a match on the same values. Once the database is brought down and started up in the evening for its normal backups, the application will find a match again on the same values. This problem does not occur every day. I could be a week or a week and a half between incidents.
I printed the contents of the sqlca.sqqlerrm.sqlerrmc field to a log file. The sqlca.sqlerrm.sqlerrmc field reported an ORA-1405 bind variable was null when the iCount was reporting a zero. When I compiled this application, I set the Proc*C flag to UNSAFE_NULLS=yes since there are other bind variable in the application that can be NULL and that is ok.
The above SQL is compiled into the C application using the Proc*C compiler. It is compiled using the Oracle 11.2.0.2 libraries. The application is executed against an Oracle 11.2.0.2 database. The database and application are executed on an HP/Unix 11.31 platform.
This problem did not start occurring until our account went from Oracle 10.2 to Oracle 11.2. Recently, I have changed the SQL to perform a “SELECT COUNT(rownum)” instead of the “SELECT COUNT(*)”. I compiled the application and executed the new application with the SELECT COUNT(rownum) against the same database where the same application with the SELECT COUNT(*) was failing to find a row that actually existed. The application with the SELECT COUNT(rownum) found the matching row as it should have. The new application has been executing in production for about 10 days now without any problems against ten various Oracle 11.2 databases.
Why would SELECT COUNT(*) and SELECT COUNT(rownum) be any different?This forum is about C programming in general, and about using Studio C in particular.
Your question is about Oracle database programming. You are more likely to find a helpful answer in a forum about database programming. Start here:
https://forums.oracle.com/forums/category.jspa?categoryID=18 -
"select count(*)" and "select single *" returns different result
Good day!
product version SAP ECC 6.0
oracle10
data transfers from external oracle db into customer tables using direct oracle db link
sometimes I get case with different results from 2 statements
*mytable has 10 rows
*1st statement
data: cnt type I value 0.
select count( * ) into cnt from mytable WHERE myfield_0 = 123 and myfield_1 = '123'.
*cnt returns 10 - correct
*2nd statement
select single * from mytable WHERE myfield_0 = 123 and myfield_1 = '123'.
*sy-dbcnt returns 0
*sy-subrc returns 4 - incorrect, 10 rows are "invisible"
but
1. se16 shows correct row number
2. I update just one row from "invisible" rows using se16 and 2nd statement returns correct result after that
can not understand why
thank you in advance.Thank you, Vishal
but,
general problem is that
1. both statements have the same WHERE conditions
2. 1st return resultset with data (sy-dbcnt=10), 2nd return empty dataset, but must return 1 in sy-dbcnt
Yes, different meaning, you are right, but must 2nd must return 1, because of "select single *" construction, not 0.
Dataset to process is the same, WHERE conditions are equal...
I think the problem is that how ABAP interperets select count(*) and "select single *".
Maybe "select count (*)" scans only PK from index page(s)? and "select single *" scans data pages? and something is wrong with that?
I'm new in SAP and didn't find any SAP tool to trace dump of data and indexes pages with Native SQL.
se16 shows all records.
And why after simple manual update of just one record using se16 "select single *" returns 1?
I've just marked one row to update, didn't change any data, then pressed "save". -
Passing Select-options in OO ABAP
Hi,
How to use select-options in oo ABAP?
Regards,
Ravi SHi Ravi,
You have to define a type as below
TYPES:tr_matnr TYPE RANGE OF matnr.
DATA: gv_matnr TYPE mara-matnr.
SELECT-OPTIONS: so_matnr FOR gv_matnr.
CLASS lcl_example DEFINITION
CLASS lcl_example DEFINITION.
PUBLIC SECTION.
METHODS:
get_data
EXPORTING
so_matnr TYPE tr_matnr.
ENDCLASS.
CLASS lcl_example IMPLEMENTATION
CLASS lcl_example IMPLEMENTATION.
METHOD get_data.
SELECT COUNT(*)
FROM mara
WHERE matnr IN so_matnr[].
ENDMETHOD.
ENDCLASS.
If you have to pass it globally create a table type that has the same structure as select-opton ( that is low high sign option ).
PLEASE REWARD THE POINTS
Thanks & Regards,
Sujith -
Select count * is not working
Hi everybody.
I've got a very strange problem, when i'm doing a select count* the result is giving me a value that is not the maximum (but when i check the database table the maximum value is another..)
Could it be that the select command is not executing against the table, rather than the SAP cache??
If this is the case, how can i avoid this?? I mean force the select command to execute against de DB table.
thanks a lot.to get max value of a table u can use
Select max( fld )............
Bypassing the SAP buffer with the above additions is a means to increase the performance when accessing buffered database tables. To explicitly bypass the SAP buffer in the SELECT statement, always use the addition BYPASSING BUFFER instead of the implicit behavior of the additions stated above. -
Using SELECT INTO statement to transfer data from one DB to another?
Hello,
I need to move data from an SAP table to another downstream SQL server box without flat file in between. I have set up the DBCON interface, so that my ABAP code on SAP can connect to the remote SQL Server, then I can run INSERT command as Native SQL inside the ABAP.
However, INSERT has performance problem. The best performer as I can find is SELECT INTO statement. But then I am stuck at how to use SELECT INTO to query my local SAP table and send (via INTO) to remote database. I am not even sure whether I should use Open SQL or Native SQL.
Any suggestion? BTW, I understand the limitation of Native SQL, but we are OK to use it.
Thanks!It appears that this is some kind of migration project due to the scope of the data contained in the single file? If so whatever you do is like ly to be trow away once the migration of data is completed.
You have a couple of options:
1) Get the data extracted from HFM in multiple files instead of one bulk file, broken down by scanario,year & period
2) Take the single data dump file produced by FDM and manipulate it yourself to get the data in a more usuable format for processing through FDM.
Option 2 could be achieved via any ETL tool or a custom file parsing script. What may be more attractive to you and allow you to fully leverage your investment in FDM is that you could use the PULL adapter that ships as part of the FDM adapter suite to perform this transformation exercise. The PULL adapter takes a flat file input and allows you to use all the in built functionality of FDM to transform it and output a modified flat file (or series of flat files). You could use it to produce multioload files or a series of files broken down by scenario,year,period.
Whatever you do I would suggest that break the single data file down into smaller chunks as this will help with the iterative debugging process you will inevitably have to undetake whislt migrating the data to the new application. -
Select count(*) from table in oracle 11g with direct path read takes time
select count(*) from table takes long time, even more than couple of hours..
direct path read is the wait event which is almost is at 99%..
can u someone provide some info on this.. on solution.. thankxknowledgespring wrote:
table has millions of records... 130 millions..
select count(*) from BIG_SIZE_TABLE; --- executed in sql plus command prompt.
Rows Execution Plan
0 SELECT STATEMENT MODE: ALL_ROWS
0 SORT (AGGREGATE)
0 TABLE ACCESS MODE: ANALYZED (FULL) OF 'BIG_SIZE_TABLE' (TABLE)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 1 0.00 0.00
enq: KO - fast object checkpoint 1 0.01 0.01
Disk file operations I/O 18 0.00 0.00
direct path read 58921 0.34 418.54direct path read time waited is : 58921 total time waited: 418.54
That 418 seconds - not the hours you reported earlier. Is it possible that your connection to the database broke ?
On a typical system, by the way, you can usually turn one direct read for tablescan into 1MB, so your scan seems to have covered about 59 GB, which seems to be in the right sort of ballpark for 130M rows.
we have another query and when we test the query execution using v$sql, is_bind_sensitive =N, how to make is_bind_sensitive=Y all the time.. There is a hint /*+ bind_aware */ - I'd have to check whether or not it's documented at present. It might help.
I would be interested in hearing why you think the hint should be bind sensitive when the optimizer doesn't.
Regards
Jonathan Lewis -
Sub-Select Count query breaking TOAD
Oracle 10.2.0.4.0
Running TOAD 9.1
I am running some SQL on our eBusiness Suite:
SELECT pha.segment1
, pha.type_lookup_code
, (SELECT COUNT(DISTINCT pha2.po_header_id)
FROM po.po_headers_all pha2
, po.po_lines_all pla
WHERE pha2.po_header_id = pla.po_header_id
AND pla.contract_id = pha.po_header_id) po_count
, (SELECT MAX(pha2.creation_date)
FROM po.po_headers_all pha2
, po.po_lines_all pla
WHERE pha2.po_header_id = pla.po_header_id
AND pla.contract_id = pha.po_header_id) latest_cpa_po
FROM po.po_headers_all pha
, po.po_vendors pv
, po.po_vendor_sites_all pvsa
WHERE pha.vendor_id = pv.vendor_id
AND pha.vendor_site_id = pvsa.vendor_site_id
-- AND pv.VENDOR_NAME LIKE 'H%'
AND pha.vendor_id = 98
AND pha.type_lookup_code = 'CONTRACT'
AND pha.org_id IN(7041, 7042);The above query runs quicky (approx. 1 second). If I take out the AND pha.vendor_id = 98 then the query takes a few minutes to run.
When I try to export it, or scroll down to view > 500 rows, TOAD crashes.
I know this isn't a TOAD forum, but I think that this is probably an issue with my no doubt rubbish SQL.
If I take out this sub-select, then the problem doesn't happen:
, (SELECT COUNT(DISTINCT pha2.po_header_id)
FROM po.po_headers_all pha2
, po.po_lines_all pla
WHERE pha2.po_header_id = pla.po_header_id
AND pla.contract_id = pha.po_header_id) po_countHowever, I can't work out a better way of getting the data I need.
The sub-select counts POs which have been raised where the contractID on the PO line is the same as the PO Header ID from the main query.
Any advice please, on what I could do to sort this out would be much appreciated.
Thanks!Hi,
It looks like you can replace both scalar sub-queries with a join, like this:
WITH header_lines_summary AS
SELECT pla.contract_id
, COUNT (DISTINCT pha2.po_header_id) AS po_count
, MAX (pha2.creation_date) AS latest_cpa_po
FROM po.po_headers_all pha2
, po.po_lines_all pla
WHERE pha2.po_header_id = pla.po_header_id
GROUP BY pla.contract_id
) -- Everything up to this line is new
SELECT pha.segment1
, pha.type_lookup_code
, hls.po_count -- Changed
, hls.latest_cpa_po -- Changed
FROM po.po_headers_all pha
, po.po_vendors pv
, po.po_vendor_sites_all pvsa
, header_lines_summary hls -- New
WHERE pha.vendor_id = pv.vendor_id
AND pha.vendor_site_id = pvsa.vendor_site_id
AND pha.po_header_id = hls.contract_id (+) -- New
-- AND pv.VENDOR_NAME LIKE 'H%'
AND pha.vendor_id = 98
AND pha.type_lookup_code = 'CONTRACT'
AND pha.org_id IN (7041, 7042);Aside from the sub-query (which is entirely new), the query above is just what you posted, with 2 lines changed and 2 lines added, as marked.
This should be more efficient, but I don't know for certain that it will solve the Toad problem.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
It never hurts to say what version of Oracle you're using. -
Where clause in SELECT INTO statement
Hi,
I am using multiple conditions in where clause for my SELECT INTO statement as follows.
SELECT count(DTLA.LOCATION_ID)
INTO LOCATION_ID_count
FROM DOC2_MGR.DOC_TYPE_LOB_ASSOC DTLA
WHERE (DTLA.DOC_TYPE_ID = 'XYZ' AND DTLA.lob_code = 'ABC');
It considers only first condition and returns the result i.e. DTLA.DOC_TYPE_ID = 'XYZ' only.
Does select into statement suppose to consider only one condition in where clause???
Thanks in advance!
--SandeepI got it resolved. Here is list of things I noted
1. I was using variable names same as column names. It was mixing up temp variable names with column name on the table, which doesn't make sense as I was referring column names in table.column format
2. I had mixed few datatypes. Input param was suppose to be number where as I was passing it as Text
Thanks anyway!
--Sandeep -
Alternative for select count('x') or count(*)
Hi Gurus,
I need to use select count(*) multiple times in a SP before and after deletion of rows from multiple tables. As this is an expensive method, do we have some alternative for Count(*), like selecting something from a system table or view instead?Hi
You can know the number of rows affected by the DELETE statement in PL/SQL (if you are using PL/SQL) using sql%rowcount. So you don't really need to count the rows again after the delete took place...
If you are deleting the same rows as selected by the second count condition (older than a particular date), in fact you only need to count rows once for each table.
Luis -
Hi
Need help with getting a count of different sums:
Table: Stay
Columns: Name, Nights
each name can have multiple rows with different number of nights, now I have a select looking like this:
select sum(nights),name from stay
group by name
The result could look something like this:
1 smith
2 miller
1 grant
1 simpson
2 sharp
How do I do to get a count on the sum(night)? Is it possible in the same query?If you want to count how many distinct records appear in your current select statement (i.e. 5 in this case), you can do
SELECT count(*) num_distinct_guests,
total_nights,
name
FROM (
SELECT sum(nights) total_nights,
name
FROM stay
GROUP BY name
)If you want the total number of stays, in addition to the total time stayed, use something like
SELECT sum(nights),
name,
count(nights)
FROM stay
GROUP BY name;Justin
Maybe you are looking for
-
Vendor Help is not Displaying in the Front end Screen
Hi, Iam Working in SRM 5.0, Extended Classic Scenario. I have Replicated all the Vendors & Materials from ECC to SRM. While Iam trying to create SC, if i select the Preferred Vendor Search Help iam getting the vendor Pop Up Screen in that i have all
-
I'm trying to install sharepoint tools to users machines. This requires admin privledges. The script below is in a .bat files and installs the product no problems with admin rights. To be able to apply this to users when they log on is where I'm stuc
-
as i said, i checked onto itunes on my pc and noticed all the songs i had in my library had been erased, except for the songs i had purchased on itunes...how do i retrieve my songs...??
-
How can I turn off auto-correct in my iPad?
Is there a way to turn off auto-correct in my iPad? It makes unwanted changes, and distracts me from my writing. I was able to turn off auto-correct in Safari on my Macs, and that has made things much better.
-
SAP note 105621 -- Hiding Cost Conditions in Sales Document
dear experts: i am facing a issue regarding SAP Note 105621. in this note it says we need to implement user exit USEREXIT_FIELD_MODIFICATION USEREXIT_FIELD_MODIFIC_LEER USEREXIT_FIELD_MODIFIC_KZWI USEREXIT_FIELD_MODIFIC_KOP