Normal SQL Query othern than Native
Can we use normal SQL query in ABAP?
if yes what are the various statements we have..
Hi,
Refer the select statement ..
*Code to demonstrate select command
*Code to demonstrate select into internal table command
TYPES: BEGIN OF t_bkpf,
include structure bkpf.
bukrs LIKE bkpf-bukrs,
belnr LIKE bkpf-belnr,
gjahr LIKE bkpf-gjahr,
bldat LIKE bkpf-bldat,
monat LIKE bkpf-monat,
budat LIKE bkpf-budat,
xblnr LIKE bkpf-xblnr,
awtyp LIKE bkpf-awtyp,
awkey LIKE bkpf-awkey,
END OF t_bkpf.
DATA: it_bkpf TYPE STANDARD TABLE OF t_bkpf INITIAL SIZE 0,
wa_bkpf TYPE t_bkpf.
TYPES: BEGIN OF t_bseg,
*include structure bseg.
bukrs LIKE bseg-bukrs,
belnr LIKE bseg-belnr,
gjahr LIKE bseg-gjahr,
buzei LIKE bseg-buzei,
mwskz LIKE bseg-mwskz, "Tax code
umsks LIKE bseg-umsks, "Special G/L transaction type
prctr LIKE bseg-prctr, "Profit Centre
hkont LIKE bseg-hkont, "G/L account
xauto LIKE bseg-xauto,
koart LIKE bseg-koart,
dmbtr LIKE bseg-dmbtr,
mwart LIKE bseg-mwart,
hwbas LIKE bseg-hwbas,
aufnr LIKE bseg-aufnr,
projk LIKE bseg-projk,
shkzg LIKE bseg-shkzg,
kokrs LIKE bseg-kokrs,
END OF t_bseg.
DATA: it_bseg TYPE STANDARD TABLE OF t_bseg INITIAL SIZE 0,
wa_bseg TYPE t_bseg.
*Select directly into an internal table
SELECT bukrs belnr gjahr buzei mwskz umsks prctr hkont xauto koart
dmbtr mwart hwbas aufnr projk shkzg kokrs
FROM bseg
INTO TABLE it_bseg.
Select directly into an internal table where fields are in a
different order or not all fields are specified
SELECT bukrs belnr gjahr buzei mwskz umsks prctr hkont xauto koart
dmbtr mwart hwbas aufnr projk shkzg kokrs
FROM bseg
INTO CORRESPONDING FIELDS OF TABLE it_bseg.
*Select... endselect command
SELECT bukrs belnr gjahr buzei mwskz umsks prctr hkont xauto koart
dmbtr mwart hwbas aufnr projk shkzg kokrs
FROM bseg
INTO wa_bseg.
APPEND wa_bseg TO it_bseg.
ENDSELECT.
*Select FOR ALL ENTRIES command
SELECT bukrs belnr gjahr bldat monat budat xblnr awtyp awkey
UP TO 100 ROWS
FROM bkpf
INTO TABLE it_bkpf.
IF sy-subrc EQ 0.
The FOR ALL ENTRIES comand only retrieves data which matches
entries within a particular internal table.
SELECT bukrs belnr gjahr buzei mwskz umsks prctr hkont xauto koart
dmbtr mwart hwbas aufnr projk shkzg kokrs
FROM bseg
INTO TABLE it_bseg
FOR ALL ENTRIES IN it_bkpf
WHERE bukrs EQ it_bkpf-bukrs AND
belnr EQ it_bkpf-belnr AND
gjahr EQ it_bkpf-gjahr.
ENDIF.
Regards,
Saran
Similar Messages
-
Hi all,
my open SQL query is like
select matnr matkl from mara into corresponding fields of table i_mara for all entries in i_marc
where matnr = marc-matnr.
can u plz tell me the native sql for the same query?
Thanks.
pabihi,
EXEC SQL PERFORMING form.
Native SQL Anweisung
ENDEXEC.
EXEC SQL
select matnr matkl from mara into corresponding fields of table i_mara for all entries in i_marc
where matnr = marc-matnr.
ENDEXEC.
For further ref pls refer to link...
Re: Normal SQL Query othern than Native
Native SQL -
Exu00E9cute an SQL Query statement.
Hi,
Can someone tel me if exist a transaction code who can help me to execute an SQL query (far than my report), either UPDATE or SELECT statement ?
Thanks in advance.
MustaphaHi Shiva,
I want to execute a SQL query like : Select vbeln from vbpa where vbeln = '00000545645'. and show to me a list (the result) in the same page.
P.S : I want to test a join query without going through the debugging.
thank you.
Best regards
Mustapha -
SQL query execution in DB02 hangs if record set is more than 50000
Hi,
We are facing issue in a report performance. The return is using native SQL query.
There are custom views created ar database level for pricing/maetrial and stock. The native sql query is written on these views. The report takes around 15 mins to run in background .
We are trying to analyse the native SQL query through DB02. I tried fetching records for one particular
custom view to make out if its indexing issue or something else.When i using TOP 35000 records with select query runs fine with this dataset or less than this . If i increase it to 40000 system doesn;t show anything in SQL ouptut. And above one lakh records system gives timeout.
The count in this view gives some 10 lakh records which I don't feel is v.v.huge that query that too native sql takes so much time.
Any help on this will be highly appreciated.
Regards
Madhuwhat do you expect from that poor information.
do you change data or onyl select.
If you use SAP and ABAP, then you should also use Open SQL.
Otherwise it is possible to run the SQL Trace with Native SQL, it is anyway only Native SQL, what the trace sees.
Use package size and it will probably work fine.
Siegfried -
Performance of native sql query detoriates
Dear Experts,
The performance of my native SQL query is bad. On the database the query takes less than 5 seconds to process. From my abap program I get a session timeout dump after 10 minutes. What might be the possible reason.
Warm Regards,
AbdullahI am not a DBA, but this is a wild guess.
I have a native SQL query. It was running fine all morning(transported it to production today). By afternoon the report was not giving any output.
I went to the MS SQL query analyzer and executed the query, it returned the results in less than 5 seconds. The same query when I was executing from SAP using native SQL took more than 10 minutes and gave a dump(time exceeded).
My database guy asked me to execute the following on the database. Dbcc dbreindex('tablename')
The report is running fine since then. I am still not satisfied if this is the reason the performance is back on track, but yeah the report is running fine again. There seems to be some problem with the indexes.
I am using standard classes provided by SAP to execute my query and after execution the resultset reference object is being closed, I am closing the connection.
the code is as below.
PERFORM:
connect USING con_name con_ref,
select_into_table USING con_ref,
disconnect USING con_ref.
* FORM connect
* Connects to the database specified by the logical connection name
* P_CON_NAME which is expected to be specified in table DBCON. In case
* of success the form returns in P_CON_REF a reference to a connection
* object of class CL_SQL_CONNECTION.
* --> P_CON_NAME logical connection name
* <-- P_CON_REF reference to a CL_SQL_CONNECTION object
FORM connect USING p_con_name TYPE dbcon-con_name
p_con_ref TYPE REF TO cl_sql_connection
RAISING cx_sql_exception.
* if CON_NAME is not initial then try to open the connection, otherwise
* create a connection object representing the default connection.
IF p_con_name IS INITIAL.
CREATE OBJECT p_con_ref.
ELSE.
p_con_ref = cl_sql_connection=>get_connection( p_con_name ).
ENDIF.
ENDFORM. " connect
* FORM select_into_table
* Selects some rows from the test table and fetches the result rows
* into an internal table whose row structure corresponds to the
* queries select list columns.
FORM select_into_table
USING p_con_ref TYPE REF TO cl_sql_connection
RAISING cx_sql_exception.
DATA:
l_stmt TYPE string,
l_stmt_ref TYPE REF TO cl_sql_statement,
l_dref TYPE REF TO data,
l_res_ref TYPE REF TO cl_sql_result_set,
*Data related query
l_itab TYPE TABLE OF t_pricing_report,
l_row_cnt TYPE i.
* create the query string
CONCATENATE
'select A.SEQ,A.CONDTABLE,A.CONDNAME,A.VKORG,A.VTWEG,A.MATKL,A.MATNR,B.MTEXT,A.VKGRP,A.SGRPNAME,'
'A.VKBUR,A.SOFFNAME,A.ZSALES,A.SCNTNAME,A.KUNNR,A.SCSTNAME,A.PRBATCH,A.INCO1,'
'A.INCO2,A.DATAB,A.DATBI,A.KBETR,A.KONWA,A.KOSRT,B.MTART,B.GROES,B.VOLUM,B.EXTWG,B.WRKST,'
'A.MXWRT,A.GKWRT,'
'B.PATTERN,B.RIM,B.SERIES,B.SPDINDEX,B.LDINDX,B.MGROUP,B.APPLN,B.SDWALL,B.MGRPTXT'
'FROM Z_PRICELIST A,Z_MATERIALVIEW B'
'WHERE A.MANDT = ? AND'
'B.MANDT = A.MANDT AND'
'A.MATNR = B.MATNR AND'
'A.KSCHL = ? AND'
'A.CONDTABLE LIKE ? AND'
'A.VKORG LIKE ? AND'
'A.VTWEG LIKE ? AND'
'A.MATKL >= ? AND A.MATKL <= ? AND'
'A.MATNR >= ? AND A.MATNR <= ? AND'
'A.INCO1 LIKE ? AND'
'A.INCO2 LIKE ? AND'
'A.ZSALES >= ? AND A.ZSALES <= ? AND'
'A.KUNNR >= ? AND A.KUNNR <= ? AND'
'A.PRBATCH >= ? AND A.PRBATCH <= ? AND'
'A.VKBUR >= ? AND A.VKBUR <= ? AND'
'A.VKGRP >= ? AND A.VKGRP <= ? AND'
'B.WRKST >= ? AND B.WRKST <= ? AND'
'B.MTART >= ? AND B.MTART <= ? AND'
'? BETWEEN A.DATAB AND A.DATBI AND'
'B.GROES LIKE ? AND'
'B.LDINDX LIKE ? AND'
'B.SPDINDEX LIKE ? AND'
'B.RIM LIKE ? AND'
'B.SERIES LIKE ? AND'
'B.PATTERN LIKE ? AND'
'B.MGROUP LIKE ?'
'order by A.MATNR'
INTO l_stmt SEPARATED BY space. "#EC NOTEXT
* create a statement object
l_stmt_ref = p_con_ref->create_statement( ).
* bind input variables
GET REFERENCE OF l_col1 INTO l_dref.
l_stmt_ref->set_param( l_dref ).
*binding other references here
GET REFERENCE OF l_col33 INTO l_dref.
l_stmt_ref->set_param( l_dref ).
* set the input values and execute the query
l_col1 = sy-mandt.
*..Assigning values here
l_col33 = p_mgroup.
* PERFORM trace_2 USING 'EXECUTE_QUERY' l_stmt l_col1 l_col2.
l_res_ref = l_stmt_ref->execute_query( l_stmt ).
* set output table
GET REFERENCE OF l_itab INTO l_dref.
l_res_ref->set_param_table( l_dref ).
* get the complete result set
l_row_cnt = l_res_ref->next_package( ).
* display the contents of the output table
* PERFORM trace_next_package USING l_itab.
* PERFORM trace_result USING l_row_cnt 'rows fetched'.
pricing_report[] = l_itab[].
free l_itab.
* don't forget to close the result set object in order to free
* resources on the database
l_res_ref->close( ).
ENDFORM. "select_into_table
* FORM disconnect
* Disconnect from the given connection. In case of the default
* connection this can be omitted.
FORM disconnect
USING p_con_ref TYPE REF TO cl_sql_connection
RAISING cx_sql_exception.
DATA: l_con_name TYPE dbcon-con_name.
l_con_name = p_con_ref->get_con_name( ).
CHECK l_con_name <> cl_sql_connection=>c_default_connection.
* PERFORM trace_0 USING 'CLOSE CONNECTION' l_con_name.
p_con_ref->close( ).
* PERFORM trace_result USING l_con_name 'closed'.
ENDFORM. "disconnect
* FORM handle_sql_exception
* Write appropriate error messages when a SQL exception has occured
* --> P_SQLERR_REF reference to a CX_SQL_EXCEPTION object
FORM handle_sql_exception
USING p_sqlerr_ref TYPE REF TO cx_sql_exception.
FORMAT COLOR COL_NEGATIVE.
IF p_sqlerr_ref->db_error = 'X'.
WRITE: / 'SQL error occured:', p_sqlerr_ref->sql_code,
/ p_sqlerr_ref->sql_message. "#EC NOTEXT
ELSE.
WRITE:
/ 'Error from DBI (details in dev-trace):',
p_sqlerr_ref->internal_error. "#EC NOTEXT
ENDIF.
ENDFORM. "handle_sql_exception -
Hi All,
We have a native SQL query accessing Oracle database(given below).
Can anyone please let me know what this query is about and how can we fine tune the query?
SELECT O.OBJECT_NAME ,
H.SID,
HS.MACHINE,
HS.PROCESS,
W.SID,
WS.MACHINE,
WS.PROCESS,
H.CTIME,
W.CTIME,
WS.ROW_WAIT_OBJ#,
WS.ROW_WAIT_FILE#,
WS.ROW_WAIT_BLOCK#,
WS.ROW_WAIT_ROW#,
HP.SPID,
WP.SPID
FROM V$LOCK H, V$LOCK W, V$LOCK I, V$LOCK I2, ALL_OBJECTS O,
V$SESSION HS, V$SESSION WS, V$PROCESS HP, V$PROCESS WP
WHERE H.ID1 = W.ID1
AND H.SID <> W.SID
AND H.TYPE IN ('TX','DL')
AND H.REQUEST = 0
AND H.SID = I.SID
AND I.TYPE = 'TM'
AND I.ID1 = O.OBJECT_ID
AND I.ID1 = I2.ID1
AND W.SID = I2.SID
AND I2.TYPE = 'TM'
AND H.SID = HS.SID
AND W.SID = WS.SID
AND HS.PADDR = HP.ADDR
AND WS.PADDR = WP.ADDR
INTO :EXCL_LOCK_WAITERS-OBJ_NAME ,
:EXCL_LOCK_WAITERS-HOLDER_SID ,
:EXCL_LOCK_WAITERS-H_HOSTNAME ,
:EXCL_LOCK_WAITERS-HOLDER_PID ,
:HOLDER_PID ,
:EXCL_LOCK_WAITERS-WAITER_SID ,
:EXCL_LOCK_WAITERS-W_HOSTNAME ,
:EXCL_LOCK_WAITERS-WAITER_PID ,
:WAITER_PID ,
:EXCL_LOCK_WAITERS-HELD_SINCE ,
:EXCL_LOCK_WAITERS-WAITSSINCE,
:ROW_WAIT_OBJ,
:ROW_WAIT_FILE,
:ROW_WAIT_BLOCK,
:ROW_WAIT_ROW,
:H_PROCESS,
:W_PROCESS
ENDEXEC
Thanks in advance.
Neethu MohanHi Neethu,
It gives you an overwiew of blocking Oracle sessions.
1. In general, the SQL checks Oracle sessions (SID's) that were requirering a DML lock ('TM') and now holding row locks (TX) to prevent destructive interference of simultaneous conflicting DML or DDL operations. DML statements automatically acquire both table-level locks and row-level locks ('TX') => holders
It joins these with the sessions that are waiting of releasing the lock by the holders => waiters.
2. it retrieves the detail information wich Oracle process , the object (table) , it's row , block and file
are affected by the locks.
3. Normally, the locks are only hold for a short period of time. If you have blocking sessions it may be of a log running task (i.e. mass data update of a table) ; but it could also be a application bug due to improper handling of concurrent updates of the same object.
4. Tuning
V$tables are expensive to query: Why?
v$ tables are generally Oracle memory structures.
v$ tables are not read consistent.
v$ tables require latches to access -- cannot modify and read memory at the same
time.
heavy access to v$ tables like this may cause some serious heavy duty contention.
Especially if you self join V$lock several times.
So the best would be to save the contents of V$LOCK in some table:
Create table mylocks as select * from v$lock;
Use that table for self-joining and joins to the other tables.
You can also CTAS the other v$ tables to bypass the performance bottleneck while retrieving
v$ directly.
You can empty or drop the created tables any time for new data.
Because you want to investigate only lock hold for a longert time to copy the v$ memory structures into
physical tables is not a disadvantage. You certainly will wait longer on finishing your query
instead of copy them into the tables.
Hope this helped
yk -
Executing Native SQL query for oracle
Hi,
I want to run following native sql query but it is giving me error ora:933,
DATA: BEGIN OF WA,
TSP_NAME(255) TYPE C,
PER_USAGE(10) TYPE C,
END OF WA.
EXEC SQL PERFORMING loop_output.
select t.tablespace_name,'(' || TO_CHAR(ROUND(100*(NVL(b.bytes,0)/NVL(a
.bytes,0)))) || '%)' "TSUsed%" from dba_tablespaces t,
( select tablespace_name, sum(bytes)/1024/1024 bytes
from dba_data_files group by tablespace_name) a,
( select e.tablespace_name, sum(e.bytes)/1024/1024 bytes
from dba_extents e group by e.tablespace_name ) b,
( select f.tablespace_name, sum(f.bytes)/1024/1024 bytes
from dba_free_space f group by f.tablespace_name ) c
where t.tablespace_name = a.tablespace_name(+) and
t.tablespace_name = b.tablespace_name(+) and
t.tablespace_name = c.tablespace_name(+) into :wa.
ENDEXEC.
Please provide me the soln
Regards,
Bharat MistryORA-00933: SQL command not properly ended.
Try:
EXEC SQL PERFORMING loop_output.
select
into :wa
ENDEXEC.
(No "." at the end). If that doesn't work, try ending it with a ";"
Rob -
Mapping Problem with Native SQL query
My application uses a native SQL query to locate certain entities. It looks like this:
SELECT UPLOADATTEMPTREF, STUDENTNUMBER, USERID, WORKITEMCODE, WORKITEMINSTURN, WORKITEMTITLE, MODULERUNCODE, STUDENTNAME, SUBMISSIONDEADLINE, UPLOADATTEMPTSERVERDATE, FILENAME, UPLOADCOMPLETESERVERDATE, NEWFILENAME, FILESIZE, FILEPATH, DOWNLOADSERVERDATE, MODULECODE, MODULETITLE
FROM Submission_Attempt WHERE UPLOADATTEMPTREF IN (
SELECT uploadAttemptRef FROM (" +<br /><br /> "SELECT MAX(uploadAttemptRef) AS uploadAttemptRef, UserID, workItemInstUrn, " +<br /><br /> "workItemCode FROM Submission_Attempt where workiteminsturn = ?1 " +<br /><br /> "GROUP BY UserID, workItemInstUrn, workItemCode) Table1 ) " +<br /><br /> "and uploadCompleteServerDate is not null;"<br />
My expectation was that EclipseLink would be able to handle the mapping of the results to the entity quite happily. However, I get a NonSynchronizedVector of Objects - each Object representing one field of data.
I need help with either:
Converting the above SQL into JPQL so that I (hopefully) don't have to worry about the SQL or
Understanding why this isn't working properly...
Anyone able to help?
Edited by: phunnimonkey on Nov 6, 2008 3:33 AMNever mind - the problem was to do with not specifying a class when creating the native query.
-
Why field length is shorter than the actual one in a SQL query based grid?
Hi,
I have a grid based on a SQL query on a UDO table, but I found when I retrieve the data from a SQL query some column show only part of data. For example, in SQL server the query should return one column data like "ABCD", but in the grid it only shows "A" or "AB". I think the SQL query should be good because when copy the same query executing in SQL server side, it returns me all complete data. But when it is executed in add-on inside a grid, then some column only returns me partial data. In most case it only return the first one or two characters. I don't see any special in the query. Basically it is normal SELECT query, the only possible special is it is using "UNION".
The SQL query looks like below:
SELECT fieldA, fieldB FROM table1
UNION ALL
SELECT fieldA, fieldB FROM table2
When it is executed in SQL side, everything looks good, but when i run it in a grid in add-on then fieldB column only display partial data.
Any idea?
Thanks,
Lan
Edited by: ZHANGLAN on Oct 4, 2011 11:55 PMHi All,
Thanks for all your replies, I agree that the issue is caused by the UNION in SQL query. Because when i create a view in SQL based on that query and the grid is based on that SQL view then everything is fine now. I think Petr's solution should work in this case.
Thank you again!
Lan -
Using '(' and less than operator in an xsql page sql query
Dear All,
I tried to use left parenthesis '(' and less than operator in an sql query through an xsql page, it doesn't let to use them.
Do you know how to use those in an xsql page?
Thanks for your help.
MustafaFollowing is the xsql page that I tried to run:
<?xml version="1.0"?>
<xsql:query xmlns:xsql="urn:oracle-xsql" connection = "bib" rowset-element="bib" row-element="book">
(SELECT year,title,last,first,' ' as affiliation,publisher,price
FROM book,author
WHERE year=2001 and bookid=parentid
UNION
SELECT year,title,last,first,affiliation,publisher,price
FROM book,editor
WHERE year=2001 and bookid=parentid)
INTERSECT
(SELECT year,title,last,first,' ' as affiliation,publisher,price
FROM book,author
WHERE publisher='Publisher1' and bookid=parentid
UNION
SELECT year,title,last,first,affiliation,publisher,price
FROM book,editor
WHERE publisher='Publisher1' and bookid=parentid)
</xsql:query>
This is the error message generated after running:
<ERROR>java.sql.SQLException: ORA-01009: missing mandatory parameter</ERROR>
When I remove the parentheses it works but this results in a different result set.
Can anybody tell me the reason?
Thanks,
Mustafa
null -
Dear All,
I have a requirement, to write a SQL query to populate the records which are inserted less than 10 no of records.
The tables has the cretaed_date column and along with other key column which will have unique values.
Ex1: The user might have inserted records from application, per week basis, between the date range '01-jun-2013' - 08-jun-2013 , the no of records created by the user during this week may be less than 10 records or more.
But I want to populate the records by giving date range that too, it should pick the records the count which fall with in 10 records.
I dont want the query to populate the records if the user has inserted more than 10 records in a week.
Ex2:
User 1 has created 15 records during the week 1 ( the query should not populate this ).
User 2: has cretaed less than 10 records from the UI during the week 2. ( This details should get populated ).
ThanksUse COUNT to find how many rows where inserted in a week.
If this does not answer your question then please read Re: 2. How do I ask a question on the forums? And provide necessary details. -
Fetch join with Native SQL Query?
Hello all,
I am using the J2EE 5.0 persistence api with the SUN appserver v9. As the java persistence api does not yet support spatial queries ("... where contains(polygon, point)") I have to use native SQL queries for that purpose.
Now my question is how can I "join fetch" my ManyToOne-related entities when using a native SQL query? Is this somehow possible using the SqlResultSetMapping annotation?Never mind - the problem was to do with not specifying a class when creating the native query.
-
Hi,
I tried to read data using the following SQL Query,
fp_work = 'ABCD'.
EXEC SQL PERFORMING WRITE_TO_ITAB .
SELECT fp_code, bank_acc_code, bank_acc_num,
INTO :gs_cds_data-FP_CODE,
:gs_cds_data-BANK_ACC_CODE,
:gs_cds_data-BANK_ACC_NUM,
FROM BANK_TABLE
WHERE fp_code = :fp_wrk
ENDEXEC.
*& Form WRITE_to_itab
FORM write_to_itab.
To move the data into the Internal Table.
APPEND gs_cds_data TO gt_cds_data.
CLEAR gs_cds_data.
ENDFORM. "WRITE_to_itab
and im getting the run time error..
What happened?
The error occurred in the current database connection "SAPABC".
How to correct the error
Database error text........: "ORA-00936: missing expression"
Triggering SQL statement...: "FETCH NEXT "
Internal call code.........: "[DBDS/NEW DSQL]"
Please check the entries in the system log (Transaction SM21).
You may able to find an interim solution to the problem
in the SAP note system. If you have access to the note system yourself,
use the following search criteria:
"DBIF_DSQL2_SQL_ERROR" C
If you cannot solve the problem yourself, please send the
following documents to SAP:
Can anyone give me a solution to correct this error?
In addition, Can i omit the WHERE clause, as i need to get all the data in the oracle database?BUT,
EXEC SQL.
connect to :LV_DB_NAME as :sy-uname
ENDEXEC.
EXEC SQL.
SET CONNECTION :sy-uname
ENDEXEC.
check sy-subrc..
connection is happening.. with sy-subrc value as ZERO -
I'd like to know if there is any easy, and convenient way, for someone to execute an SQL query an calculate, these measurments relative to the query:
1) The I/O performed
2)Number Read I/O
3) Number of Write out I/O
(such that 2+3 = 1
4) Number of buffered reads
5)Query Execution time
6) Query CPU usage
I've heard mention of such statisctis in views such as V$OSSTAT, etc.
But these views give the current values, and not the specific cumulative values. Such as: cummulative CPU usage time since start of the query; cumulative I/O since query begin, etc...
What is the right approach to this. Is it through the V$SESSION view? Would you about it by storing the V$SESSIOn values before the query, you run the query, and get the new V$SESSION values?Well, actually i stayed here a little longer to try you part 2 of the manual.
It worked fine, following comes the output, originating from a spool file, of my first experiment:
Connected.
SQL> set timing on trimspool on linesize 250 pagesize 999
SQL>
SQL> -- system environment can be checked with:
SQL> -- show parameter statis
SQL> -- this show a series of parameters related to statistics
SQL>
SQL> -- this setting can influence your sorting
SQL> -- in particular if an index can satisfy your sort order
SQL> -- alter session set nls_language = 'AMERICAN';
SQL>
SQL>
SQL> rem Set the ARRAYSIZE according to your application
SQL> set arraysize 15 termout off
SQL>
SQL> spool diag2.log
SQL>
SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'))
PLAN_TABLE_OUTPUT
SQL_ID b4j5rmwug3u8p, child number 0
SELECT USRID, FAVF FROM (SELECT ID as USRID, FAVF1, FAVF2, FAVF3,
FAVF4, FAVF5 FROM PROFILE) P UNPIVOT (FAVF FOR CNAME IN ( FAVF1,
FAVF2, FAVF3, FAVF4, FAVF5)) FAVFRIEND
Plan hash value: 888567555
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time |
Buffers |
| 0 | SELECT STATEMENT | | 1 | | 5 |00:00:00.01 |
8 |
|* 1 | VIEW | | 1 | 5 | 5 |00:00:00.01 |
8 |
| 2 | UNPIVOT | | 1 | | 5 |00:00:00.01 |
8 |
| 3 | TABLE ACCESS FULL| PROFILE | 1 | 1 | 1 |00:00:00.01 |
8 |
Predicate Information (identified by operation id):
1 - filter("unpivot_view_013"."FAVF" IS NOT NULL)
Note
- dynamic sampling used for this statement
26 rows selected.
Elapsed: 00:00:00.14
SQL>
SQL> spool off
SQL>
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Pr
oduction
With the OLAP, Data Mining and Real Application Testing options
C:\Documents and Settings\Administrator\My Documents\scripts\oracle\99templates_
autotrace>my_part2_template.bat
C:\Documents and Settings\Administrator\My Documents\scripts\oracle\99templates_
autotrace>sqlplus /NOLOG @my_part2_template.sql
SQL*Plus: Release 11.1.0.7.0 - Production on Qui Jul 9 22:00:39 2009
Copyright (c) 1982, 2008, Oracle. All rights reserved.
Connected.
SQL> set timing on trimspool on linesize 250 pagesize 999
SQL>
SQL> -- system environment can be checked with:
SQL> -- show parameter statis
SQL> -- this show a series of parameters related to statistics
SQL>
SQL> -- this setting can influence your sorting
SQL> -- in particular if an index can satisfy your sort order
SQL> -- alter session set nls_language = 'AMERICAN';
SQL>
SQL>
SQL> rem Set the ARRAYSIZE according to your application
SQL> set arraysize 15 termout off
SQL>
SQL> spool diag2.log
SQL>
SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'))
PLAN_TABLE_OUTPUT
SQL_ID b4j5rmwug3u8p, child number 0
SELECT USRID, FAVF FROM (SELECT ID as USRID, FAVF1, FAVF2, FAVF3,
FAVF4, FAVF5 FROM PROFILE) P UNPIVOT (FAVF FOR CNAME IN ( FAVF1,
FAVF2, FAVF3, FAVF4, FAVF5)) FAVFRIEND
Plan hash value: 888567555
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time |
Buffers |
| 0 | SELECT STATEMENT | | 1 | | 5 |00:00:00.01 |
8 |
|* 1 | VIEW | | 1 | 5 | 5 |00:00:00.01 |
8 |
| 2 | UNPIVOT | | 1 | | 5 |00:00:00.01 |
8 |
| 3 | TABLE ACCESS FULL| PROFILE | 1 | 1 | 1 |00:00:00.01 |
8 |
Predicate Information (identified by operation id):
1 - filter("unpivot_view_013"."FAVF" IS NOT NULL)
Note
- dynamic sampling used for this statement
26 rows selected.
Elapsed: 00:00:00.01
SQL>
SQL> spool off
SQL>
SQL>
SQL> -- rem End of Part 2
SQL> show parameter statis
NAME TYPE VALUE
optimizer_use_pending_statistics boolean FALSE
statistics_level string ALL
timed_os_statistics integer 5
timed_statistics boolean TRUE
SQL> quitIf you notice, at the end of the execution I print my statistics session environment. The statistics_level was set to ALL, as you advisied. But the output I obtained seems a lot more incomplete than the one I got from using the autotrace feature.
Am I missing something. Could it have something to do with the fact that I am running as system and not as sysdba? System shoul have enough permissions to access its session environment statistic values.
May be it's just a language issue (I'm not a native speaker either) but your understanding of Oracle's read consistency model seems to be questionable.No, you could be right; my understanding is questionable indeed. I am familiar with general concepts of concurrency.
Things like: Read uncommited data:
T1 Writes A; T2 Reads A -> Here is a conflict
This enough for you to not be able to guarantee that the execution is serializable.
T1 Reads A, T2 Writes A and commits, T1 Reads A - You get another confli, the Unrepeatable read.
And so on.
I am also familiar with the different levels of atomicity that databse systems in general give you.
Conflict Serializable, normally implemented by using the strict phase locking mechanism.
Repeatable Reads, you lock the rows you access during a transaction. You are guaranteed that those data values you access do not change value; but other entires in the table could be put.
Unrepeatable reads. Only the data you modify is guaranteed to stay the same. Only you write locks are kept throughout the transaction. And so on.
But anyway...
What you explained in your post is more or less what I was saying. In you case much more clear than in mine.
For instance, if a thread T1 reads A; a thread T2 Writes on A
In oracle, you could have the thread T1 read A again without geting an Unrepeatable Read error. This is strange: in a normal system you directly get an exception telling you that your vision of the system is inconsistent. But in oracel you can do so, because oracle tries to fetch from the Undo Table Space that same data objects consistent with the view of the system you had when you first accessed it. It looks for a block with an an SCN older than the current version SCN. Or something like that. The only problem is that those modified blocks do not stay indefinitely there. Once a transaction commits you have a time bomb in your hands. That is, if you are working with that is not at its most current version.
But you are quite right, I have not read enough about Oracle concurrency. But I have a good enough understanding for mu current needs.
I can not know everything, nor do i want to :D.
My memory is very limited.
My best regards, and deepest thanks for your time and attention.
Edited by: user10282047 on Jul 9, 2009 2:41 PM -
Dear all,
what is meant by SQL Query?
I have a report which is directly in production and not in development.its a user created program.
some one said that it is SQL query.
What is meant by it ?
Is there any name for that SQL query?
If yes,how can I find it?Hi,
SQL Query means select statement u r getting the data from the database table.
Standard SQL
SQL (Structured Query Language) is a largely standardized language for accessing relational databases. It can be divided into three areas:
· Data Manipulation Language (DML)
Statements for reading and changing data in database tables.
· Data Definition Language (DDL)
Statements for creating and administering database tables.
· Data Control Language (DCL)
Statements for authorization and consistency checks.
Each database has a programming interface that allows you to access the database tables using SQL statements. The SQL statements in these programming interfaces are not fully standardized. To access a specific database system, you must refer to the documentation of that system for a list of the SQL statements available and their correct syntax.
The Database Interface
To make the R/3 System independent of the database system with which you use it despite the differences in the SQL syntax between various databases, each work process on an application server has a database interface. The R/3 System communicates with the database by means of this interface. The database interface converts all of the database requests from the R/3 System into the correct Standard SQL statements for the database system. To do this, it uses a database-specific component that shields the differences between database systems from the rest of the database interface. You choose the appropriate layer when you install the R/3 System.
There are two ways of accessing the database from a program - with Open SQL or Native SQL.
Open SQL
Open SQL statements are a subset of Standard SQL that is fully integrated in ABAP. They allow you to access data irrespective of the database system that the R/3 installation is using. Open SQL consists of the Data Manipulation Language (DML) part of Standard SQL; in other words, it allows you to read (SELECT) and change (INSERT, UPDATE, DELETE) data.
Open SQL also goes beyond Standard SQL to provide statements that, in conjunction with other ABAP constructions, can simplify or speed up database access. It also allows you to buffer certain tables on the application server, saving excessive database access. In this case, the database interface is responsible for comparing the buffer with the database. Buffers are partly stored in the working memory of the current work process, and partly in the shared memory for all work processes on an application server. Where an R/3 System is distributed across more than one application server, the data in the various buffers is synchronized at set intervals by the buffer management. When buffering the database, you must remember that data in the buffer is not always up to date. For this reason, you should only use the buffer for data which does not often change. You specify whether a table can be buffered in its definition in the ABAP Dictionary.
Native SQL
Native SQL is only loosely integrated into ABAP, and allows access to all of the functions contained in the programming interface of the respective database system. Unlike Open SQL statements, Native SQL statements are not checked and converted, but instead are sent directly to the database system. When you use Native SQL, the function of the database-dependent layer is minimal. Programs that use Native SQL are specific to the database system for which they were written. When writing R/3 applications, you should avoid using Native SQL wherever possible. It is used, however, in some parts of the R/3 Basis System - for example, for creating or changing table definitions in the ABAP Dictionary.
The ABAP Dictionary
The ABAP Dictionary, part of the ABAP Workbench, allows you to create and administer database tables. Open SQL contains no statements from the DDL part of Standard SQL. Normal application programs should not create or change their own database tables.
The ABAP Dictionary uses the DDL part of Open SQL to create and change database tables. It also administers the ABAP Dictionary in the database. The ABAP Dictionary contains metadescriptions of all database tables in the R/3 System. Only database tables that you create using the ABAP Dictionary appear in the Dictionary. Open SQL statements can only access tables that exist in the ABAP Dictionary.
Authorization and Consistency Checks
The DCL part of Standard SQL is not used in R/3 programs. The work processes within the R/3 System are logged onto the database system as users with full rights. The authorizations of programs or users to read or change database tables is administered within the R/3 System using the R/3 authorization concept. Equally, transactions must ensure their own data consistency using the R/3 locking concept. For more information, refer to Authorization Concept and Programming Database Updates.
Plzz reward points if it helps.
Edited by: manjari kotta on Dec 18, 2007 7:29 AM
Maybe you are looking for
-
Can you have Two iMessage accounts on a MBP
We have mid 2009 MBP running Yosemite 10.10.1 The MBP is in my wifes name, I tend to use it all the time rather than the wife, so I use her user account rather making my own user account on the Mac, but do we have our own Apple id's. The MBP has neve
-
Wow, I tried to submit this as a problem and the computer lost the wifi connection again, so i lost the whole explanation i typed up. I've turned off computer and modem multiple times. When I tried to run the network diagnostic, the macbook pro gave
-
New role with workbooks not visible
Dear all, I have something strange. I created a role and I saved workbooks in it. When I create a new workbook and save, I can see this role and I can save the workbook in my role (this role is assigned to me). However, when I reopen the workbook, I
-
How do I make dynamic links to Excel cells, not sheets?
Help! I thought I'd found the perfect way to link an in-progress Excel spreadsheet to an in-progress InDesign file. That allowed the Product Management group to do content, and the graphic group to do layout simultaneously. After several days of layo
-
I used to use batch apply RAW settings to multiple picutres in PSE 3. Now I can't find it in PSE 4. Anyone knows if it is still there?