Suggestion regarding query
Hi,
I have a requirement to select two columns from 6 million rows which is one database, and go through the result set, take the one of the column value as the criteria and select another column from 10000 rows table.
I have used two methods to work. Both are working but they are very slow.
I am using jdbc for this.
First method:
Following is the pseudo code for the same
--Select all rows from the table 1
while (rs.next())
String column1= rs.getString(1);
String Query 2= "Select column2 from table 2 where my_field=column1";
--prepare the statement1 using query2
-- execute the statement1 and copy in to rs1
-- while (rs1.next())
do something
Second method:
In this one instead of querying the database for each row in the first resutl set, used a stored procedure which returns a ref cursor taking the array as the input string.
create or replace type mylist as table of varchar2(20);
create or replace type outlist as table of BLOB;
create or replace package my_pkg
as
type rc is ref cursor;
procedure p(myval_list in mylist, outcur OUT rc);
end;
create or replace package body my_pkg
as
PROCEDURE get_phonetype(myval_list IN imeilist,orefcur OUT rc )
AS
l_data outlist := outlist();
tmp_profile BLOB;
BEGIN
--DBMS_OUTPUT.put_line(myval_list.COUNT);
FOR i IN myval_list.FIRST .. myval_list.LAST
LOOP
BEGIN
SELECT column1 INTO tmp_profile FROM table1 WHERE
column2 IN (SELECT column2
FROM table2
WHERE (column3< myval_list(i) AND column4 > myval_list(i)));
--DBMS_OUTPUT.put_line(tmp_phone);
l_data.extend;
l_data(i) := tmp_profile;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
END;
END LOOP;
open outcur for
select * from TABLE( cast (l_data as outlist));
END;
END;
in the java program:
--Select all rows from the table 1
while (rs.next())
--loop few times to populate the column1 string arrays
OracleCallableStatement stmt1=(OracleCallableStatement)conn.prepareCall("{call p(?,?)}");
-- register the out parameter as ORACLETYPES.CURSOR
--prepare the array descriptor for the array, set the array using column1 values
-- set the first argument as array
-- retrieve the result set
--do something with the result set
} //end of while
I thought using the stored procedure would make my process faster, but the second approach deteriated the execution time.
I could not understand where I did the mistake. FOr the 200000 rows for the first table, first approach executed in 10 minutes and the second was taking more than hours.
Can some one help me in fine tuning the stored procedure or suggest an alternative best method.
Regards,
Syam
Syam,
Not knowing your table data or the whole of the queries you're making, this may not be feasible. But could you write this as either a single (albeit complex) query, or perhaps a PL/SQL block that uses a temp table or two, but still does all of the processing in Oracle as queries, not loops?
From the examples you gave, it looks like putting it into one query would just involve a few table joins. But they look like you abbreviated some more complex processing...
Similar Messages
-
Regarding Query/Where box in oracle forms
Hi,
I have a query regarding query/where box in oracle.
When I enter ":" in one of the field query box pops up and when I enter some query and press F12 to execute query.
The OK button has to be pressed twice to retrieve the result.
Can anyone please let me know why this is happening, instead of retreiving results at one go by pressing OK once.
When does query box pos up? I have to avoid hitting OK button on query box twice.
Thanks for your advice in advance.
Thanks,
KLC
Edited by: user5411765 on Nov 22, 2010 10:44 PMHi,
Were you able to get around this problem? I am facing the same and need help! :(
Regards,
Arun -
Need suggestion regarding File compression and splititng
Hi,
I want to split and compress the big files into small chucks. On later any standard zip utility i.e. winzip, 7z etc can merge(extract) all the chunks to generate the original file. I am looking for any java library which provide the split and compression functionality.
As Java also supports in built compression utility. Should I use those library or any other open source is available to do this? I welcome your suggestion regarding how can I start.
ThanksIf you're just looking for something to be used internally, it'd be pretty simple:
1. Open your source InputStream.
2. Create a standard read/write loop to pump the stream.
3. Add a counter that determines how much you've pushed into your current target. After you reach a certain value, close your current target, create a new target stream, and reset the counter.
4. Conclude by closing your source and your current target.
For compression, you can use the built-in GZIPOutputStream or a third-party library of your choice. I usually find GZIP sufficient for my needs.
Of course, if you want the output to be compatible with other programs like 7-Zip, you've got a lot more work on your hands complying with the file format spec. :) -
Hi
I need you help for suggesting a query. These are the two tables :
CREATE TABLE "RENCONTRE"
( "NUMPERS1" NUMBER,
"NUMPERS2" NUMBER,
"DATE_R" DATE,
"NUMLIEU" NUMBER,
"RESULTAT" VARCHAR2(20),
CONSTRAINT "RENCONTRE_PK" PRIMARY KEY ("NUMPERS1", "NUMPERS2", "DATE_R") ENABLE
ALTER TABLE "RENCONTRE" ADD CONSTRAINT "RENCONTRE_FK" FOREIGN KEY ("NUMLIEU")
REFERENCES "LIEU" ("NUMLIEU") ENABLE
CREATE TABLE "PERSONNE"
( "NUMPERS" NUMBER,
"NOM" VARCHAR2(50),
"PRENOM" VARCHAR2(50),
"ADRESSE" VARCHAR2(128),
"TELEPHONE" VARCHAR2(64),
"SEXE" VARCHAR2(20),
CONSTRAINT "PERSONNE_PK" PRIMARY KEY ("NUMPERS") ENABLE
INSERT INTO PERSONNE (Numpers,Nom,Prenom,Adresse,Telephone,Sexe) values
(1,'Delval','Bruno','Rue de la Fantaisie','06 52 45 89','masculin');
INSERT INTO PERSONNE (Numpers,Nom,Prenom,Adresse,Telephone,Sexe) values (2,'Jolie','Emily','30 rue de arc en ciel','06 25 89 45','feminin');
INSERT INTO PERSONNE (Numpers,Nom,Prenom,Adresse,Telephone,Sexe) values (4,'Dufour','Coralie','97 avenue du Four','05 78 46 89','feminin');
INSERT INTO PERSONNE (Numpers,Nom,Prenom,Adresse,Telephone,Sexe) values (3,'Judoper','Marcel','23 rue de la resistance','06 89 45 78','masculin');
INSERT INTO RENCONTRE (NUMPERS1,NUMPERS2,DATE_R,NUMLIEU,RESULTAT) VALUES (1,2,TO_DATE('01/20/2007', 'DD/MM/YYYY'),1, 'positif');
INSERT INTO RENCONTRE (NUMPERS1,NUMPERS2,DATE_R,NUMLIEU,RESULTAT) VALUES (3,4,TO_DATE('01/15/2006', 'DD/MM/YYYY'),2,'negatif');
INSERT INTO RENCONTRE (NUMPERS1,NUMPERS2,DATE_R,NUMLIEU,RESULTAT) VALUES (2,4,TO_DATE('01/01/0007', 'DD/MM/YYYY'),4,’positif’);The table RENCONTRE contains the NUMPERS of people who had met another person (NUMPERS1 and NUMPERS2 of the table RENCONTRE)
NUMPERS1 and NUMPERS2 refers to NUMPERS of the table PERSONNE.
Expected result of the query :
Name of the people (column 'NOM' of table PERSONNE) who never had met a person of the same gender ('SEXE')
NOM
Judoper
Thank you for your kind help.
ChristianThe foreign key might be correctly intended, but we don't have the table it refers to.
But anyway, that's a side note, how about:
SQL> select p.nom
2 from personne p
3 where not exists ( select null
4 from rencontre r
5 , personne p2
6 where r.numpers1 = p.numpers
7 and p2.numpers != p.numpers
8 and p2.numpers = r.numpers2
9 and p2.sexe = p.sexe
10 )
11 and not exists ( select null
12 from rencontre r
13 , personne p2
14 where r.numpers1 != p.numpers
15 and p2.numpers = p.numpers
16 and p2.numpers = r.numpers2
17 and p2.sexe = p.sexe
18 );
NOM
Delval
Judoper
2 rows selected. -
hello! i am new to Macbook pro, i have recently transferred my data from my Pc to Mac, i can not open .exe file. Please give me any suggestion regarding this!
I have using Mac OS 10.9.2Try running it through WineSkin or CrossOver Mac, or installing Windows through VirtualBox, Parallels Desktop, VMware Fusion, Boot Camp, or similar software.
(106527) -
Suggestion regarding Oracle import & export utility
hi
I am navneet,I want to give some suggestion on Oracle import & export utility to Oracle Corporation. can u tell me where to send these suggestions
regards
navneetIt would seem to me that if they are enhancement requests, then the right way would be to file an enhancement request. If they are bugs, then file SRs so bugs can be entered.
Dean -
Trying to play purchased TV series to my Apple TV, I am requested to authorise the computer. This has already been done and I have tried the suggestions regarding authorisation. I can play the programs on my computer, but not the Apple TV.
Any ideas?in remote app click on the
lower left corner on the text
top of the context menu click devices
choose the appletv rather then your shared lib in the list
if you are trying to view a movie that is located on your ipad on your tv using the appletv then
you should use airplay mirror not the remote app -
Want suggestion regarding a bulk deletion
Hi,
I need some suggestion regarding a deletion and i have the following scenario.
tab1 contains 100 items.
for one item tab2..6 tables contain 4000 rows.So the loop will run for each item and will delete 20,000 lines and will do a commit.
Currently for 5,00,000 deletion it is taking 1 hr.All the tables and indexes are analysied.
CURSOR C_CHECK_DELETE_IND
IS
SELECT api.item FROM tab1 api WHERE api.delete_item_ind = 'Y';
type p_item IS TABLE OF tab1.item%type;
act_p_item p_item;
BEGIN
OPEN C_CHECK_DELETE_IND;
LOOP
FETCH C_CHECK_DELETE_IND bulk collect INTO act_p_item limit 5000;
FOR i IN 1..act_p_item.count
LOOP
DELETE FROM tab2 WHERE item = act_p_item(i);
DELETE FROM tab3 WHERE item = act_p_item(i);
DELETE FROM tab4 WHERE item = act_p_item(i);
DELETE FROM tab5 WHERE item = act_p_item(i);
DELETE FROM tab6 WHERE item = act_p_item(i);
COMMIT;
END IF;
END LOOP;
exit when C_CHECK_DELETE_IND%notfound;
END LOOP;
Hope i have explained the scenario.Can you please suggest me the right approach.
Thanks in advance.Hi,
why not just use straight sql. ie
DELETE FROM tabn
WHERE item in (
SELECT api.item
FROM tab1 api
WHERE api.delete_item_ind = 'Y');For bulk deletes other techniques include -
disabling constraints then reenabling them
making indexes unusable and then rebuilding them
creating temporary tables with the data you want left, dropping the source table and renaming the temp table
partitioning
Which of these is most useful depends on a lot of factors such as data volumes versus delete volumes, system outage availability, concurrency issues etc.
Regards
Andre -
Regarding Query and Logical database
Hi All,
I have one requirement to create a report which gives all selection fields of a query.I got the selection fields defined in the query,but some extra selection fields are coming from logical database,which query uses.These extra fields count is different for different queries using same logical data base.Please suggest me a solution.
Regards
ShibinHi Jogeswara,
Thanks for your inputs.
But my question is, how can I filter the data which is being fetched by standard logical database. I cannot go inside the std. LDB and change internal tables of it. I tried coding in extras, but I think it works only if we want to add additional fields in output.
At present, we are considering the option of creating a z LDB where we copy. std. LDB and also add the reqd. table which is not present in LDB.
Is there any other option?
Please provide your valuable inputs.
Regards,
Imran Kundan. -
Hi,
I have a requirement in which i have to add 1 more column to a ALV reporte that was created based on a query (SQ01). But the problem is that the query was deleted.
Does anybody know how to rebuild the query from the program? Or could anybody tell me which would be a better solution for this?
Regards,
RobertoI think it is not possible to create a SQ01 from report. My suggestion will be alter the report as per your needs
a® -
Regarding Query Generator One Column Extra
hi.
i have one requirement
ie.
normally
sleect ordr.cardcode from ordr
i put this query in query generator
so, the result will come like
s
y
x
p
but what i need is, i want one column extra each time the value of this column is 'co'
like
co s
co y
co x
co p
is it possible...
i need your valuable suggestions..Hi Srinivas,
Fine Srini..hope you are fine..
If you got the answer please close this thread with tag correct answer...
Regards
Ajith -
Hi All,
Please suggest me the logic to generate the report as per below
I need to display the No Of Customers based upon the sales quantity they purchased for particular period (Jan to May) in the Year range (2005 to 2006)
Its Urgent
Thanks & Regards
Veeru.Hi
Use the conditions to solve ur problem.
You can formulate conditions to make data analysis more efficient. In the results area of the query, the data is filtered according to the conditions so that only the part of the results area that you are interested in is displayed.
If you apply conditions to a query, you are not changing any numbers. Instead, you are just hiding the numbers that are not relevant for you. For this reason, conditions have no effect on the displayed values of the results rows. The results row of a query with an active condition corresponds to the results row of a query without this condition (see Ranked List Condition: Top 5 Products).
You can define multiple conditions for a query. Conditions are evaluated independently of each other. In doing so, the results quantity for the evaluation sequence is independent. The result is the intersection of the individual conditions. Multiple conditions are linked logically with AND. A characteristic value is only displayed when it fulfills all (active) conditions of the query (see Linking Two Conditions: Bottom 2 Sales and Invoiced Quantity > 100,000,000). -
Need suggestions regarding a system design for incremental load
Hi,
Our client has a set of SQL Server tables which are being fully refreshed daily using views from DB2 source tables. We need to design an approach to load them incrementally.
We have a third party application 'XXX' which will provide us the changed records in the underlying DB2 tables into SQL Server tables daily. Let us call them CDC_<tbl>. This table will have the same schema of source and have a flag to indicate whether
it is an insert, update or delete record. From these CDC tables, we have to do the required transformations and do the insert/update/delete from the target table accordingly.
This approach would work easily for cases where there is only one source table. But when we have multiple tables joined together to load the target table, we are unable to design an approach. If on a particular day, an insert record comes in only one of
the source CDC tables, we will not be getting that row in the target since the other CDC table doesn't have a record for that particular key. We cannot join the SQL Server CDC table with source DB2 table since that will cause performance issues.
Please share your thoughts on how we can design an approach which will work in cases of join, union, group by etc. between source tables. We are open to suggestions on changes in CDC tables also since the third party tool is to be configured as per our design
needs.
Thanks in advance,
KPIf on a particular day, an insert record comes in only one of the source CDC tables, we will not be getting that row in the target since the other CDC table doesn't have a record for that particular key.
If I understand correctly, you extract data using DB2 views (some with joins) and then use third party CDC software to capture all changes made to the underlying DB2 tables. These changes are then applied to a transformed version of data extracted
from the views. If my understanding is correct, why use DB2 views at all? It seems to me the transformation process must have intimate knowledge of the underlying DB2 tables anyway in order to apply the CDC data properly.
Are you saying you are not getting the other CDC table row at all, or is it just that the CDC tables are not transactionally consistent at the time the changes are applied to the target? I think transactional inconsistencies should be addressed by
the third party CDC application. The other alternative as I see it is to query DB2 for a each CDC key to make sure you have the latest data during the transformation process.
Dan Guzman, SQL Server MVP, http://www.dbdelta.com -
Regarding Query Performance.
Please tell me ..
How can i check the performance of query using index and without using index?Hi,
As deepak said, query with and without index.
to get the cost and access path of the query get explain for the query. Read the Oracle docs
[http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/ex_plan.htm]
It is common to all the version from 9i as far as I know.
do
SQL> set autotrace on
SQL> run your query
you will get the explain plan and cost information in the sql prompt if the statistis_level is set to typical or all
Regards,
Vijayaraghavan K
Edited by: Vijayaraghavan Krishnan on Jan 18, 2010 4:24 PM -
Urgent..help regarding query
can anyone tell me what this code does..
REPORT Z_SD_Q_03 MESSAGE-ID Z_SD.
PROGRAMA : Z_SD_Q_03
FECHA : 12-07-1999
AUTOR : MADASV
DESCRIPCION : Ejecutar query 03(SD)
VARIABLES
DATA: WERKS LIKE LIKP-WERKS,
NOMBRE_REPORT LIKE AQADEF-PGNAME.
RANGES
RANGES CENTRO FOR LIKP-WERKS.
CONSTANTS
CONSTANTS: QUERY LIKE AQADEF-QUNAME VALUE '03',
USERGROUP LIKE AQADEF-BGNAME VALUE 'SD'.
START-OF-SELECTION
START-OF-SELECTION.
Centro
GET PARAMETER ID 'WR1' FIELD WERKS.
CENTRO-LOW = WERKS.
CENTRO-SIGN = 'I'.
CENTRO-OPTION = 'EQ'.
APPEND CENTRO.
CALL FUNCTION 'RSAQ_EXIST_QUERY'
EXPORTING
WORKSPACE = ' '
USERGROUP = USERGROUP
QUERY = QUERY
IMPORTING
REPORTNAME = NOMBRE_REPORT
EXCEPTIONS
NO_USERGROUP = 1
NO_QUERY = 2
OTHERS = 3
IF SY-SUBRC <> 0.
MESSAGE E100 WITH QUERY SY-MANDT.
ELSE.
SUBMIT (NOMBRE_REPORT)
WITH OFICI IN CENTRO
WITH SP$00001-LOW = SY-DATUM
VIA SELECTION-SCREEN.
ENDIF.it's checking display authorization of plant WR1 for current user .
Reward if useful
Regards
ANUPAM
Maybe you are looking for
-
Trial version of Adobe Acrobat Pro 9
Is it possible to successfully deploy a trial version of Adobe Acrobat 9 across a Windows network? Can a group of users open a single file from inside Adobe Acrobat Pro 9 at the same time, rename it and work from the individual copied file?
-
Old iphone3 photo albums not showing in iphoto and I want to import them
I found my old iphone3 today and discovered a heap of photos on there that we lost years ago when our hard drive died. I'm very keen to get these photos onto the computer and of course then back them up onto an external drive! When I plug the phone i
-
MP3 files do not appear in Library
I am having a problem with windows media player. I am running Windows 7 and media player 12. I have wav recordings of Swing Shift which I have converted to mp3 files and then used a tag editor to fill in the Artist and Album fields. I included the
-
Not able to locate the path of adgentopfile.sh
Hi All, I am in the process of creating a customtop. I got stuck in between because i need to run the adgentopfile.sh which i am not able to locate. bash-3.00$ cd $INST_TOP/admin/install bash-3.00$ cd /u01/oracle/ERPDEV/appldev/inst/apps/DEV_zanerpua
-
I want to download free apps for iphone 4s but when downloading it is asking for payment info. the application are free but why it is asking for purchase details...please help me...