SQL Select and From Functions
Can sql aggregate functions be added to an interface select clause and from clause.
I want to have a datasource where one of the columns is an aggregate such as a count, which would need the ability to indicate a from clause function group by, or having by. In the Designer Diagram tab for the interface, it seems you can only apply sql functions to where clause joins or filters.
I want to have a query such as follows as my datasource
select columnA, count(*) as thecount
from table x
group by columnA
order by thecount asc
and ultimately
select columnA, thecount
from (select columnA, count(*) as thecount
from table x
group by columnA
order by thecount asc)
where rownum <1001
Can this be done in the ODI Designer, without creating a physical custom view on the database?
Hi lpantuso,
Aggregate functions are added by ODI automatically. In this case you would want mappings like this:
TARGET_COL_1: columnA
TARGET_COL_2: count(*)
ODI will generate something like this:
select
columnA,
count(*)
from MY_TABLE MY_TABLE
where
(1=1)
Group By MY_TABLE.columnA
The subselect, however, isn't handled out of the box. In general ODI isn't quite as friendly with ordering clauses since order by is not relational. (Sets aren't ordered.) To get only the first 1000 columnA values, you'll probably need to create a view or break it into 2 separate interfaces.
Regards,
Matt
Similar Messages
-
Blocking Session - blocked SQL - SELECT SYSDATE FROM SYS.DUAL
Oracle 10.0.0.4g
When database execute some big and long queries/operations my system is slow and some users wait, can’t work (they work with some Oracle forms applications ) because I often have blocking session.
I found up that this blocking sessions block only this query of another user:
SELECT SYSDATE FROM SYS.DUAL
Or:
+10-АВГ-2009 08:51:10 User X1 ( SID= 222 ) with the statement: SELECT ... is blocking the SQL statement on Y1 ( SID=333 ) blocked SQL -> SELECT SYSDATE FROM SYS.DUAL+
When I kill one of the blocking session another session take his place and do the same:
+10-АВГ-2009 08:53:10 User X2 ( SID= 444 ) with the statement: SELECT ... is blocking the SQL statement on Y2 ( SID=555 ) blocked SQL -> SELECT SYSDATE FROM SYS.DUAL+
When long queries finished everything is OK.
Please Help Me!!!I create ASH report:_
Top User Events
Avg Active
Event Event Class % Activity Sessions
enq: TM - contention Application 55.87 0.96
db file sequential read User I/O 18.87 0.32
CPU + Wait for CPU CPU 16.33 0.28
db file scattered read User I/O 3.02 0.05
Top Event P1/P2/P3 Values
Event % Event P1 Value, P2 Value, P3 Value % Activity
Parameter 1 Parameter 2 Parameter 3
enq: TM - contention 55.87 "xxxxxxxxxxxxxxxxxxxx" 38.35
name|mode object # table/partition
"1111111111","xxxxxxx","0" 17.44
db file sequential read 19.21 "xxxxxxxxxxxxxxx’’ 0.00
file# block# blocks
db file scattered read 3.03 "xxxxxxxxxxxxxxxxxxxxxx’’ 0.01
file# block# blocks
Top SQL Statements …………..
SQL ID Planhash % Activity Event % Event
fnxxxxxxxxx N/A 25.09 enq: TM - contention 23.47
** SQL Text Not Available **
N/A 25.09 db file sequential read 1.19
** SQL Text Not Available **
byxxxxxxxxxxxxx 1111111 10.11 enq: TM - contention 7.43
SELECT SYSDATE FROM SYS.DUAL
db file sequential read 2.10
fnxxxxxxxxx 11111111111 2.57 enq: TM - contention 2.16
** SQL Text Not Available **
Top DB Objects
Object ID % Activity Event % Event
Object Name (Type) Tablespace
11111 10.33 enq: TM - contention 10.30
XXXXXXXXXXXXXXXXXXXXXXXX (INDEX) CC
99999 10.18 enq: TM - contention 10.16
XXXXXXXXXXXXXXXXXXXXXXXXX (INDEX) IND
933333 6.67 enq: TM - contention 6.55
FFFFFFFFFFFFFFFF (TABLE) T3
114545 3.88 enq: TM - contention 3.85
RRRRRRRRRRRRRRRRRRRRRR (INDEX) JJJ
1136664 2.96 enq: TM - contention 2.93
FFFFFFFFFFFFFFFFFFFFFFFFF (INDEX) G
How to found sql text that is not available ** SQL Text Not Available **?
What to do whit this Top DB Objects that have enq: TM - contention event?
And how to solve this problem? -
Why select data from Function directly (SE37) got data , but when use funct
why select data from Function directly (SE37) got data , but when use function in program donot found data
i use function
CS_BOM_EXPL_MAT_V2
when i run function directly at SE37 .
i found data.
but when i use same function in program .
system not found.
please see my attachment.
help me please.
[http://www.quickfilepost.com/download.do?get=c974356a498b3a4d369aa0c50622e50b]
http://www.quickfilepost.com/download.do?get=c974356a498b3a4d369aa0c50622e50bI know why U get empty data.
In Program U should follow the rules:
U'd better data a variant typed the function parameters's type.
for example:
in your program the parameter: stlal = '1'
U'd better like follow:
Data l_stlal type STKO-STLAL
l_stlal = '01'. *Attention: '1' <> '01'.
stlal = l_stlal.
in this way U may have less mistake
and the parameter MTNRV
U should use material convernt : "CONVERSION_EXIT_MATN1_INPUT" to change material into internal types before U put into function's parameter.
why se37 has no problem? because In se37, the data you filled was be processed before use -
PL/SQL select list from query
Hello,
I am trying to modifying a PL/SQL process. Wherever there was a reference to the Application ID, I wanted to change it to refer to the Application Alias.
Here is the original code:
declare
cursor app_cur is
select aa.application_id||' - '||aa.application_name app_name,
aa.application_id
from apex_applications aa
where exists (select 1
from profiles p
where p.application_id = aa.application_id);
cursor user_app_cur (p_user number, p_app number) is
select to_char(profile_id)
from user_app_profiles
where user_id = p_user
and application_id = p_app;
v_profile varchar2(10);
v_count number := 0;
v_class varchar2(15);
begin
htp.p('<table class="t3standardalternatingrowcolors" cellpadding="0" cellspacing="0">');
htp.p('<tr><th class="t3header" >Application</th><th class="t3header" >Profile</th></tr>');
for app in app_cur loop
v_count := v_count + 1;
if mod(v_count,2) = 1 then
v_class := 't3dataalt';
else
v_class := 't3data';
end if;
open user_app_cur(:P3_USER_ID, app.application_id);
fetch user_app_cur
into v_profile;
if user_app_cur%notfound then
v_profile := 'NONE';
end if;
close user_app_cur;
htp.p('<tr><td class="'||v_class||'">'||app.app_name||
'</td><td class="'||v_class||'">'||
apex_item.select_list_from_query(40, v_profile,
'select description, profile_id from profiles where application_id = '||app.application_id,
null, 'YES', 'NONE', 'No Profile Assigned', null, null, 'NO')||
apex_item.hidden(41,app.application_id) ||
'</td></tr>');
end loop;
htp.p('</table>');
end;Here is my revised code:
declare
cursor app_cur is
select aa.alias||' - '||aa.application_name app_name,
aa.alias
from apex_applications aa
where exists (select 1
from profiles p
where p.application_alias = aa.alias);
cursor user_app_cur (p_user number, p_app varchar2) is
select to_char(profile_id)
from user_app_profiles
where user_id = p_user
and application_alias = p_app;
v_profile varchar2(10);
v_count number := 0;
v_class varchar2(15);
begin
htp.p('<table class="t3standardalternatingrowcolors" cellpadding="0" cellspacing="0">');
htp.p('<tr><th class="t3header" >Application</th><th class="t3header" >Profile</th></tr>');
for app in app_cur loop
v_count := v_count + 1;
if mod(v_count,2) = 1 then
v_class := 't3dataalt';
else
v_class := 't3data';
end if;
open user_app_cur(:P3_USER_ID, app.alias);
fetch user_app_cur
into v_profile;
if user_app_cur%notfound then
v_profile := 'NONE';
end if;
close user_app_cur;
htp.p('<tr><td class="'||v_class||'">'||app.app_name||
'</td><td class="'||v_class||'">'||
apex_item.select_list_from_query(40, v_profile,
'select description, profile_id from profiles where application_alias = '||app.alias,
null, 'YES', 'NONE', 'No Profile Assigned', null, null, 'NO')||
apex_item.hidden(41,app.alias) ||
'</td></tr>');
end loop;
htp.p('</table>');
end;Here is the error:
ORA-06550: line 1, column 153: PL/SQL: ORA-00904: "F109NEWNAME": invalid identifier ORA-06550: line 1, column 7: PL/SQL: SQL Statement ignored
I think that the problem is in the table/LOV generation near the end, but I don't fully understand the apex_item.select_list_from_query function as it is written (I didn't write it).
Any help is greatly appreciated.
Thanks,
MattHi Matt,
This line:
'select description, profile_id from profiles where application_alias = '||app.aliaswould become:
select description, profile_id from profiles where application_alias = F109NEWNAMEif F109NEWNAME was the app_alias. SQL would see F109NEWNAME as a variable as it is not in quotes. Therefore, you should change the line to:
'select description, profile_id from profiles where application_alias = ''' || app.alias || ''''to end up with:
select description, profile_id from profiles where application_alias = 'F109NEWNAME'which would make more sense
Andy -
In a table I have a field "Ticket No.". I am using Ticket No in a format like:
00021-10-06-0201
The first set (left side) represents Ticket No. Then month, year, and code.
Each time when a user wants to enter new record a new ID is generated as:
"Select max(Left(TicketID,5)) from Ticket".
The new id becomes result+1.
I want to know that the above field is a string. But when I use LEFT
function, as above, it successfully returns max of the first set. Does
it automatically converts it to Long integer?
If not, how to use it securely so that first the left set is converted
to Long Integer and then the MAX is found. All in SQL query.I want to know whether your "substr(00021...)
approach and in my example, does max function
automatically converts it to a numeric type.I did not use MAX in my example, but still it is converting to numeric depending on the operator you are using. Elaborating....see below..
SQL> select substr('00021-10-06-0021',1,5)+1 from dual;
SUBSTR('00021-10-06-0021',1,5)+1
22
SQL> select substr('A0021-10-06-0021',1,5)+1 from dual;
select substr('A0021-10-06-0021',1,5)+1 from dual
ERROR at line 1:
ORA-01722: invalid number
SQL> select substr('A0021-10-06-0021',1,5)||'A' from dual;
SUBSTR
A0021ASee the above 1st and 3rd query, the behaviour is completely based on the operators. -
SQL*Loader and DECODE function
Hi All,
I am loading data from data files into oracle tables and while loading the data using SQL*Loader, the following requirement needs to be fulfilled.
1) If OQPR < 300, RB = $ 0-299, SC = "SC1"
2) If 300 < OQPR < 1200, RB = $ 300-1199, SC = "SC2"
3) If 1200 < OQPR < 3000, RB = $ 1200-2999, SC = "SC3"
4) If OQPR > 3000 USD, RB = > $3000, SC = "SC4"
Here OPQR is a field in the data file.
Can anyone suggest how do we handle this using DECODE function? Triggers and PL/SQL functions are not to be used.
TIA.
Regards,
Ravi.The following expression gives you different values for your different intervals and boundaries :
SIGN(:OQPR - 300) + SIGN(:OQPR - 1200) + SIGN(:OQPR - 3000) -
I have a simple SELECT statement in a Stored Proc that
queries 2 tables in
SQL Server 2000 using a join. My problem is I want to return
values based on
the outcome of the query eg. if a row is returned then return
1, or return 2
if no rows are found. I have tried various ways to implement
this and they
always work fine in Query Analyser but in Dreamweaver MX2004
either return
no return values ( or at least they are not displayed on my
page ) or the
return values are inconsistent. I am using a DW Command.
I know this is DW and not my code as Query Analyser produces
the correct
values every time. Can anyone tell me what code I can use
that is DW
friendly please.
Thanks.I read your note with a great degree of sympathy but no
solutions. I was having the same trouble with access tables after 4
years of trouble free connections. It may not be relevant but the
solutions for my problem was a Server software SP release. Details
are:
Following the avalanche of hints and tips I am pleased to
report that there is a problem with Dreamweaver MX and MX2004 when
connecting to Access databases running on Windows Server 2003 SP1.
Whilst it is covered in the knowledge base I note that others in
the forum are having similar difficulties with Sequel connections
and unable to retrieve failures.
There is a "fix" - SP2DBFix1.0.2.mxp - for my problem and I
cannot be alone in experiencing this.
And just in case anyone from Adobe is reading this, you
should have written to all your registered and paid up members
informing us of this problem when WS2003 SP1 was released!
Hope this helps. -
Hello,
i have the following SQL-Statement:
SELECT /*+ PARALLEL(mytable,16*/ COUNT(*)
FROM mytable;
Does the database use ALWAYS 16 cores (of course, if 16 cores are free) - even if the cbo (cost based optimizer ) "thinks" that this makes no sense? Or CAN the cbo use 16 cores with this sql-statement? Or if the cbo "thinks" the server has more cores as in the hint-stament, the cbo gives more cores.
Many thanks
Best regards
HeidiHeidi Weber wrote:
Hello,
i have the following SQL-Statement:
SELECT /*+ PARALLEL(mytable,16*/ COUNT(*)
FROM mytable;
Does the database use ALWAYS 16 cores (of course, if 16 cores are free) - even if the cbo (cost based optimizer ) "thinks" that this makes no sense? Or CAN the cbo use 16 cores with this sql-statement? Or if the cbo "thinks" the server has more cores as in the hint-stament, the cbo gives more cores.
Many thanks
Best regards
HeidiYour query is missing a bracket from the hint. ;)
Looking at it one way, if I were to hint to you that it's a good idea to go jump off a cliff, would you do it? Answer: You'd look to see what the possibility of surviving is and if the chances were 100% survival (and you didn't have a fear of heights) you'd do it.
Likewise Oracle will look at a hint and if it's not going to break the query or conflict with something else that is required, it will do it, but if for some reason it can't then it won't. So if you don't have 16 cores and you're telling it to use 16, then it won't do it. There are obviously various internal rules and formula that the CBO uses when determining the best execution plan, so the hint has to be looked at in the context of the whole query. In the simple example you've given, there's no reason why it shouldn't comply with the hint. -
Mutilple File Selection and Upload Functionality in Sharepoint 2010
Hi,
I have a requirement that i have to create an Application page where i should have the following functionality.
Should be able to select multiple files at a single shot.
That is when i click on Browse and choose files i should be able to choose more than one file and then i have to upload all the files to Sharepoint document library.
I know how to upload mutiple files to library , but am unaware how to select mutiple files with single browse.
By using Fileupload control we can select only one file at a time. ( We have to use more Fileupload control and get more files , but have to select the files one by one only )
Is there any control or any workaround to achieve this.
Main thing is to select Multiple files at a single go.
Thanks in Advance.
Regards,
SivaKumar.Hi,
The following links for your reference:
<asp:FileUpload AllowMultiple="True"...>
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.aspx
jQuery File Upload pulgins
http://plugins.jquery.com/?s=upload+file
Best Regards
Guangchao chen
TechNet Community Support -
IF I config odbc dsn_ggExtdb , when exect this command:
DBLOGIN sourcedb dsn_ggExtdb USERID sa,PASSWORD 123456
error :Unrecognized parameter (SOURCEDB), expected USERID.
help me!Please ensure that you have downloaded the OGG software for SQLserver
OS >ggsci -v
Oracle GoldenGate Command Interpreter for Oracle <------- here is the problem it should reflect the DB environment that you would like to connect to in this case MS SQLServer
Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230
Windows x64 (optimized), Oracle 11g on Apr 23 2012 04:55:02
if the DB is not showing as Sqlserver , please download the correct patch form the Oracle Site and try. -
Select and function with no_data_found
Hi,
I came across this today (I remembered reading about it somewhere).
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> create function rahul_f return varchar2 as
2 begin
3 raise no_data_found;
4 end rahul_f;
5 /
Function created.
SQL> select rahul_f from dual;
RAHUL_F
SQL> declare
2 i varchar2(1);
3 begin
4 i := rahul_f;
5 end;
6 /
declare
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at "XX.RAHUL_F", line 3
ORA-06512: at line 4
SQL>
So, I know this has something to do with 'no_data_found' mentioned here:
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/errors.htm#LNPLS00703
'Because this exception is used internally by some SQL functions to signal completion, you should not rely on this exception being propagated if you raise it within a function that is called as part of a query.'
Anybody have any link on explaining this part more? I looked around but, couldn't find any discussions on this.I had same experience few days back.
First I dont think you need the funtion to call the exception.
You can directly implement your code in the EXCEPTION block, if theres a no_data_found excpetion.
This is my code..
PROCEDURE modify_req_det(
detail_id_in IN req_details.detail_id%TYPE,
type_id_in IN req_details.req_type_id%TYPE,
value_in IN VARCHAR2,
parent_in IN req_details.parent%TYPE,
sortorder_in IN req_details.sort_order%TYPE,
groupid_in IN req_details.group_id%TYPE,
errormsg OUT NOCOPY VARCHAR2) AS
BEGIN
SELECT DISTINCT lookup, col_name
INTO v_lookup, v_colname
FROM req_type t, req_details d
WHERE parent = parent_in
AND t.req_type_id = d.req_type_id;
EXCEPTION
WHEN no_data_found THEN
UPDATE req_details SET
req_type_id = type_id_in,
value_id = v_valueId,
parent = parent_in,
sort_order = sortorder_in,
group_id = groupid_in
WHERE detail_id = detail_id_in;
END modify_req_det; -
Output of value returned from function in SELECT statement ??
Hi
I have created the below function
create or replace
FUNCTION jc_test
RETURN VARCHAR2
IS myrec VARCHAR2(270);
BEGIN
SELECT RPAD('*',270,'*')
INTO myrec
FROM DUAL ;
RETURN myrec;
END ;
and I executed the SELECT statement in Oracle SQL developer as a script
select
LENGTH(jc_test()) len
*,jc_test() rec*
from dual ;
I get exact output as below
LEN REC
270 ******************************************************************************************************************************************************************************************************************************************************************************
So here LEN is correctly shown as 270 characters but when I see the astrisk's (also appended with spaces ) its total length is 4000 characters
Can anyone give their thoughts on this.
Its fine if I run as normal, i mean not as a script.
Regards
jc
Edited by: JC on Jun 16, 2011 11:25 AMHi,
So here LEN is correctly shown as 270 charactersYes, correct
but when I see the astrisk's (also appended with spaces ) its total length is 4000 charactersNo buts. It is not padded. That is just how it is displayed by your tool. In SQL*Plus this is controlled by LINESIZE and COLUMN
SQL> create or replace function dummy return varchar2 as begin return null; end;
2 /
Function created.
SQL> select dummy from dual;
D
X
SQL> select dummy() from dual;
DUMMY()
SQL> col "dummy()" for a10
SQL> select dummy() from dual;
DUMMY()
SQL>P.S: It is a really bad idea to create your own wrapper functions, built-in functions. Hopefully you are not really doing that?
Regards
Peter -
Functions for mapping Latin-1 character codes to and from WinLatin-1 character codes
HI ALL
I will like to know how could i write own functions for mapping Latin-1 character codes to and from WinLatin-1
character codes.
Can show me some source code or how to mapping it. Because i just begineer.
Hope you able to help me..I see your issue. I tried to reproduce this issue using sqlplus.
Setup NLS_LANG as you mentioned using WE8ISO8859P1 and connect to a UTF8 db.
[oracle@server ~]$ locale -a | grep en_US
en_US
en_US.iso88591
en_US.iso885915
en_US.utf8
[oracle@server ~]$ export LC_ALL=en_US.iso88591
[oracle@server ~]$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.iso88591"
LC_NUMERIC="en_US.iso88591"
LC_TIME="en_US.iso88591"
LC_MEASUREMENT="en_US.iso88591"
LC_IDENTIFICATION="en_US.iso88591"
LC_ALL=en_US.iso88591
[oracle@server ~]$ echo $NLS_LANG
AMERICAN_AMERICA.WE8ISO8859P1
SQL> select value from nls_database_parameters where parameter='NLS_CHARACTERSET';
AL32UTF8
SQL> select nchr(223) from dual;
NCHR
ß
SQL> select chr(223) from dual;
ERROR:
ORA-29275: partial multibyte character
SQL> SELECT CHR (223 USING NCHAR_CS) from dual;
C
ß
SQL> select CONVERT('ß', 'WE8ISO8859P1','UTF8') FROM DUAL;
CO
SQL> select CONVERT(CHR(223 USING NCHAR_CS), 'WE8ISO8859P1','UTF8') FROM DUAL;
select CONVERT(CHR (223 USING NCHAR_CS), 'WE8ISO8859P1','UTF8') FROM DUAL
ERROR at line 1:
ORA-12703: this character set conversion is not supportedI found that beta is in WE8ISO8859P1 character set
here[url http://docs.oracle.com/cd/E11882_01/server.112/e10729/ch2charset.htm#NLSPG164]What Characters Does a Character Set Support?
But I don't really understand whats the problem in the conversion. -
Inconsistent SQL results when using View with UNION-ALL and table function
Can any of you please execute the below scripts and check the output. In the table type variable, I am adding 4 distinct object ids, where as in the result, I get only the row pertaining to last id in the table type variable. Same row is returned 4 times (4= number of values in the table type).
This scenario is occurring in our product with a SQL with exactly same pattern. I could simulate the same issue with the sample script I have provided.
Database version: 11.2.0.3 Enterprise Edition, Single node
Thank you.
CREATE TABLE TEMP_T1 AS SELECT * FROM ALL_OBJECTS;
CREATE TABLE TEMP_T2 AS SELECT * FROM ALL_OBJECTS;
UPDATE TEMP_T2 SET OBJECT_ID = OBJECT_ID * 37;
CREATE UNIQUE INDEX TEMP_T1_U1 ON TEMP_T1(OBJECT_ID);
CREATE UNIQUE INDEX TEMP_T2_U1 ON TEMP_T2(OBJECT_ID);
CREATE OR REPLACE VIEW TEMP_T1T2_V AS
SELECT * FROM TEMP_T1 UNION ALL SELECT * FROM TEMP_T2;
CREATE OR REPLACE TYPE TEMP_OBJ_TYPE AS OBJECT (OBJ_ID NUMBER);
CREATE OR REPLACE TYPE TEMP_OBJ_TAB_TYPE IS TABLE OF TEMP_OBJ_TYPE;
SET SERVEROUTPUT ON;
DECLARE
TYPE TEMP_T1T2_V_ROW_TAB_TYPE IS TABLE OF TEMP_T1T2_V%ROWTYPE;
TEMP_T1T2_V_ROW_TAB TEMP_T1T2_V_ROW_TAB_TYPE;
TEMP_OBJ_TAB TEMP_OBJ_TAB_TYPE := TEMP_OBJ_TAB_TYPE();
PROCEDURE ADD_TO_TEMP_OBJ_TAB(OBJ_ID IN NUMBER) IS
BEGIN
TEMP_OBJ_TAB.EXTEND;
TEMP_OBJ_TAB(TEMP_OBJ_TAB.LAST) := TEMP_OBJ_TYPE(OBJ_ID);
END;
BEGIN
ADD_TO_TEMP_OBJ_TAB(100);
ADD_TO_TEMP_OBJ_TAB(116);
ADD_TO_TEMP_OBJ_TAB(279);
ADD_TO_TEMP_OBJ_TAB(364);
DBMS_OUTPUT.PUT_LINE('=====================');
FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
LOOP
DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
END LOOP;
DBMS_OUTPUT.PUT_LINE('---------------------');
SELECT * BULK COLLECT INTO TEMP_T1T2_V_ROW_TAB
FROM TEMP_T1T2_V VW
WHERE ((VW.OBJECT_ID) IN (SELECT OBJ_ID
FROM TABLE(CAST(TEMP_OBJ_TAB AS TEMP_OBJ_TAB_TYPE))));
FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
LOOP
DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
END LOOP;
DBMS_OUTPUT.PUT_LINE('---------------------');
IF TEMP_T1T2_V_ROW_TAB.COUNT > 0 THEN
FOR I IN TEMP_T1T2_V_ROW_TAB.FIRST..TEMP_T1T2_V_ROW_TAB.LAST
LOOP
DBMS_OUTPUT.PUT_LINE(TEMP_T1T2_V_ROW_TAB(I).OBJECT_ID||' : '||TEMP_T1T2_V_ROW_TAB(I).OBJECT_NAME);
END LOOP;
ELSE
DBMS_OUTPUT.PUT_LINE('NO ROWS RETURNED!');
END IF;
DBMS_OUTPUT.PUT_LINE('---------------------');
END;
/I can reproduce it:
SQL*Plus: Release 11.2.0.3.0 Production on Tue Oct 30 14:05:39 2012
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Enter user-name: scott
Enter password:
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select *
2 from v$version
3 /
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for 64-bit Windows: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
SQL> CREATE TABLE TEMP_T1 AS SELECT * FROM ALL_OBJECTS;
Table created.
SQL>
SQL> CREATE TABLE TEMP_T2 AS SELECT * FROM ALL_OBJECTS;
Table created.
SQL>
SQL> UPDATE TEMP_T2 SET OBJECT_ID = OBJECT_ID * 37;
72883 rows updated.
SQL>
SQL> CREATE UNIQUE INDEX TEMP_T1_U1 ON TEMP_T1(OBJECT_ID);
Index created.
SQL>
SQL> CREATE UNIQUE INDEX TEMP_T2_U1 ON TEMP_T2(OBJECT_ID);
Index created.
SQL>
SQL> CREATE OR REPLACE VIEW TEMP_T1T2_V AS
2 SELECT * FROM TEMP_T1 UNION ALL SELECT * FROM TEMP_T2;
View created.
SQL>
SQL> CREATE OR REPLACE TYPE TEMP_OBJ_TYPE AS OBJECT (OBJ_ID NUMBER)
2 /
Type created.
SQL> CREATE OR REPLACE TYPE TEMP_OBJ_TAB_TYPE IS TABLE OF TEMP_OBJ_TYPE
2 /
Type created.
SQL> SET SERVEROUTPUT ON;
SQL>
SQL> DECLARE
2 TYPE TEMP_T1T2_V_ROW_TAB_TYPE IS TABLE OF TEMP_T1T2_V%ROWTYPE;
3 TEMP_T1T2_V_ROW_TAB TEMP_T1T2_V_ROW_TAB_TYPE;
4 TEMP_OBJ_TAB TEMP_OBJ_TAB_TYPE := TEMP_OBJ_TAB_TYPE();
5 PROCEDURE ADD_TO_TEMP_OBJ_TAB(OBJ_ID IN NUMBER) IS
6 BEGIN
7 TEMP_OBJ_TAB.EXTEND;
8 TEMP_OBJ_TAB(TEMP_OBJ_TAB.LAST) := TEMP_OBJ_TYPE(OBJ_ID);
9 END;
10 BEGIN
11 ADD_TO_TEMP_OBJ_TAB(100);
12 ADD_TO_TEMP_OBJ_TAB(116);
13 ADD_TO_TEMP_OBJ_TAB(279);
14 ADD_TO_TEMP_OBJ_TAB(364);
15 DBMS_OUTPUT.PUT_LINE('=====================');
16 FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
17 LOOP
18 DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
19 END LOOP;
20 DBMS_OUTPUT.PUT_LINE('---------------------');
21 SELECT * BULK COLLECT INTO TEMP_T1T2_V_ROW_TAB
22 FROM TEMP_T1T2_V VW
23 WHERE ((VW.OBJECT_ID) IN (SELECT OBJ_ID
24 FROM TABLE(CAST(TEMP_OBJ_TAB AS TEMP_OBJ_TAB_TYPE))));
25 FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
26 LOOP
27 DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
28 END LOOP;
29 DBMS_OUTPUT.PUT_LINE('---------------------');
30 IF TEMP_T1T2_V_ROW_TAB.COUNT > 0 THEN
31 FOR I IN TEMP_T1T2_V_ROW_TAB.FIRST..TEMP_T1T2_V_ROW_TAB.LAST
32 LOOP
33 DBMS_OUTPUT.PUT_LINE(TEMP_T1T2_V_ROW_TAB(I).OBJECT_ID||' : '||TEMP_T1T2_V_ROW_TAB(I).OBJECT_NAME);
34 END LOOP;
35 ELSE
36 DBMS_OUTPUT.PUT_LINE('NO ROWS RETURNED!');
37 END IF;
38 DBMS_OUTPUT.PUT_LINE('---------------------');
39 END;
40 /
=====================
OBJ_ID = 100
OBJ_ID = 116
OBJ_ID = 279
OBJ_ID = 364
OBJ_ID = 100
OBJ_ID = 116
OBJ_ID = 279
OBJ_ID = 364
364 : I_AUDIT
364 : I_AUDIT
364 : I_AUDIT
364 : I_AUDIT
PL/SQL procedure successfully completed.
SQL> column object_name format a30
SQL> select object_id,
2 object_name
3 from dba_objects
4 where object_id in (100,116,279,364)
5 /
OBJECT_ID OBJECT_NAME
100 ORA$BASE
116 DUAL
279 MAP_OBJECT
364 I_AUDIT
SQL> Works fine in:
=====================
OBJ_ID = 100
OBJ_ID = 116
OBJ_ID = 279
OBJ_ID = 364
OBJ_ID = 100
OBJ_ID = 116
OBJ_ID = 279
OBJ_ID = 364
100 : ORA$BASE
116 : DUAL
364 : SYSTEM_PRIVILEGE_MAP
279 : MAP_OBJECT
PL/SQL procedure successfully completed.
SQL> select object_id,
2 object_name
3 from dba_objects
4 where object_id in (100,116,279,364)
5 /
OBJECT_ID OBJECT_NAME
100 ORA$BASE
116 DUAL
364 SYSTEM_PRIVILEGE_MAP
279 MAP_OBJECT
SQL> select *
2 from v$version
3 /
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL>SY.
Edited by: Solomon Yakobson on Oct 30, 2012 2:14 PM -
Performance problem in select data from data base
hello all,
could you please suggest me which select statement is good for fetch data form data base if data base contain more than 10 lac records.
i am using SELECT PACKAGE SIZE n statement, but it's taking lot of time .
with best regards
srinivas rathodHi Srinivas,
if you have huge data and selecting ,you could decrease little bit time if you use better techniques.
I do not think SELECT PACKAGE SIZE will give good performance
see the below examples :
ABAP Code Samples for Simple Performance Tuning Techniques
1. Query including select and sorting functionality
tables: mara, mast.
data: begin of itab_new occurs 0,
matnr like mara-matnr,
ernam like mara-ernam,
mtart like mara-mtart,
matkl like mara-matkl,
werks like mast-werks,
aenam like mast-aenam,
stlal like mast-stlal,
end of itab_new.
select fmatnr fernam fmtart fmatkl gwerks gaenam g~stlal
into table itab_new from mara as f inner join mast as g on
fmatnr = gmatnr where gstlal = '01' order by fernam.
Code B
tables: mara, mast.
data: begin of itab_new occurs 0,
matnr like mara-matnr,
ernam like mara-ernam,
mtart like mara-mtart,
matkl like mara-matkl,
werks like mast-werks,
aenam like mast-aenam,
stlal like mast-stlal,
end of itab_new.
select fmatnr fernam fmtart fmatkl gwerks gaenam g~stlal
into table itab_new from mara as f inner join mast as g on f~matnr =
gmatnr where gstlal = '01'.
sort itab_new by ernam.
Both the above codes essentially do the same function, but the execution time for code B is considerably lesser than that of Code A. Reason: The Order by clause associated with a select statement increases the execution time of the statement, so it is profitable to sort the internal table once after selecting the data.
2. Performance Improvement Due to Identical Statements Execution Plan
Consider the below queries and their levels of efficiencies is saving the execution
tables: mara, mast.
data: begin of itab_new occurs 0,
matnr like mara-matnr,
ernam like mara-ernam,
mtart like mara-mtart,
matkl like mara-matkl,
werks like mast-werks,
aenam like mast-aenam,
stlal like mast-stlal,
end of itab_new.
select fmatnr fernam fmtart fmatkl gwerks gaenam g~stlal
into table itab_new from mara as f inner join mast as g on f~matnr =
gmatnr where gstlal = '01' .
sort itab_new.
select fmatnr fernam
fmtart fmatkl gwerks gaenam g~stlal
into table itab_new from mara as
f inner join mast as g on f~matnr =
gmatnr where gstlal
= '01' .
Code D (Identical Select Statements)
tables: mara, mast.
data: begin of itab_new occurs 0,
matnr like mara-matnr,
ernam like mara-ernam,
mtart like mara-mtart,
matkl like mara-matkl,
werks like mast-werks,
aenam like mast-aenam,
stlal like mast-stlal,
end of itab_new.
select fmatnr fernam fmtart fmatkl gwerks gaenam g~stlal
into table itab_new from mara as f inner join mast as g on f~matnr =
gmatnr where gstlal = '01' .
sort itab_new.
select fmatnr fernam fmtart fmatkl gwerks gaenam g~stlal
into table itab_new from mara as f inner join mast as g on f~matnr =
gmatnr where gstlal = '01' .
Both the above codes essentially do the same function, but the execution time for code B is considerably lesser than that of Code A. Reason: Each SQL statement during the process of execution is converted into a series of database operation phases. In the second phase of conversion (Prepare phase) an execution plan is determined for the current SQL statement and it is stored, if in the program any identical select statement is used, then the same execution plan is reused to save time. So retain the structure of the select statement as the same when it is used more than once in the program.
3. Reducing Parse Time Using Aliasing
A statement which does not have a cached execution plan should be parsed before execution; this parsing phase is a highly time and resource consuming, so parsing time for any sql query must include an alias name in it for the following reason.
1. Providing the alias name will enable the query engine to resolve the tables to which the specified fields belong to.
2. Providing a short alias name, (a single character alias name) is more efficient that providing a big alias name.
Code E
select jmatnr jernam jmtart jmatkl
gwerks gaenam g~stlal into table itab_new from mara as
j inner join mast as g on jmatnr = gmatnr where
g~stlal = '01' .
In the above code the alias name used is j .
4. Performance Tuning Using Order by Clause
If in a SQL query you are going to read a particular database record based on some key values mentioned in the select statement, then the read query can be very well optimized by ordering the fields in the same order in which we are going to read them in the read query.
Code F
tables: mara, mast.
data: begin of itab_new occurs 0,
matnr like mara-matnr,
ernam like mara-ernam,
mtart like mara-mtart,
matkl like mara-matkl,
end of itab_new.
select MATNR ERNAM MTART MATKL from mara into table itab_new where
MTART = 'HAWA' ORDER BY MATNR ERNAM MTART MATKL.
read table itab_new with key MATNR = 'PAINT1' ERNAM = 'RAMANUM'
MTART = 'HAWA' MATKL = 'OFFICE'.
Code G
tables: mara, mast.
data: begin of itab_new occurs 0,
matnr like mara-matnr,
ernam like mara-ernam,
mtart like mara-mtart,
matkl like mara-matkl,
end of itab_new.
select MATNR ERNAM MTART MATKL from mara into table itab_new where
MTART = 'HAWA' ORDER BY ERNAM MATKL MATNR MTART.
read table itab_new with key MATNR = 'PAINT1' ERNAM = 'RAMANUM'
MTART = 'HAWA' MATKL = 'OFFICE'.
In the above code F, the read statement following the select statement is having the order of the keys as MATNR, ERNAM, MTART, MATKL. So it is less time intensive if the internal table is ordered in the same order as that of the keys in the read statement.
5. Performance Tuning Using Binary Search
A very simple but useful method of fine tuning performance of a read statement is using Binary search addition to it. If the internal table consists of more than 20 entries then the traditional linear search method proves to be more time intensive.
Code H
select * from mara into corresponding fields of table intab.
sort intab.
read table intab with key matnr = '11530' binary search.
Code I
select * from mara into corresponding fields of table intab.
sort intab.
read table intab with key matnr = '11530'.
Thanks
Seshu
Maybe you are looking for
-
How do i transfer funds from one account to another in the same table?
Say for example i want to transfer funds from UserID 1111101 to UserID 1111103. Anyone know the procedure for this. I use php/mysql and dreamweaver.
-
List View webpart from subsite to Top site shows random error "List Does not exist"
Hi All, We have a list in subsite and we are creating a view for that list which we are showing in one of the top site home page. We have taken care of changing the web and list guid of list view webpart when we added on top site. Its working fine bu
-
How do i get a valid printer code for h470?
I see that my printer is able to use eprint, but I cannot find any information on how to set this up and enable web services or ePrint. My ultimate goal is to enable my mobile devices (tablet and phone) to be able to print. I see that the only way
-
Can I anchor the new mini-player to one screen while keeping iTunes in another on iTunes 11?
I like having my main iTunes window on another screen while I'm browsing so that it doesn't distract me when I'm working. But I like the new mini-player & I ilke the fact that it notifies which song is playing each time it skips to the next one. So w
-
Backup and restoration of weblogic server (alongwith its domain)
Hello Everyone, I want to change node 1 hardware due to some technical issues. Currently im using weblogic 10.3.6 with Oracle forms and Reports 11gR2 (only forms reports on HA) on Windows Server 2008 R2 After changing hardware im planning to use the