Break the algorithm through sql query
Hi,
My table 'x' contains data as follows:
Row_id
Person
Effective_date
Status
Code
1
12345
8-Apr-04
POS
A
2
12345
13-Jun-04
PLA
P
3
12345
20-Oct-04
POS
P
4
12345
1-Apr-05
PAY
P
5
12345
8-Aug-05
RFL
A
6
12345
8-Aug-05
XFR
A
7
12345
1-Apr-05
PAY
P
Need this row as output
8
12345
14-Jul-06
LOA
L
9
12345
1-Oct-06
PAY
P
10
12345
16-Jul-07
LOA
L
11
12345
17-Jul-07
RFL
A
Logic that should be used:
1. Get the most recent row based on effective date and code in L or P-> In this case row 10 since this row has L and is latest one
2. Then go back in time until the code is not in L or P -> so based on above data row 6 since the code is 'A'
3. Then come forward from that record 6 until you get status LOA or PLA -> you will come and stand on row '8'
4. finally i need the row_id = 8 as output based on the above steps
Pls help me in framing a query for this
Your effective dates are not unique, therefore it is impossible to decide which row with same effective date goes first. It is not possible to provide a deterministic solution until you define rules how to order rows with same effective date. Solution below is non-deterministic. Because you have rows with same effective date it can produce different results next time you run it. When you define ordering rules add them to ORDER BY clause of ROW_NUMBER function in below code. This will make it deterministic:
with t1 as (
select e.*,
row_number() over(partition by emplid order by effective_start_date) rn
from employee e
t2 as (
select t1.*,
max(
case
when code in ('L','P') then rn
end
over(partition by emplid) last_l_p_rn,
last_value(
case
when code not in ('L','P') then rn
end
ignore nulls
over(partition by emplid order by rn) last_non_l_p_rn,
first_value(
case
when status in ('LOA','PLA') then rn
end
ignore nulls
over(
partition by emplid
order by rn
rows between current row and unbounded following
) first_loa_pla_rn
from t1
select emplid,
effective_start_date,
status,
code
from t2
where level = 3
start with rn = last_l_p_rn
connect by (emplid = prior emplid and rn = prior last_non_l_p_rn and level = 2)
or (emplid = prior emplid and rn = prior first_loa_pla_rn and level = 3)
EMPLID EFFECTIVE STA C
12345 14-JUL-06 LOA L
SQL>
SY.
Similar Messages
-
Issue in creation of group in oim database through sql query.
hi guys,
i am trying to create a group in oim database through sql query:
insert into ugp(ugp_key,ugp_name,ugp_create,ugp_update,ugp_createby,ugp_updateby,)values(786,'dbrole','09-jul-12','09-jul-12',1,1);
it is inserting the group in ugp table but it is not showing in admin console.
After that i also tried with this query:
insert into gpp(ugp_key,gpp_ugp_key,gpp_write,gpp_delete,gpp_create,gpp_createby,gpp_update,gpp_updateby)values(786,1,1,1,'09-jul-12',1,'09-jul-12',1);
After that i tried with this query.but still no use.
and i also tried to assign a user to the group through query:
insert into usg(ugp_key,usr_key,usg_priority,usg_create,usg_update,usg_createby,usg_updateby)values(4,81,1,'09-jul-12','09-jul-12',1,1);
But still the same problem.it is inserting in db.but not listing in admin console.
thanks,
hanuman.Hanuman Thota wrote:
hi vladimir,
i didn't find this 'ugp_seq'.is this a table or column?where is it?
It is a sequence.
See here for details on oracle sequences:
http://www.techonthenet.com/oracle/sequences.php
Most of the OIM database schema is created with the following script, located in the RCU distribution:
$RCU_HOME/rcu/integration/oim/sql/xell.sql
there you'll find plenty of sequence creation directives like:
create sequence UGP_SEQ
increment by 1
start with 1
cache 20
to create a sequence, and
INSERT INTO UGP (UGP_KEY, UGP_NAME, UGP_UPDATEBY, UGP_UPDATE, UGP_CREATEBY, UGP_CREATE,UGP_ROWVER, UGP_DATA_LEVEL, UGP_ROLE_CATEGORY_KEY, UGP_ROLE_OWNER_KEY, UGP_DISPLAY_NAME, UGP_ROLENAME, UGP_DESCRIPTION, UGP_NAMESPACE)
VALUES (ugp_seq.nextval,'SYSTEM ADMINISTRATORS', sysadmUsrKey , SYSDATE,sysadmUsrKey , SYSDATE, hextoraw('0000000000000000'), 1, roleCategoryKey, sysadmUsrKey, 'SYSTEM ADMINISTRATORS', 'SYSTEM ADMINISTRATORS', 'System Administrator role for OIM', 'Default');
as a sequence usage example.
Regards,
Vladimir -
Help needed in Exporting tables data through SQL query
Hi All,
I need to write a shell script(ksh) to take some of the tables data backup.
The tables list is not static, and those are selecting through dynamic sql
query.
Can any body tell help me how to write the export command to export tables
which are selected dynamically through SQL query.
I tried like this
exp ------ tables = query \" select empno from emp where ename\= \'SSS\' \"
but its throws the following error
EXP-00035: QUERY parameter valid only for table mode exports
Thanks in advance,Hi,
You can dynamically generate parameter file for export utility using shell script. This export parameter file can contain any table list you want every time. Then simply run the command
$ exp parfile=myfile.txt -
Row value needs to be changes as column through SQL Query
HI ALL
I have a table like below
ID Month VALUES
1 01-jan 10
1 01-feb 20
2 01-jan 10
2 01-feb 20
I need the output like below
ID 01-jan 01-feb
1 10 20
2 10 20
How can i get it through SQL Query?. Please help me on that i have urgent work like thisIn effect because you are wanting to take X rows and squish them down to 1 row per id, you are gouping on the ID to typically a group by clause is the best way to do this.
If you really wanted to do it without aggregate functions and a group by clause you would be looking for something like this...
SQL> ed
Wrote file afiedt.buf
1 WITH t as (select 1 as id, '01-jan' as month, 10 as val from dual union all
2 select 1, '01-feb', 20 from dual union all
3 select 1, '01-mar', 30 from dual union all
4 select 2, '01-jan', 10 from dual union all
5 select 2, '01-feb', 30 from dual union all
6 select 2, '01-mar', 60 from dual)
7 --
8 select id, jan, feb, mar
9 from (
10 select id
11 ,row_number() over (partition by id order by to_date(month,'dd-mon')) as rn
12 ,val as jan
13 ,lead(val) over (partition by id order by to_date(month,'dd-mon')) as feb
14 ,lead(val,2) over (partition by id order by to_date(month,'dd-mon')) as mar
15 from t
16 )
17* where rn = 1
SQL> /
ID JAN FEB MAR
1 10 20 30
2 10 30 60
SQL>Although this will only work if you can guarantee that there is a '01-jan' value for each id. If there could be missing values then you'll have to use aggregate functionality. -
Finding the Text of SQL Query causing Full Table Scans
Hi,
does anyone have a sql script, that shows the complete sql text of queries that have caused a full table scan?
Please also let me know as to how soon this script needs to be run, in the sense does it work only while the query is running or would it work once it completes (if so is there a valid duration, such as until next restart, etc.)
Your help is appreciated.
Thx,
MayuranFinding the Text of SQL Query Causing Full Table Scan
-
How to insert the records using sql query
hi,
i insert the record uisng sql query and DOTNET programme successfully and increase the doc num .ubut when i try to add record using SAP B1 the old Doc no show.It means its not consider the docnums which are not inserted by sql query.
how can i solve this problem?
Regards,
M.Thippa ReddyYou are not support use Insert / Update / Delete on SAP Databases directly.
SAP will not support any database, which is inconsistent, due to SQL-Queries, which modify datasets or the datastructure of the SAP Business One Database. This includes any update-, delete- or drop-statements executed via SQL-Server Tools or via the the query interface of SAP Business One
Check SAP Note: 896891 Support Scope for SAP Business One - DB Integrity
[https://websmp130.sap-ag.de/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/smb_searchnotes/display.htm?note_langu=E¬e_numm=896891] -
Determining the parameters passed in a Discoverer Report through SQL query
Hi,
I want to know the parameters passed in a Discoverer Report through a SQL query.
i.e if we pass the Report name (Workbook Name) then we get the paramaters used .
Is there any way we can do this.
Any help will be really appreciated.
Thanx in advance
AnkurHi
You can indeed get the parameters from the EUL5_QPP_STATS table, although they are extremely difficult to get at.
Look at this script:
SELECT
QS.QS_DOC_OWNER USER_NAME,
QS.QS_DOC_NAME WORKBOOK,
QS.QS_DOC_DETAILS WORKSHEET,
TRUNC(QS.QS_CREATED_DATE) DOC_DATE,
*(LENGTH(TO_CHAR(EUL5_GET_ITEM_NAME(QS.QS_ID)))+1)/9 ITEMS,*
EUL5_GET_ITEM(SUBSTR(EUL5_GET_ITEM_NAME(QS.QS_ID),1, 6)) ITEM1,
EUL5_GET_ITEM(SUBSTR(EUL5_GET_ITEM_NAME(QS.QS_ID),10, 6)) ITEM2,
EUL5_GET_ITEM(SUBSTR(EUL5_GET_ITEM_NAME(QS.QS_ID),19, 6)) ITEM3,
EUL5_GET_ITEM(SUBSTR(EUL5_GET_ITEM_NAME(QS.QS_ID),28, 6)) ITEM4,
EUL5_GET_ITEM(SUBSTR(EUL5_GET_ITEM_NAME(QS.QS_ID),37, 6)) ITEM5,
EUL5_GET_ITEM(SUBSTR(EUL5_GET_ITEM_NAME(QS.QS_ID),46, 6)) ITEM6,
EUL5_GET_ITEM(SUBSTR(EUL5_GET_ITEM_NAME(QS.QS_ID),55, 6)) ITEM7,
EUL5_GET_ITEM(SUBSTR(EUL5_GET_ITEM_NAME(QS.QS_ID),64, 6)) ITEM8,
EUL5_GET_ITEM(SUBSTR(EUL5_GET_ITEM_NAME(QS.QS_ID),73, 6)) ITEM9,
EUL5_GET_ITEM(SUBSTR(EUL5_GET_ITEM_NAME(QS.QS_ID),82, 6)) ITEM10,
EUL5_GET_ITEM(SUBSTR(EUL5_GET_ITEM_NAME(QS.QS_ID),91, 6)) ITEM11,
EUL5_GET_ITEM(SUBSTR(EUL5_GET_ITEM_NAME(QS.QS_ID),100,6)) ITEM12,
EUL5_GET_ITEM(SUBSTR(EUL5_GET_ITEM_NAME(QS.QS_ID),109,6)) ITEM13,
EUL5_GET_ITEM(SUBSTR(EUL5_GET_ITEM_NAME(QS.QS_ID),118,6)) ITEM14,
EUL5_GET_ITEM(SUBSTR(EUL5_GET_ITEM_NAME(QS.QS_ID),127,6)) ITEM15,
EUL5_GET_ITEM(SUBSTR(EUL5_GET_ITEM_NAME(QS.QS_ID),136,6)) ITEM16,
EUL5_GET_ITEM(SUBSTR(EUL5_GET_ITEM_NAME(QS.QS_ID),145,6)) ITEM17,
EUL5_GET_ITEM(SUBSTR(EUL5_GET_ITEM_NAME(QS.QS_ID),154,6)) ITEM18,
EUL5_GET_ITEM(SUBSTR(EUL5_GET_ITEM_NAME(QS.QS_ID),163,6)) ITEM19,
EUL5_GET_ITEM(SUBSTR(EUL5_GET_ITEM_NAME(QS.QS_ID),172,6)) ITEM20
FROM
EUL5_QPP_STATS QS--,
-- APPS.FND_USER USR
WHERE
-- QS.QS_DOC_OWNER = '#' || USR.USER_ID AND
*(LENGTH(TO_CHAR(EUL5_GET_ITEM_NAME(QS.QS_ID)))+1)/9 < 21*
AND QS.QS_CREATED_DATE > '01-JAN-2007'
What this does is return the first 20 items used in a worksheet. It does this by passing 6 characters at a time out of a cusror made up by concatenating QS_DBMP0 to QS_DBMP7 to get the Dimensions and then again by concatenating QS_MBMP0 to QS_MBMP7 to get the Measures. Having got that cursor it then takes each 6 characters and passes them to a nibble algorithm to decode the actual item. The code is extremely difficult to follow.
I mention this because other fields in the same table are QS_JBMP0 to QS_JBMP7 which I believe are Joins, and QS_FBMP0 to QS_FBMP7 which look like Filters (aka parameters) being used. I think the QS stands for Query Statistics and BMP for bitmap. Somewhere in the EUL5.SQL script is the key to unlocking this.
Good luck. The reason I say this will become apparent when you look inside EUL5.SQL.
Best wsihes
Mcihael -
How to get the metadata (in xml format) of all the fileds in SQl query ?
Good day ,
I am using the dbms_xmlgen.getXMLfunction to get the result of any query in xml format.
With this XML I also want the metadata information about all the fields used in the query (passed to getXML function). Is it possible and how can I achieve this.
I tried to Google it but couldn't find any solution , it's easy to do it in java where I can get the resultset meta data from the resultset but I have to do it in Oracle function since I want the result in xml format and want to use the oracle XML API.
You may think why I need metadata , the reason is the application will later use this information to sort the data contained in these fields according to their data type provided to.
Regards
Sajjad Ahmed ParachaHi,
Please always say which version of Oracle you're using (SELECT * FROM v$version).
With this XML I also want the metadata information about all the fields used in the query (passed to getXML function). Is it possible and how can I achieve this.It is possible but with a bit of effort.
I would use DBMS_SQL utility to parse the query, extract each column's description and then build a METADATA element with the required information.
Here's an example (11g) :
DECLARE
v_query varchar2(30) := 'select * from scott.emp';
v_cur integer;
v_desc_tab dbms_sql.desc_tab;
v_col_cnt number;
v_col_lst varchar2(4000);
v_xml_query varchar2(32767);
xml_metadata_coll xmlsequencetype := xmlsequencetype();
xml_metadata xmltype;
res clob;
BEGIN
v_cur := dbms_sql.open_cursor;
dbms_sql.parse(v_cur, v_query, dbms_sql.native);
dbms_sql.describe_columns(v_cur, v_col_cnt, v_desc_tab);
dbms_sql.close_cursor(v_cur);
for i in 1 .. v_col_cnt loop
if i > 1 then
v_col_lst := v_col_lst || ', ';
end if;
v_col_lst := v_col_lst || v_desc_tab(i).col_name;
xml_metadata_coll.extend;
select xmlelement("COLUMN"
, xmlattributes(v_desc_tab(i).col_name as "name")
, xmlforest(
case v_desc_tab(i).col_type
when 1 then 'VARCHAR2'
when 2 then 'NUMBER'
when 12 then 'DATE'
when 180 then 'TIMESTAMP'
else 'UNKNOWN'
end as "DATATYPE"
, v_desc_tab(i).col_max_len as "MAX_LENGTH"
, v_desc_tab(i).col_precision as "PRECISION"
, v_desc_tab(i).col_scale as "SCALE"
into xml_metadata_coll(i)
from dual;
end loop;
v_xml_query :=
'SELECT XMLSerialize(document
XMLElement("ROOT"
, :1
, XMLElement("ROWSET"
, XMLAgg(
XMLElement("ROW", XMLForest(' || v_col_lst || '))
) as clob indent
FROM ( ' || v_query || ')';
select xmlelement("METADATA", xmlagg(column_value))
into xml_metadata
from table(xml_metadata_coll)
execute immediate v_xml_query into res using xml_metadata;
dbms_output.put_line(res);
END;
/Ouput :
<ROOT>
<METADATA>
<COLUMN name="EMPNO">
<DATATYPE>NUMBER</DATATYPE>
<MAX_LENGTH>22</MAX_LENGTH>
<PRECISION>4</PRECISION>
<SCALE>0</SCALE>
</COLUMN>
<COLUMN name="ENAME">
<DATATYPE>VARCHAR2</DATATYPE>
<MAX_LENGTH>10</MAX_LENGTH>
<PRECISION>0</PRECISION>
<SCALE>0</SCALE>
</COLUMN>
<COLUMN name="JOB">
<DATATYPE>VARCHAR2</DATATYPE>
<MAX_LENGTH>9</MAX_LENGTH>
<PRECISION>0</PRECISION>
<SCALE>0</SCALE>
</COLUMN>
<COLUMN name="MGR">
<DATATYPE>NUMBER</DATATYPE>
<MAX_LENGTH>22</MAX_LENGTH>
<PRECISION>4</PRECISION>
<SCALE>0</SCALE>
</COLUMN>
<COLUMN name="HIREDATE">
<DATATYPE>DATE</DATATYPE>
<MAX_LENGTH>7</MAX_LENGTH>
<PRECISION>0</PRECISION>
<SCALE>0</SCALE>
</COLUMN>
<COLUMN name="SAL">
<DATATYPE>NUMBER</DATATYPE>
<MAX_LENGTH>22</MAX_LENGTH>
<PRECISION>7</PRECISION>
<SCALE>2</SCALE>
</COLUMN>
<COLUMN name="COMM">
<DATATYPE>NUMBER</DATATYPE>
<MAX_LENGTH>22</MAX_LENGTH>
<PRECISION>7</PRECISION>
<SCALE>2</SCALE>
</COLUMN>
<COLUMN name="DEPTNO">
<DATATYPE>NUMBER</DATATYPE>
<MAX_LENGTH>22</MAX_LENGTH>
<PRECISION>2</PRECISION>
<SCALE>0</SCALE>
</COLUMN>
</METADATA>
<ROWSET>
<ROW>
<EMPNO>7369</EMPNO>
<ENAME>SMITH</ENAME>
<JOB>CLERK</JOB>
<MGR>7902</MGR>
<HIREDATE>1980-12-17</HIREDATE>
<SAL>800</SAL>
<DEPTNO>20</DEPTNO>
</ROW>
<ROW>
<EMPNO>7499</EMPNO>
<ENAME>ALLEN</ENAME>
<JOB>SALESMAN</JOB>
<MGR>7698</MGR>
<HIREDATE>1981-02-20</HIREDATE>
<SAL>1600</SAL>
<COMM>300</COMM>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7521</EMPNO>
<ENAME>WARD</ENAME>
<JOB>SALESMAN</JOB>
<MGR>7698</MGR>
<HIREDATE>1981-02-22</HIREDATE>
<SAL>1250</SAL>
<COMM>500</COMM>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7566</EMPNO>
<ENAME>JONES</ENAME>
<JOB>MANAGER</JOB>
<MGR>7839</MGR>
<HIREDATE>1981-04-02</HIREDATE>
<SAL>2975</SAL>
<DEPTNO>20</DEPTNO>
</ROW>
<ROW>
<EMPNO>7654</EMPNO>
<ENAME>MARTIN</ENAME>
<JOB>SALESMAN</JOB>
<MGR>7698</MGR>
<HIREDATE>1981-09-28</HIREDATE>
<SAL>1250</SAL>
<COMM>1400</COMM>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7698</EMPNO>
<ENAME>BLAKE</ENAME>
<JOB>MANAGER</JOB>
<MGR>7839</MGR>
<HIREDATE>1981-05-01</HIREDATE>
<SAL>2850</SAL>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7782</EMPNO>
<ENAME>CLARK</ENAME>
<JOB>MANAGER</JOB>
<MGR>7839</MGR>
<HIREDATE>1981-06-09</HIREDATE>
<SAL>2450</SAL>
<DEPTNO>10</DEPTNO>
</ROW>
<ROW>
<EMPNO>7839</EMPNO>
<ENAME>KING</ENAME>
<JOB>PRESIDENT</JOB>
<HIREDATE>1981-11-17</HIREDATE>
<SAL>5000</SAL>
<DEPTNO>10</DEPTNO>
</ROW>
<ROW>
<EMPNO>7844</EMPNO>
<ENAME>TURNER</ENAME>
<JOB>SALESMAN</JOB>
<MGR>7698</MGR>
<HIREDATE>1981-09-08</HIREDATE>
<SAL>1500</SAL>
<COMM>0</COMM>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7900</EMPNO>
<ENAME>JAMES</ENAME>
<JOB>CLERK</JOB>
<MGR>7698</MGR>
<HIREDATE>1981-12-03</HIREDATE>
<SAL>950</SAL>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7902</EMPNO>
<ENAME>FORD</ENAME>
<JOB>ANALYST</JOB>
<MGR>7566</MGR>
<HIREDATE>1981-12-03</HIREDATE>
<SAL>3000</SAL>
<DEPTNO>20</DEPTNO>
</ROW>
<ROW>
<EMPNO>7934</EMPNO>
<ENAME>MILLER</ENAME>
<JOB>CLERK</JOB>
<MGR>7782</MGR>
<HIREDATE>1982-01-23</HIREDATE>
<SAL>1300</SAL>
<DEPTNO>10</DEPTNO>
</ROW>
</ROWSET>
</ROOT>A couple of comments :
<li> I handle only four datatypes here (VARCHAR2, NUMBER, DATE, TIMESTAMP). Of course you can add more.
The list of Oracle Type Number is available here : http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements001.htm#i54330
Starting with 11g (not sure which release), DBMS_SQL package also declares these numbers through named constants.
<li> I don't use DBMS_XMLGEN in this example. Instead I rebuild the query using SQL/XML functions and the list of columns that's just been described. -
Possibility to show opening balance of a GL account through SQL query?
Hi experts,
Is it possible to run an SQL query in SBO that shows the opening balance
of a GL account based on a date entered by the user?
This is similar to how the general ledger shows the opening balance of a GL account based on the posting dates entered.
Thanks for your ideas.Hi Gordon,
Thanks for that idea.
I am thinking of the following:
1. Create a virtual table (#TEST) from a SELECT statement that gets all journal entries for the specified GL account BEFORE the specified posting date.
2. Perform a SELECT statement that sums the debit and credit from (#TEST).
This should show the opening balance of the GL account right?
Regards,
Eric
Edited by: eceguerra on May 18, 2011 7:02 AM
Edited by: eceguerra on May 18, 2011 7:02 AM -
SAP Crystal Report (2008) through SQL Query parameters
Hi,
I Created a report in Crystal report (2008) based on Sql Query. I created parameters in SQL query prompt only (all single valued).
Based on this I need to show the data in detail section.
For Graph, I used another SQL query, and added one subreport to the Main report header section. Since this subreport is also using the SQL query prompts for taking parameters.
Since both the reports are using same set of parameters. I mapped Main report parameters to sub-report parameters.
So Now structure is like,
In a report there is one subreport.
Main report ....SQL query generates parameter prompt..same parameters is passed to subreport.
In subreport there are sql generated prompts. and we mapped that prompts to main report parameter prompts.
Now it is running fine from crystal report, but not from CMC. It is not showing the graph.
Made Two Experiment:
1. To check subreport is running or not , Mannualy put my name in sub report--working fine.(CMC)
2. To check the parameters are correctly mapped--printed the value in subreport--Showing all the parameters value from CMC
but it is not running the SQL query of that sub report.
Any suggestion ?? Or is there anyoption to check?? Or a CMC setting.
Please suggest and respond..
Thank you in advance.!!Hi Rajeev,
This is Crystal reports development community, you said the report is working fine in Crystal. it is problem in CMC. So the issue is at BI Server.
So i think you need to create the thread in the below community.
BI Platform
--Naga -
How to measure the performance of sql query?
Hi Experts,
How to measure the performance, efficiency and cpu cost of a sql query?
What are all the measures available for an sql query?
How to identify i am writing optimal query?
I am using Oracle 9i...
It ll be useful for me to write efficient query....
Thanks & Regardspsram wrote:
Hi Experts,
How to measure the performance, efficiency and cpu cost of a sql query?
What are all the measures available for an sql query?
How to identify i am writing optimal query?
I am using Oracle 9i... You might want to start with a feature of SQL*Plus: The AUTOTRACE (TRACEONLY) option which executes your statement, fetches all records (if there is something to fetch) and shows you some basic statistics information, which include the number of logical I/Os performed, number of sorts etc.
This gives you an indication of the effectiveness of your statement, so that can check how many logical I/Os (and physical reads) had to be performed.
Note however that there are more things to consider, as you've already mentioned: The CPU bit is not included in these statistics, and the work performed by SQL workareas (e.g. by hash joins) is also credited only very limited (number of sorts), but e.g. it doesn't cover any writes to temporary segments due to sort or hash operations spilling to disk etc.
You can use the following approach to get a deeper understanding of the operations performed by each row source:
alter session set statistics_level=all;
alter session set timed_statistics = true;
select /* findme */ ... <your query here>
SELECT
SUBSTR(LPAD(' ',DEPTH - 1)||OPERATION||' '||OBJECT_NAME,1,40) OPERATION,
OBJECT_NAME,
CARDINALITY,
LAST_OUTPUT_ROWS,
LAST_CR_BUFFER_GETS,
LAST_DISK_READS,
LAST_DISK_WRITES,
FROM V$SQL_PLAN_STATISTICS_ALL P,
(SELECT *
FROM (SELECT *
FROM V$SQL
WHERE SQL_TEXT LIKE '%findme%'
AND SQL_TEXT NOT LIKE '%V$SQL%'
AND PARSING_USER_ID = SYS_CONTEXT('USERENV','CURRENT_USERID')
ORDER BY LAST_LOAD_TIME DESC)
WHERE ROWNUM < 2) S
WHERE S.HASH_VALUE = P.HASH_VALUE
AND S.CHILD_NUMBER = P.CHILD_NUMBER
ORDER BY ID
/Check the V$SQL_PLAN_STATISTICS_ALL view for more statistics available. In 10g there is a convenient function DBMS_XPLAN.DISPLAY_CURSOR which can show this information with a single call, but in 9i you need to do it yourself.
Note that "statistics_level=all" adds a significant overhead to the processing, so use with care and only when required:
http://jonathanlewis.wordpress.com/2007/11/25/gather_plan_statistics/
http://jonathanlewis.wordpress.com/2007/04/26/heisenberg/
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/ -
How can I use the Rownum/Customized SQL query in a Mapping?
Hi,
* I need to use a Rownum for populating one of the target field? How to create a mapping with Rownum?
* How can I use an Dual table in OWB mapping?
* Can I write Customized SQL query in OWB? How can I achieve this in a Mapping?
Thanks in Advance
KishanHi Niels,
As I'm sure you know, the conundrum is that Reports doesn't know how many total pages there will be in the report until it is all done formatting, which is too late for your needs. So, one classical solution to this problem is to run the report twice, storing the total number of pages in the database using a format trigger, and throwing away the output from the first run when you don't know the total number of pages.
Alternatively, you could define a report layout so that the number of pages in the output is completely predictable based upon, say, the number of rows in the main query. E.g., set a limit of one, two, ... rows per page, and then you'll know how many pages there will be simply because you can count the rows in a separate query.
Hope this helps...
regards,
Stewart -
Can we generate the output of SQL Query in XML format ..
Hi Team,
Can we generate an XML doc for an SQL Query.
I've seen in SQL Server 2000.It is generating the output of an SQL Query in xml format.
select * from emp for xml auto
The output looks like
<emp EMPNO="7369" ENAME="SMITH" JOB="CLERK" MGR="7902" HIREDATE="1980-12-17T00:00:00" SAL="2800" DEPTNO="20"/><emp EMPNO="7370" ENAME="SMITH" JOB="CLERK" MGR="7902" HIREDATE="1980-12-17T00:00:00" SAL="2800" DEPTNO="10"/>Just a little bit of short hand.
Get the XML out of your database, via HTTP
Of course the easiest method is just to return an XMLType from a stored procedure and let the calling routine figure out what to do with it. Instead
of that way though, I'll show you how to do it via HTTP. It's all completely built into 10g and is super easy to use.
CREATE OR REPLACE VIEW emps_and_depts AS
SELECT e.employee_id AS "EmployeeId",
e.last_name AS "Name",
e.job_id AS "Job",
e.manager_id AS "Manager",
e.hire_date AS "HireDate",
e.salary AS "Salary",
e.commission_pct AS "Commission",
XMLFOREST (
d.department_id AS "DeptNo",
d.department_name AS "DeptName",
d.location_id AS "Location"
) AS "Dept"
FROM employees e, departments d
WHERE e.department_id = d.department_id
Some people hear web and immediately start salivating about security issues. Let me address that quickly. Just because you have the HTTP and/or
FTP servers running in the database, that does not mean you have a security problem. For one, I would hope your databases are behind a firewall.
Second, with the correct architecture (DMZ, app servers, etc) you can make this data available outside the firewall fairly transparently and third,
just because it's on the web does not mean the data MUST be available on the internet. This is a good way to make your data available on your
intranet. If you are worried about people INSIDE your firewall, that still doesn't preclude web based access. Follow Oracle security guidelines.
Before I show you how to get to your data, let's talk about URLs and URIs. A URL is a Uniform Resource Locater and URI is a Uniform Resource
Identifier. A URL is the way you would identify a document on the net, i.e. http://www.oracle.com is a URL. A URI is a more generic form of a URL.
Oracle supports three types of URI: HTTPURIType - basically a URL (which would be like the URL above), XDURIType - a pointer to an XDB resource
(usually an XML document but can be other objects), and DBURIType - a pointer to database objects.
It's the DBURIType that we're going to concentrate on here. The DBURIType let's us reference database objects using a file/folder paradigm. The
format for a DBURI is /oradb/<schema>/<table>. Oradb is shorthand for the database; it is not the database name or SID. My database is named XE
but I still use oradb in the DBURI. For example, the view we created above is in my XE database, is owned by HR (at least in my case) and is called
EMPS_AND_DEPTS. This can be referenced as /oradb/HR/EMPS_AND_DEPTS.
If the view had many rows and you wanted only one of them, you can restrict it by including a predicate. The documentation for XDB has a great
write up on Using DBURIs.In our case, we are going to write out the entire document. Now that you understand that the DBURI is a pointer to
objects in our instance, we can use that to access the data as a URL.
The format for the URL call is http://<machinename>:<port>/<DBURI>
In my case, my XE database is running on a machine called mach1 and is listening on port 8080. So to see the view we created above, I open my
browser and navigate to: http//mach1:8080/oradb/HR/EMPS_AND_DEPTS
The created URL will be as http//mach1:8080/oradb/PUBLIC/EMPS_AND_DEPTS
If your database is set up correctly and listening on port 8080 (the default), your browser should ask you to login. Login as the user who created the
view (in my case HR). You should now get an XML document displayed in your browser.
And that's it. It doesn't get much simpler than that. If you get rid of the descriptive text above, it basically comes down to:
Create a table or view
Open your web browser
Enter a URL
Enter a user ID and password
View your XML
If you notice, Oracle formatted the data as XML for us. Our view returns scalar columns and an XML fragment called Dept. Oracle formatted the
return results into an XML format.
And as a side note, if you look closely, you'll see that my URL has PUBLIC where I said to put HR. PUBLIC is a synonym for all objects that your
logged in user can see. That way, if your user has been granted select access on many schemas, you can use PUBLIC and see any of them. -
Where is the oracle.xml.sql.query package?
Hi,
I have downloaded the xmlparser_v2_0_2_9.zip. I hoped I have everything to compile the example for retrieving XML document with an sql query. However, the jar file is missing the entire package oracle.xml.sql.query which contains for instance the crucial class OracleXMLQuery. Does anyone know where I could get this package - is it part of another download that I have to do, or can I buy it anywhere? Thanks for your help.
KarelIt's part of the XML SQL Utility for Java, avialable for download from http://technet.oracle.com/tech/xml
-
Bug with readonly view (through sql query)
HI , I'm using JDEV11.1.1.2
I found the following problem which I consider a bug:
When you create a readonly view object based on sql query the first attribute gets type: VARCHAR2(255) although it is VARCHAR2(10) in the database. All other attributes get the correct type and length only the first one is not correct.
Can you confirm this behavior to be a bug ?
Thanks
agruevHi,
of other string attributes show the correct length then this indeed sounds like a bug. However, a bug is a bug when it is getting filed.
Frank
Maybe you are looking for
-
ICloud won't setup properly on my iPhone 6, iPad Mini or iMac
Hi everyone, I've had an iMac and iPad for a while now and wasn't keen on setting up iCloud but this changed with my first iPhone which I got a few days ago. I opted to activate iCloud during the setup process thinking it'd be just as easy to do as e
-
JDBC connection to AS/400 in SQL0204 error
Hi, I'm trying to execute a statement on AS/400 from a JDBC receiver adapter. The statement looks like this: <ns0:MT_PriceCall_JDBC_Article_Request xmlns:ns0="urn:delixl:poc"> <Statement> <KT0100S action="EXECUTE"> <CUSTOMER type="VARCHAR
-
Does someone know information about Company name:TianMei Electronic Trade Co., Ltd Address:Anbao Building No.28 street, quanzhou , FUJian, China Pleas abswer is it legit or not? Does someone have got any experience with that company? Any information
-
Hi, I'd like to place Guest Accounts in a different "UserGroup" depending on the base country of the sponsor, which is meantion in the LDAP CN-String used to authenticate sponsors. Unfortunately, the ISE (1.2, Patch Level 5) only provides the operato
-
Set iphoto pictures as dektop pictures
Hi, I have pictures in my iphoto library but when I right click there is no set as dektop picture, how can I set a pictures in iphoto as dektop picture, can ypu help, thanks.