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
Similar Messages
-
Alternative For Select Queries
H All,
Is there a way to extract sales doc. number of corresponding billing doc. number with out using select query in a report?Ravi,
Is there a way to extract sales doc. number of corresponding billing doc. number with out using select query in a report?
I want to take shower without getting Wet?
Try with BAPI_SALESORDER_GETDETAILBOS,and see the details from BAPISDFLOW structure.
Amit. -
ALTERNATIVE FOR 'SELECT TOP STATEMENT
HI FRIENDS
IF ANY ONE KNOWS HOW TO CONVERT THE SQL STATEMENT GIVEN BELOW PLEASE HELP ME
SELECT TOP 1 CardID FROM EasyRechargeMaster WHERE CardGroup = EasyRecharge.CardGroup
THANKS & REGARDSCheck this query. It should give you desired results....Are you sure about that? Does TOP 1 mean "whatever happens to be the first row fetched"?
-
Alternative for selecting ISF file in FM12 Webhelp publishing
Hi
I am currently evaluating TCS5/ FM12 as an upgrade from TCS4/ FM11.
In TCS 4, I could create an ISF file that contains my FM-RH style mapping and use that file in FM to publish the WebHelp. Now in FM12, I don't see the option to assign the ISF file. Instead, I need to start all over, first pull up the CSS file that contains the custom styles I added in RH, and then create a STS file which stores my style mapping.
Is there any other way out? I have about 70+ styles, mapping and testing them again would be a crazy task!
Thanks in advance.
SreekanthSreekanth,
Perhaps you can create a custom HTML template [AFAIK, that's essentially what the RH master page is - I don't know if you can export this from RH, as I don' use it much] and use the option to import an HTML template:
Addendum: see Adobe FrameMaker 12 * Using HTML page templates -
Select count(*) returns double?
I have executed a 'select count(*) from ...' statement through ODBC against Oracle9i and I am very supprised that the returned ODBC type is a 'double' and not an 'int' (or a 'numeric').
Is this really correct?Did you ever get a response or figure this out?
My problem is fairly simliar, but specific to an 11.1.0.7 and onward release of the Oracle Client.
Current C++ Application using ODBC API calling Oracle Client 10g (all versions), 11gR1 (v11.1.0.6) returns a LONG (4-byte integer) for "SELECT COUNT(*) from tablename"
Change Oracle client to 11gR1 (v11.1.0.7) or higher (11.2.x.y etc) and that same statement returns a DOUBLE (8-byte floating value equivalent to oracle NUMBER data type).
Since the backend DB is the same version, there must be a client side setting (I presume) that has changed the default behaviour of this Aggregate SQL function to return a double rather than a long. I'm hoping to find such a setting that I can either set programmatically through an ODBC API call, or in the Oracle Client configuration itself.
I even tried using SQL CAST to make it an INT SELECT CAST(COUNT(*) AS INT) FROM tablename but that still returns a DOUBLE (8-byte floating NUMBER).
Note: given that I use ODBC, I've written alot of generic C++ code supporting the return value as LONG, as that is how it's been for 10 years via ODBC. I'd like to maintain that if possible without having to write ORACLE specific code within my applications. -
Select count(*) for each row of a table
Hello All,
Following query gives a statistics for each user (how many items he owns, home many tickets authored, how many objects he is subscribed to etc...)
select auser.userid,
(select count(*) from item where owner like '%' || auser.id || '%') ITEM_OWNER_CNT,
(select count(*) from tkt where originator = auser.id) TKT_ORIGINATE_CNT,
(select count(*) from tkt where assigned_to = auser.id) TKT_QA_CNT,
(select count(*) from tkt where create_user = auser.id) TKT_AUTHOR_CNT,
(select count(*) from subscriptions where subscriber_id = auser.id) SUBSCRIPTION_CNT
from
user auser
I was not happy with the performance of this query, so I tried the same using group by. The performance was even worse.
Is there any other option for me to try? Please advice.
Thanks,
SathishHi, Sathish,
As SBH said, a lot depends on your data. Please post some sample data (CREATE TABLE adn INSERT statemetns) for all tables, and the results you want from that data. Describe and give examples of any relationships that are not one-to-one..
You probably want to do joings, like SBH suggested, rather than scalar sub-queries.
The connection between the auser and item tables
(select count(*) from item where owner like '%' || auser.id || '%') ITEM_OWNER_CNT,is very suspicious. Perhaps the item table is poorly designed, and the query would be faster if that table were changed. Is changing the design of the item table an option?
You should be able to get all the information from the tkt table in one pass. It looks like you need to unpivot the data, so instead of one row per ticket (with 3 different people connected to it), there are 3 rows per ticket, each with only 1 person referenced. This is not necessarily a bad table design. Unpivoting, even more than most other things, depends on your database version, so you'll have to tell what version of Oracle you're using. -
Count (*) for select stmt take more time than execute a that sql stmt
HI
count (*) for select stmt take more time than execute a that sql stmt
executing particular select stmt take 2.47 mins but select stmt is using the /*+parallel*/ (sql optimer) in that sql command for faster execute .
but if i tried to find out total number of rows in that query it takes more time ..
almost 2.30 hrs still running to find count(col)
please help me to get count of row faster.
thanks in advance...797525 wrote:
HI
count (*) for select stmt take more time than execute a that sql stmt
executing particular select stmt take 2.47 mins but select stmt is using the /*+parallel*/ (sql optimer) in that sql command for faster execute .
but if i tried to find out total number of rows in that query it takes more time ..
almost 2.30 hrs still running to find count(col)
please help me to get count of row faster.
thanks in advance...That may be because your client is displaying only the first few records when you are running the "SELECT *". But when you run "COUNT(*)", the whole records has to be counted.
As already mentined please read teh FAQ to post tuning questions. -
Better and faster alternative for count(*)
I want to check whether empno=1234 exists in emp table
Currently I am using in proc
select count(*) into cnt from emp
where empno=1234
if cnt>1 then exists otherwise no exists.
Is there any better way to do the same.?user11253970 wrote:
I want to check whether empno=1234 exists in emp table
Is there any better way to do the same.?http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1525380674899
select count(*)
from dual
where exists ( select NULL
from emp
where sal = 5000 );Faster still is to not count at all
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1525380674899#34907832120350
Just process the data and take appropriate action if nothing was processed. -
Create dynamic report or query for piece count
Hi abaper's
This is a very straight forward requirement. so please give me code
First you have to get the corresponding plant from table T320 for the given warehouse numbers in the selection screen.
1. Get the sum of order qty of sales orders from the sales order tables for the given warehouse(Plant), distribution channel and the give date range.
2. Get the confirmed transfer orders qty from the TO master table where TO confirmation date is in the given date range and WH number.
3. Get the total PGIed qty from the delivery master table where PGI'ed date in the given date range, shipping point is in the corresponding plant of the WH and for the given distribution channel.
As you are going to use the major tables please try to write the select commands effectively to avoid further performance issues.How to improve the performance fo this code.....this very urgent.
& Issue Number : 22199 &
& Programmer : Anjaneyulu.Pabba &
& Transport Number : D01K962471 &
& Date of Creation : 19/03/2008 &
& Description : Dynamic report or query for piece count &
& Requested By : Parvati.Polisetty &
REPORT ZR_SD_PIECE_COUNT_ALV no standard page heading
line-size 255
line-count 65.
TABLES DECLARATION
*TABLES: T320, "Assignment IM Storage Location to WM Warehouse Number
VBAK, "Sales Document: Header Data
VBAP, "Sales Document: Item Data
TVKOV, "Org. Unit: Distribution Channels per Sales Organization
LTAK, "WM transfer order header
LTAP, "Transfer order item
LIKP, "SD Document: Delivery Header Data
LIPS. "SD document: Delivery: Item data
TYPE-POOLS DECLARATION
TYPE-POOLS: SLIS .
Internal Table Declaration
DATA : BEGIN OF TY_T320,
WERKS TYPE WERKS_D,
LGNUM TYPE LGNUM,
END OF TY_T320.
DATA : BEGIN OF TY_VBAK,
VBELN TYPE VBELN_VA,
VTWEG TYPE VTWEG,
WERKS TYPE WERKS_D,
KWMENG TYPE KWMENG,
VSTEL TYPE VSTEL,
END OF TY_VBAK.
DATA : BEGIN OF TY_LTAK,
LGNUM TYPE LGNUM,
TANUM TYPE TANUM,
VISTA TYPE LTAP_VISTA,
END OF TY_LTAK.
DATA : BEGIN OF TY_LIKP,
VBELN TYPE VBELN_VL,
WERKS TYPE WERKS_D,
LFIMG TYPE LFIMG,
END OF TY_LIKP.
DATA : BEGIN OF TY_ITAB ,
LGNUM TYPE LGNUM, "Warehouse Number / Warehouse Complex
WERKS TYPE WERKS_D, "Plant
VBELN TYPE VBELN_VA, "Sales Document
VTWEG TYPE VTWEG, "Distribution Channel
KWMENG TYPE KWMENG, "Cumulative order quantity in sales units
TANUM TYPE TANUM , "Transfer Order Number
VISTA TYPE LTAP_VISTA, "Source actual quantity in alternative
unit of measure
LFIMG TYPE LFIMG, "Actual quantity delivered (in sales units)
END OF TY_ITAB .
DATA: T_T320 LIKE STANDARD TABLE OF TY_T320 INITIAL SIZE 0 WITH HEADER
LINE,
T_VBAK LIKE STANDARD TABLE OF TY_VBAK INITIAL SIZE 0 .
DATA: T_LTAK LIKE STANDARD TABLE OF TY_LTAK INITIAL SIZE 0 WITH HEADER
LINE.
DATA :T_LIKP LIKE STANDARD TABLE OF TY_LIKP INITIAL SIZE 0 WITH HEADER
LINE.
DATA:T_ITAB LIKE STANDARD TABLE OF TY_ITAB INITIAL SIZE 0 WITH HEADER
LINE .
*& Fieldcatalog Declaration
DATA : T_FCAT TYPE SLIS_T_FIELDCAT_ALV,
W_FCAT TYPE SLIS_FIELDCAT_ALV.
DATA : W_LAYOUT TYPE SLIS_LAYOUT_ALV.
********Global Data Declaration***
DATA :G_REPID LIKE SY-REPID,
G_EXIT(1) TYPE C,
GX_VARIANT LIKE DISVARIANT,
X_SAVE, "for Parameter I_SAVE
GS_VARIANT TYPE DISVARIANT. "for parameter IS_VARIANT
data: g_lgnum type t320-lgnum,
g_vtweg type vbak-vtweg,
g_erdat type vbak-erdat.
*& Selection-Screen
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS : S_LGNUM FOR g_lgnum, "Warehouse Number
S_VTWEG FOR g_vtweg, "Distribution Channel
S_ERDAT FOR g_erdat ."Date on which the record was
**********"created
SELECTION-SCREEN END OF BLOCK B1 .
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
PARAMETER: P_VARI LIKE DISVARIANT-VARIANT. "Layout
SELECTION-SCREEN END OF BLOCK B2.
*& INITIALIZATION EVENT
INITIALIZATION.
CLEAR GS_VARIANT.
'gs_variant' must at least contain the report-id to allow
saving a variant.
G_REPID = SY-REPID.
§ 2.At least field REPORT of this structure has to be filled!
GS_VARIANT-REPORT = G_REPID.
§ 3.Determine saving options.
X_SAVE = 'A'. "The user may save all types of variants
*******Validating selection-screen values**********************
getting F4 value for display variant field
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_VARI.
PERFORM F4_FOR_VARIANT.
****validation of F4 value of display variant
AT SELECTION-SCREEN.
PERFORM PAI_OF_SELECTION_SCREEN.
*& Start-Of-Selection
START-OF-SELECTION.
*****Subroutine to select Plant from T320
PERFORM FIND_PLANT .
*****Subroutine to select Order Quantity from VBAP
PERFORM ORDER_QUANTITY .
*****Subroutine to select Transfer Order Quantity from LTAK and LTAP
PERFORM TRANSFER_ORDER_QUANTITY.
*****Subroutine to select TDelivery Quantity from LIKP and LIPS
PERFORM DELIVERY_QUANTITY.
*& End-Of-Selection
END-OF-SELECTION.
*****Subroutine for Fieldcatalog
PERFORM FIELDCATALOG .
*****Subroutine for Final Output
PERFORM DISPLAY_OUTPUT .
*& Subroutine Implementaion
*& Form FIND_PLANT
text
--> p1 text
<-- p2 text
FORM FIND_PLANT .
SELECT WERKS
LGNUM
FROM T320
INTO TABLE T_T320
WHERE LGNUM IN S_LGNUM.
ENDFORM. " FIND_PLANT
*& Form order_quantity
text
--> p1 text
<-- p2 text
FORM ORDER_QUANTITY .
SELECT VK~VBELN
VK~VTWEG
VP~WERKS
VP~KWMENG
VP~VSTEL
INTO TABLE T_VBAK FROM VBAK AS VK
INNER JOIN VBAP AS VP
ON VKVBELN = VPVBELN
FOR ALL ENTRIES IN T_T320
WHERE VK~VTWEG IN S_VTWEG
AND VK~ERDAT IN S_ERDAT
AND VP~WERKS = T_T320-WERKS.
ENDFORM. " order_quantity
*& Form Transfer_order_quantity
text
--> p1 text
<-- p2 text
FORM TRANSFER_ORDER_QUANTITY .
SELECT LK~LGNUM
LK~TANUM
LP~VISTA
INTO TABLE T_LTAK FROM LTAK AS LK
INNER JOIN LTAP AS LP
ON LKLGNUM = LPLGNUM
WHERE LK~KQUIT = 'X'
AND LK~BDATU IN S_ERDAT
AND LK~LGNUM IN S_LGNUM.
ENDFORM. " Transfer_order_quantity
*& Form Delivery_QUANTITY
text
--> p1 text
<-- p2 text
FORM DELIVERY_QUANTITY .
SELECT VBELN WERKS LFIMG FROM LIPS
INTO TABLE T_LIKP
FOR ALL ENTRIES IN T_T320
WHERE WERKS = T_T320-WERKS
AND ERDAT IN S_ERDAT
AND VTWEG IN S_VTWEG.
ENDFORM. " Delivery_QUANTITY
*& Form fieldcatalog
text
--> p1 text
<-- p2 text
FORM FIELDCATALOG .
W_FCAT-COL_POS = '1' .
W_FCAT-FIELDNAME = 'LGNUM' .
W_FCAT-REF_TABNAME = 'T320'.
W_FCAT-REF_FIELDNAME = 'LGNUM' .
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-COL_POS = '2' .
W_FCAT-FIELDNAME = 'VTWEG' .
W_FCAT-REF_TABNAME = 'VBAK'.
W_FCAT-REF_FIELDNAME = 'VTWEG' .
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-COL_POS = '3' .
W_FCAT-FIELDNAME = 'KWMENG' .
W_FCAT-REF_TABNAME = 'VBAP'.
W_FCAT-REF_FIELDNAME = 'KWMENG' .
*w_fcat-seltext_m = '# of Orders'.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-COL_POS = '4' .
W_FCAT-FIELDNAME = 'VISTA' .
W_FCAT-REF_TABNAME = 'LTAP'.
W_FCAT-REF_FIELDNAME = 'VISTA' .
*w_fcat-seltext_m = '# of Pcs Picked'.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-COL_POS = '5' .
W_FCAT-FIELDNAME = 'LFIMG' .
W_FCAT-REF_TABNAME = 'LIPS'.
W_FCAT-REF_FIELDNAME = 'LFIMG' .
*w_fcat-seltext_m = '# of Pcs Shipped'.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-COL_POS = '6' .
W_FCAT-FIELDNAME = 'TANUM' .
W_FCAT-REF_TABNAME = 'LTAK'.
W_FCAT-REF_FIELDNAME = 'TANUM' .
**w_fcat-seltext_m = '# of Pcs Shipped'.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-COL_POS = '7' .
W_FCAT-FIELDNAME = 'WERKS' .
W_FCAT-REF_TABNAME = 'T320'.
W_FCAT-REF_FIELDNAME = 'WERKS' .
**w_fcat-seltext_m = '# of Pcs Shipped'.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
ENDFORM. " fieldcatalog
*& Form display_output
text
--> p1 text
<-- p2 text
FORM DISPLAY_OUTPUT .
LOOP AT T_T320 INTO TY_T320.
TY_ITAB-WERKS = TY_T320-WERKS.
TY_ITAB-LGNUM = TY_T320-LGNUM.
READ TABLE T_VBAK INTO TY_VBAK WITH KEY WERKS = TY_T320-WERKS.
IF SY-SUBRC = 0.
TY_ITAB-VBELN = TY_VBAK-VBELN.
TY_ITAB-VTWEG = TY_VBAK-VTWEG.
TY_ITAB-KWMENG = TY_VBAK-KWMENG + ty_itab-kwmeng.
ENDIF.
READ TABLE T_LTAK INTO TY_LTAK WITH KEY LGNUM = TY_T320-LGNUM.
IF SY-SUBRC = 0.
TY_ITAB-TANUM = TY_LTAK-TANUM.
TY_ITAB-VISTA = TY_LTAK-VISTA + ty_itab-vista.
ENDIF.
READ TABLE T_LIKP INTO TY_LIKP WITH KEY WERKS = TY_T320-WERKS.
IF SY-SUBRC = 0.
TY_ITAB-LFIMG = TY_LIKP-LFIMG + ty_itab-lfimg.
ENDIF.
APPEND TY_ITAB TO T_ITAB.
ENDLOOP.
Function Module for Displaying Final Output ********
W_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-CPROG
IS_LAYOUT = W_LAYOUT
IT_FIELDCAT = T_FCAT[]
TABLES
T_OUTTAB = T_ITAB.
ENDFORM. " display_output
*& Form f4_for_variant
text
--> p1 text
<-- p2 text
FORM F4_FOR_VARIANT .
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
IS_VARIANT = GS_VARIANT
I_SAVE = X_SAVE
IMPORTING
E_EXIT = G_EXIT
ES_VARIANT = GX_VARIANT
EXCEPTIONS
NOT_FOUND = 2.
IF SY-SUBRC = 2.
MESSAGE ID SY-MSGID TYPE 'S' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
IF G_EXIT = SPACE.
P_VARI = GX_VARIANT-VARIANT.
ENDIF.
ENDIF.
ENDFORM. " f4_for_variant
*& Form pai_of_selection_screen
text
--> p1 text
<-- p2 text
FORM PAI_OF_SELECTION_SCREEN .
IF NOT P_VARI IS INITIAL.
MOVE GS_VARIANT TO GX_VARIANT.
MOVE P_VARI TO GX_VARIANT-VARIANT.
CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
EXPORTING
I_SAVE = X_SAVE
CHANGING
CS_VARIANT = GX_VARIANT.
GS_VARIANT = GX_VARIANT.
ELSE.
PERFORM VARIANT_INIT.
ENDIF.
ENDFORM. " pai_of_selection_screen
*& Form variant_init
text
--> p1 text
<-- p2 text
FORM VARIANT_INIT .
CLEAR GS_VARIANT.
GS_VARIANT-REPORT = G_REPID.
ENDFORM. " variant_init -
Performance issue when using select count on large tables
Hello Experts,
I have a requirement where i need to get count of data from a database table.Later on i need to display the count in ALV format.
As per my requirement, I have to use this select count inside a nested loops.
Below is the count snippet:
LOOP at systems assigning <fs_sc_systems>.
LOOP at date assigning <fs_sc_date>.
SELECT COUNT( DISTINCT crmd_orderadm_i~header )
FROM crmd_orderadm_i
INNER JOIN bbp_pdigp
ON crmd_orderadm_iclient EQ bbp_pdigpclient "MANDT is referred as client
AND crmd_orderadm_iguid EQ bbp_pdigpguid
INTO w_sc_count
WHERE crmd_orderadm_i~created_at BETWEEN <fs_sc_date>-start_timestamp
AND <fs_sc_date>-end_timestamp
AND bbp_pdigp~zz_scsys EQ <fs_sc_systems>-sys_name.
endloop.
endloop.
In the above code snippet,
<fs_sc_systems>-sys_name is having the system name,
<fs_sc_date>-start_timestamp is having the start date of month
and <fs_sc_date>-end_timestamp is the end date of month.
Also the data in tables crmd_orderadm_i and bbp_pdigp is very large and it increases every day.
Now,the above select query is taking a lot of time to give the count due to which i am facing performance issues.
Can any one pls help me out to optimize this code.
Thanks,
SumanHi Choudhary Suman ,
Try this:
SELECT crmd_orderadm_i~header
INTO it_header " interna table
FROM crmd_orderadm_i
INNER JOIN bbp_pdigp
ON crmd_orderadm_iclient EQ bbp_pdigpclient
AND crmd_orderadm_iguid EQ bbp_pdigpguid
FOR ALL ENTRIES IN date
WHERE crmd_orderadm_i~created_at BETWEEN date-start_timestamp
AND date-end_timestamp
AND bbp_pdigp~zz_scsys EQ date-sys_name.
SORT it_header BY header.
DELETE ADJACENT DUPLICATES FROM it_header
COMPARING header.
describe table it_header lines v_lines.
Hope this information is help to you.
Regards,
José -
Select count from large fact tables with bitmap indexes on them
Hi..
I have several large fact tables with bitmap indexes on them, and when I do a select count from these tables, I get a different result than when I do a select count, column one from the table, group by column one. I don't have any null values in these columns. Is there a patch or a one-off that can rectify this.
ThxYou may have corruption in the index if the queries ...
Select /*+ full(t) */ count(*) from my_table t
... and ...
Select /*+ index_combine(t my_index) */ count(*) from my_table t;
... give different results.
Look at metalink for patches, and in the meantime drop-and-recreate the indexes or make them unusable then rebuild them. -
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 -
SELECT COUNT( ) gives warning in ECC6.0.
Hi,
The following query is giving syntax error in ECC6.0, where as it worked absolutely fine in 3.1i server.
SELECT COUNT( OBOX_CNTNO ) FROM ZT2OB
INTO W_COUNT
WHERE SUPPL_CD = W_SUPPL_CD
AND INVC_NO = W_INVC_NO
AND INVC_LN_NO = T_SCR_ITEMS-INVC_LN_NO.
Error: "COUNT( OBOX_CNTNO )" is only valid in the extended form "COUNT( DIS
OBOX_CNTNO )" . . .
The query seems obsolete in ECC6.0. Can anybody help me to give valid query for this in ECC6.0?Hi,
<b>Count</b> functionality is to be used along with <b>Distinct</b> functionality.
COUNT( DISTINCT col )
<b>Reward points if this helps,</b>
Kiran -
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. -
Select * shows 1 record - select count(*) shows 2232 records
Using SQL 2008 R2 and SS Import Wizard
Imported Excel file into SQL Table. No errors reported during import.
Command: Select * From XLImport
returns 1 record
Command: Select Count(*) From XLImport
returns 2232
What could be causing this ??
Many thanks
MisterT99I see what happened.
A previous command issued 'Set ROWCOUNT 1'
When I entered 'Set ROWCOUNT 0' That fixed the problem.
Thanks everyone for your comments.
MisterT99
Cool
That now makes sense
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
Maybe you are looking for
-
Still can't receive messages from Iphone Users
Greetings, I know there are many topics asking similar questions if it's googled, and I think I have read through almost all of them to no prevail. I know veterans of these boards probably get tired of seeing the same topics, but im desperate and wil
-
Deployment package error when transferring a playlist through WAN
Hi , I'm using DMM 5.2.1 and DMP 4305G .I'm using the deployment package to transfer the files to DMPs through the WAN.at once i'm sending to 10 DMPs. But everytime im getting errors for at least 2 DMPs .I'm attaching the error report generated from
-
Deploying MBean with ear/jar/war files
Hi! I'm working on a project where we plan to use jmx to manage our web(servlet) application. I have created a simple test MBean, and try to create the MBean with MBeanServer. When i try this, i got a ReflectionException(ClassNotFoundException). I ha
-
Mac locked up completely. Mouse, screen.
Hello, this is my very first Mac and I tried searching the community for an answer but I can't seem to come up with anything. I bought the MacBook Pro 15" i7 retina display YESTERDAY. Trying to find my way around this morning and it locked up. The
-
Can you make the installer for Vista 64bit as well?
It shouldn't be too hard to make the installer available for Windows Vista 64 bit as well, should it? Or is there a special reason Scout is Windows 7 and >? I think there's still a lot of people working on an old Vista machine (like me) who don't re