Help needed in copying data through sql
Hi
I want to populate data in a table in a manner
EID ENAME EADDRESS ESALARY EDEPARTMENT MANAGER_ID
101 Pankaj Saxena New Delhi 2000 IT
102 Sanjay Singh New Delhi 2000 IT 101
103 Dhiraj Tuteja Kanpur 3000 NONIT 101
104 Nitin Grover New Delhi 4000 IT 102
105 Juhi Agarwal Itawa 5000 NONIT 103
106 Siddharth Itawa 5000 NONIT 103
107 Kalyan Itawa 7000 IT 104Now i want to populate the same data 10 times but the ids need to be incremented
What should i do??
I am using oracle 9i
insert into demo_1
select eid,ename,eaddress,esalary,edepartment,manager_id from demo_1I eid need to be increased sequencially
Try this
select eid, ENAME, EADDRESS, ESALARY, EDEPARTMENT, MANAGER_ID
from <table>
union all
select max(eid) over() +rownum eid, ENAME, EADDRESS, ESALARY, EDEPARTMENT, MANAGER_ID
from <table>
cross join (select level no from dual connect by level <=9)
Similar Messages
-
Help needed to load data using sql loader.
Hi,
I trying to load data from xls to oracle table(solaris OS) and its failing to load data.
Control file:
LOAD DATA
CHARACTERSET UTF16
BYTEORDER BIG ENDIAN
INFILE cost.csv
BADFILE consolidate.bad
DISCARDFILE Sybase_inventory.dis
INSERT
INTO TABLE FIT_UNIX_NT_SERVER_COSTS
FIELDS TERMINATED BY ','
TRAILING NULLCOLS
HOST_NM,
SERVICE_9071_DOLLAR DOUBLE,
SERVICE_9310_DOLLAR DOUBLE,
SERVICE_9700_DOLLAR DOUBLE,
SERVICE_9701_DOLLAR DOUBLE,
SERVICE_9710_DOLLAR DOUBLE,
SERVICE_9711_DOLLAR DOUBLE,
SERVICE_9712_DOLLAR DOUBLE,
SERVICE_9713_DOLLAR DOUBLE,
SERVICE_9720_DOLLAR DOUBLE,
SERVICE_9721_DOLLAR DOUBLE,
SERVICE_9730_DOLLAR DOUBLE,
SERVICE_9731_DOLLAR DOUBLE,
SERVICE_9750_DOLLAR DOUBLE,
SERVICE_9751_DOLLAR DOUBLE,
GRAND_TOTAL DOUBLE
Log file:
Table FIT_UNIX_NT_SERVER_COSTS, loaded from every logical record.
Insert option in effect for this table: INSERT
TRAILING NULLCOLS option in effect
Column Name Position Len Term Encl Datatype
HOST_NM FIRST * , CHARACTER
SERVICE_9071_DOLLAR NEXT 8 DOUBLE
SERVICE_9310_DOLLAR NEXT 8 DOUBLE
SERVICE_9700_DOLLAR NEXT 8 DOUBLE
SERVICE_9701_DOLLAR NEXT 8 DOUBLE
SERVICE_9710_DOLLAR NEXT 8 DOUBLE
SERVICE_9711_DOLLAR NEXT 8 DOUBLE
SERVICE_9712_DOLLAR NEXT 8 DOUBLE
SERVICE_9713_DOLLAR NEXT 8 DOUBLE
SERVICE_9720_DOLLAR NEXT 8 DOUBLE
SERVICE_9721_DOLLAR NEXT 8 DOUBLE
SERVICE_9730_DOLLAR NEXT 8 DOUBLE
SERVICE_9731_DOLLAR NEXT 8 DOUBLE
SERVICE_9750_DOLLAR NEXT 8 DOUBLE
SERVICE_9751_DOLLAR NEXT 8 DOUBLE
GRAND_TOTAL NEXT 8 DOUBLE
Record 1: Rejected - Error on table FIT_UNIX_NT_SERVER_COSTS, column HOST_NM.
Field in data file exceeds maximum length
Table FIT_UNIX_NT_SERVER_COSTS:
0 Rows successfully loaded.
1 Row not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.
Please help me ASAP.
Awaiting u r reply.Hi,
I verified and everything looks fine according to me.
Table structure:
OST_NM VARCHAR2(30)
SERVICE_9071_DOLLAR NUMBER(8,2)
SERVICE_9310_DOLLAR NUMBER(8,2)
SERVICE_9700_DOLLAR NUMBER(8,2)
SERVICE_9701_DOLLAR NUMBER(8,2)
SERVICE_9710_DOLLAR NUMBER(8,2)
SERVICE_9711_DOLLAR NUMBER(8,2)
SERVICE_9712_DOLLAR NUMBER(8,2)
SERVICE_9713_DOLLAR NUMBER(8,2)
SERVICE_9720_DOLLAR NUMBER(8,2)
SERVICE_9721_DOLLAR NUMBER(8,2)
SERVICE_9730_DOLLAR NUMBER(8,2)
SERVICE_9731_DOLLAR NUMBER(8,2)
SERVICE_9750_DOLLAR NUMBER(8,2)
SERVICE_9751_DOLLAR NUMBER(8,2)
GRAND_TOTAL NUMBER(8,2)
Control file:
LOAD DATA
BYTEORDER BIG ENDIAN
INFILE cost.csv
BADFILE consolidate.bad
DISCARDFILE Sybase_inventory.dis
INSERT
INTO TABLE FIT_UNIX_NT_SERVER_COSTS
FIELDS TERMINATED BY ','
TRAILING NULLCOLS
HOST_NM ,
SERVICE_9071_DOLLAR NUMBER(8,2),
SERVICE_9310_DOLLAR NUMBER(8,2),
SERVICE_9700_DOLLAR NUMBER(8,2),
SERVICE_9701_DOLLAR NUMBER(8,2),
SERVICE_9710_DOLLAR NUMBER(8,2),
SERVICE_9711_DOLLAR NUMBER(8,2),
SERVICE_9712_DOLLAR NUMBER(8,2),
SERVICE_9713_DOLLAR NUMBER(8,2),
SERVICE_9720_DOLLAR NUMBER(8,2),
SERVICE_9721_DOLLAR NUMBER(8,2),
SERVICE_9730_DOLLAR NUMBER(8,2),
SERVICE_9731_DOLLAR NUMBER(8,2),
SERVICE_9750_DOLLAR NUMBER(8,2),
SERVICE_9751_DOLLAR NUMBER(8,2),
GRAND_TOTAL NUMBER(8,2)
Sample date file:
ABOS12,122.46,,1315.00,,1400.00,,,,,,,,1855.62,,4693.07
ABOS39,6391.16,,1315.00,,1400.00,,,,,,,,,4081.88,13188.04 -
I need to copy data from a table in one database (db1) to another table in
Hi
I need to copy data from a table in one database (db1) to another table in another database (db2).
I am not sure if the table exists in db2,,,if it doesnot it needs to be created as well data also needs to be inserted...
How am I supposed to this using sql statements..?
I shall be happy if it is explained SQL also...
Thanking in advanceHow many rows does the table contains? There are manyway you can achieve this.
1. export and import.
2. create a dblink between two databases and use create table as select, if structure doesnot exists in other database, if structure exists, use, insert into table select command.
example:
create a dblink in db2 database for db1 database.
create table table1 as select * from table1@db1 -- when there is no structure present
-- you need to add constraints manually, if any exists.
insert into table1 select * from table1@db1 -- when there is structure present.
If the table contains large volume of data, I would suggest you to use export and import.
Jaffar -
Does Mac have a tool similar to snippy or snagit?
I do not have Windows.
Need to copy data off archived online newspapers. Unable to do so with screenprint, etc.
Heard windows has a tool called Snippy, looked at Snagit, but read free download agreement and it reads a bit 'fishy', as the download is only free for 30 days, etc and it talks about fees etc.Mac does have two utilities: Snagit for Mac and LittleSnapper. There are a few others. Snag it for mac is just a better "clippings" thing. It will not scan your image. There are OCR products available for Mac which might be able to take your clipping document and scan it back to text.
Snagit Mac is here: http://www.techsmith.com/snagit-mac-features.html
To see OCR stuff do a google search for: Mac OCR Software
And you'll get quite a few. -
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 -
Help converting between Java Dates and SQL Dates
Hey all,
I'm working on a JSP to allow a user to enter information about news articles into a mySQL database. I'm using text fields for most of the data, and most of it is transferred correctly when the user hits "Submit." However, I am having a problem with the date field of the mySQL database. Basically I'm trying to retrieve the current date from the JSP page, and then insert this into the date field of the appropriate table when the user hits submit. The problem is that I can't typecast a java.util.Date or even a java.util.Calendar to a java.sql.Date object. I've tried lots of approaches, including creating a new instance of java.util.Calendar, getting all its fields and concatenating them onto the date variable, but this doesn't work.
Anyone know how I could easily convert between java.util.Date or java.util.Calendar and java.sql.Date?
Thanks!Thanks for the help!
I can correctly display the current date on the page in java.sql.Date format now, but it's still not being inserted into the database correctly. The specific code is as follows:
java.util.Date dt = new java.util.Date();
java.sql.Date sqlDate = new java.sql.Date(dt.getTime());
(As you wrote)
Then (after connecting to the database etc.):
PreparedStatement pstmt = con.prepareStatement("INSERT INTO NEWS(NEWSDATE,DAYOFWEEK,AUTHOR,HEADLINE,CLIP,PUBLICATION,LINK,NEWSLOCATION,DATECREATED,DATEMODIFIED,CATEGORY,KEYWORDS,PHOTOURL,PHOTOGRAPHER,AUDIOURL) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
pstmt.clearParameters();
pstmt.setString(1,date);
pstmt.setString(2,dayofweek);
pstmt.setString(3,author);
pstmt.setString(4,headline);
pstmt.setString(5,clip);
pstmt.setString(6,publication);
pstmt.setString(7,link);
pstmt.setString(8,newslocation);
pstmt.setDate(9,sqlDate);
pstmt.setString(10,datemodified);
pstmt.setString(11,category);
pstmt.setString(12,keywords);
pstmt.setString(13,photoURL);
pstmt.setString(14,photographer);
pstmt.setString(15,audioURL);
int i = pstmt.executeUpdate();
pstmt.close();
All the other fields are retrieved with request.getParameter from text fields. Any idea why the DATECREATED field is being updated to all 0's but the others work fine?
Thanks again. -
Help needed to insert data from different database
Hi ,
I have a requirement where i need to fetch data from different database through database link .Depending on user request , the dblink needs to change and data from respective table from mentioned datbase has to be fetched and populated .Could i use execute immediate for this, would dblink work within execute immediate .If not , could pls let me know any other approach .What does "the dblink needs to change" mean?
Are you trying to dynamically create database links at run-time? Or to point a query at one of a set of pre-established database links at run-time?
Are you sure that you really need to get the data from the remote database in real time? Could you use materialized views/ Streams/ etc to move the data from the remote databases to the local database? That tends to be far more robust.
Justin -
I need to copy data from sysbase database to oracle database
I have to database one on sybase and the other on oracle ,them have the same tables i need to copy the data in the table of sybase to the tables in oracle
I setup the getway already but after this the oracle client didnt connect to any thing even the oracle server which was conneted succesfully before setup the getway
I sorry for long and thanks for your advice -
Help needed on meta data export
I need a meta data export dump of a source database of two schemas and import to a fresh new database.
COuld you please help with the steps to be followed.Assuming you are using 10g and exp utility
You can say rows=N
exp help=yes
Export: Release 10.2.0.1.0 - Production on Thu Jul 23 13:36:59 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
You can let Export prompt you for parameters by entering the EXP
command followed by your username/password:
Example: EXP SCOTT/TIGER
Or, you can control how Export runs by entering the EXP command followed
by various arguments. To specify parameters, you use keywords:
Format: EXP KEYWORD=value or KEYWORD=(value1,value2,...,valueN)
Example: EXP SCOTT/TIGER GRANTS=Y TABLES=(EMP,DEPT,MGR)
or TABLES=(T1:P1,T1:P2), if T1 is partitioned table
USERID must be the first parameter on the command line.
Keyword Description (Default) Keyword Description (Default)
USERID username/password FULL export entire file (N)
BUFFER size of data buffer OWNER list of owner usernames
FILE output files (EXPDAT.DMP) TABLES list of table names
COMPRESS import into one extent (Y) RECORDLENGTH length of IO record
GRANTS export grants (Y) INCTYPE incremental export type
INDEXES export indexes (Y) RECORD track incr. export (Y)
DIRECT direct path (N) TRIGGERS export triggers (Y)
LOG log file of screen output STATISTICS analyze objects (ESTIMATE)
{color:red}*ROWS export data rows (Y)* {color} PARFILE parameter filename
CONSISTENT cross-table consistency(N) CONSTRAINTS export constraints (Y)
OBJECT_CONSISTENT transaction set to read only during object export (N)
FEEDBACK display progress every x rows (0)
FILESIZE maximum size of each dump file
FLASHBACK_SCN SCN used to set session snapshot back to
FLASHBACK_TIME time used to get the SCN closest to the specified time
QUERY select clause used to export a subset of a table
RESUMABLE suspend when a space related error is encountered(N)
RESUMABLE_NAME text string used to identify resumable statement
RESUMABLE_TIMEOUT wait time for RESUMABLE
TTS_FULL_CHECK perform full or partial dependency check for TTS
TABLESPACES list of tablespaces to export
TRANSPORT_TABLESPACE export transportable tablespace metadata (N)
TEMPLATE template name which invokes iAS mode export
Export terminated successfully without warnings. -
Need help in storing XML data in SQL server using EJB
Hi all...
i have one XML file and i need to store the data of XML in one of the table of SQL server ..i want to do this using EJB..
like this
Example :
Data i XML :
========
<Employee>
<Details>
<empid> 101 </empid>
<name> Ajitha </name>
</Details>
</Employee>
Table i have Created in SQL SERVER:
==============================
Empid || name
Final output should be :
=================
Empid || name
101 || AjithaHI,
Please check your settings as per following.
Goto T code> DC20>Define data carrier type "server, front end"---> Then check the setting as per below
Type Description Path Online
PC give descriptio maintain path Tick
Then Select this entry and click on " Define servers and files or folders"--->Then check the setting as per below
Data Carrier Type Description
DEFAULT PC default
Then Select this entry and click on "Identify front computer"--> Then check the setting as per below
Data Carrrier Type Net. address Description
Default PC DEFAULT Default for local PC
I have explained above so that u can co relate your settings with above..
I hope this will help you.
Thanks
Yogesh -
I need to denormalize data in sql query, please help!
With the query
select ref, start_time, end_time, person
from appointments
I get, eg:
REF START_TIME END_TIME PERSON
1234 10:00 11:00 USER1
1234 10:00 11:00 USER2
The users want to see it like this:
REF START_TIME END_TIME PERSON
1234 10:00 11:00 USER1, USER2
How do I do this just in sql?
cheers
Tracey.Apologies, my mistake, I forgot to connect by the ref as well...
(Note: you can ignore the CAST to VARCHAR2(40) as that just helped me get the formatted output.)
SQL> ed
Wrote file afiedt.buf
1 with t as (select 1234 as ref, '10:00' as start_time, '11:00' as end_time, 'USER1' as person from dual union all
2 select 1234, '10:00', '11:00', 'USER2' from dual union all
3 select 345, '11:00', '12:00', 'USER3' from dual)
4 -- END OF TEST DATA
5 select ref, start_time, end_time, CAST(MAX(LTRIM(SYS_CONNECT_BY_PATH(person,', '),', ')) AS VARCHAR2(40)) as users
6 from (select ref, start_time, end_time, person
7 ,row_number() over (partition by ref, start_time, end_time order by person) rn
8 from t) t
9 CONNECT BY rn = PRIOR rn+1 AND ref = PRIOR ref
10 START WITH rn = 1
11* GROUP BY ref, start_time, end_time
SQL> /
REF START END_T USERS
1234 10:00 11:00 USER1, USER2
345 11:00 12:00 USER3
SQL> -
Help needed with Copying DVD error in Toast Titanium 6
(I tried to post to Roxio forum but couldn't get registered) ... hope someone can help
I made an iDVD of a school event (Métis Gathering) and burned it to DVD through the iDVD program (iDVD 6)
I used Toast (6.0.3) to make 8 copies of the dvd.
Now I need to make more copies, but Toast never finishes the 'recording' (copying) session ... it gives me "couldn't complete the last command: I/O error, result code -36."
I'm using the original DVD, which was only played once and I've kept it as a master .... I don't see any scratches or anything on it.
What's happening? What can I do?
Any help is appreciated, thank you
Eliz
iMac 17", Intel Core Duo , 512 Ram, 160 GB Mac OS X (10.4.6)With the luxury of two internal burners, I've never
used Toast that way.
I find it a luxury just to have a dvd burner!!
Any way, back to the saga .... I tried the same original master dvd at home again, no copying possible, so setting the speed wasn't a factor
So, I put in the copy I made at school .... I made a disk image with disc utility, then burned the image ... at a slower speed ... with toast. Seems fine. I'm going to save the disc image as a data dvd to use as the future master, no more copying with toast for me!
Since I've managed to overcome this little problem using a second computer (the luxury of which I won't have, come July), i think I'm okay ... just need to remember to try a slower burn speed from the start next time ...
But, why wouldn't it read the dvd? almost like it had a shelf life or something
Thank you for your help
Eliz -
Help needed in inserting data using a query
I need to have some data as a result of the following query:
select sched_num,load_id,ord_id,split_id from ord_load_seq
where (ord_id,split_id,sched_num) in (select ord_id,split_id,sched_num from ord_load_seq where seq_num = '2'
group by ord_id,split_id,sched_num having count(1) >1)
order by ord_id,split_id,sched_num;
But currently it retunrns no rows. The problem is in the having count(1)> 1 clause.
When i make =1, it returns rows. But no rows on > 1. I even tried inserting some rows to get the result >1
But still the query on a whole returns no rows.Please help.ohhh... lets start our lesson children:
here is code to consider:
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.2.0
SQL>
SQL> --Q1
SQL> with tbl as
2 (select 1 fld1, 1 fld2, 1 fld3 from dual
3 union all
4 select 1 fld1, 1 fld2, 2 fld3 from dual
5 union all
6 select 1 fld1, 1 fld2, 3 fld3 from dual
7 union all
8 select 1 fld1, 2 fld2, 3 fld3 from dual
9 union all
10 select 1 fld1, 3 fld2, 3 fld3 from dual)
11 select fld1, fld2, fld3 from tbl
12 order by fld1, fld2, fld3
13 /
FLD1 FLD2 FLD3
1 1 1
1 1 2
1 1 3
1 2 3
1 3 3
SQL> --Q2
SQL> with tbl as
2 (select 1 fld1, 1 fld2, 1 fld3 from dual
3 union all
4 select 1 fld1, 1 fld2, 2 fld3 from dual
5 union all
6 select 1 fld1, 1 fld2, 3 fld3 from dual
7 union all
8 select 1 fld1, 2 fld2, 3 fld3 from dual
9 union all
10 select 1 fld1, 3 fld2, 3 fld3 from dual)
11 select fld1, fld2, fld3, count(1) from tbl
12 group by fld1,fld2,fld3
13 order by fld1, fld2, fld3
14 /
FLD1 FLD2 FLD3 COUNT(1)
1 1 1 1
1 1 2 1
1 1 3 1
1 2 3 1
1 3 3 1
SQL> --Q3
SQL> with tbl as
2 (select 1 fld1, 1 fld2, 1 fld3 from dual
3 union all
4 select 1 fld1, 1 fld2, 2 fld3 from dual
5 union all
6 select 1 fld1, 1 fld2, 3 fld3 from dual
7 union all
8 select 1 fld1, 2 fld2, 3 fld3 from dual
9 union all
10 select 1 fld1, 3 fld2, 3 fld3 from dual)
11 select fld1, fld2, fld3 from tbl
12 group by fld1,fld2,fld3
13 having count(1) > 1
14 order by fld1, fld2, fld3
15 /
FLD1 FLD2 FLD3
SQL> --Q4
SQL> with tbl as
2 (select 1 fld1, 1 fld2, 1 fld3 from dual
3 union all
4 select 1 fld1, 1 fld2, 2 fld3 from dual
5 union all
6 select 1 fld1, 1 fld2, 2 fld3 from dual
7 union all
8 select 1 fld1, 1 fld2, 3 fld3 from dual
9 union all
10 select 1 fld1, 2 fld2, 3 fld3 from dual
11 union all
12 select 1 fld1, 3 fld2, 3 fld3 from dual)
13 select fld1, fld2, fld3 from tbl
14 order by fld1, fld2, fld3
15 /
FLD1 FLD2 FLD3
1 1 1
1 1 2
1 1 2
1 1 3
1 2 3
1 3 3
6 rows selected
SQL> --Q5
SQL> with tbl as
2 (select 1 fld1, 1 fld2, 1 fld3 from dual
3 union all
4 select 1 fld1, 1 fld2, 2 fld3 from dual
5 union all
6 select 1 fld1, 1 fld2, 2 fld3 from dual -- inserted duplicate row
7 union all
8 select 1 fld1, 1 fld2, 3 fld3 from dual
9 union all
10 select 1 fld1, 2 fld2, 3 fld3 from dual
11 union all
12 select 1 fld1, 3 fld2, 3 fld3 from dual)
13 select fld1, fld2, fld3, count(1) from tbl
14 group by fld1,fld2,fld3
15 order by fld1, fld2, fld3
16 /
FLD1 FLD2 FLD3 COUNT(1)
1 1 1 1
1 1 2 2
1 1 3 1
1 2 3 1
1 3 3 1
SQL> --Q6
SQL> with tbl as
2 (select 1 fld1, 1 fld2, 1 fld3 from dual
3 union all
4 select 1 fld1, 1 fld2, 2 fld3 from dual
5 union all
6 select 1 fld1, 1 fld2, 2 fld3 from dual -- inserted duplicate row
7 union all
8 select 1 fld1, 1 fld2, 3 fld3 from dual
9 union all
10 select 1 fld1, 2 fld2, 3 fld3 from dual
11 union all
12 select 1 fld1, 3 fld2, 3 fld3 from dual)
13 select fld1, fld2, fld3 from tbl
14 group by fld1,fld2,fld3
15 having count(1) > 1
16 order by fld1, fld2, fld3
17 /
FLD1 FLD2 FLD3
1 1 2
SQL> Q1. As you may see we have an bunch of data where each row is unique combination of the columns value.
Q2. lets try to group it by fld1 and fld2 and fld3 columns. We don't expect any miracle and got the same data as Q1. Why? Because each row is unique combination(group) in scope of fld1, fld2, fld3 - count(1) exactly shows us that.
Q3. Q2 is explanation why we got no rows filter (having count(1) > 1)because the result of the clause is always false.
Q4. Lets put some duplication.
Q5. Now we got some new result. Count shows us group with more then one rows.
Q6. Shows us exact group which we've found in Q5. -
Help Needed!! Working with SQL Databases
Hi All,
I'm currently working on an application that interfaces with an SQL database, and I seem to have ran into a roadblock.
I have a multicolumn list box on my front panel which is filled in with data extracted from the database. On selecting any of the rows in the list box, another one is opened displaying another set of data extracted by a generated SQL query. At the moment I am only selecting one row at a time to view it's related data, but I want to expand such that I can select mutiple rows from the list box at a time and see all of their corresponding data.
With only a single selection, I can pass the index value of the selection to an Index Array Function with the database as the other input and build my SQL statement.
But with multiple selections, I imagine I would have to build an array on index values and use those as a reference to build the SQL statment. And I am not sure how exactly to go about doing that.
Here is the code that I currently have working for a single selection from the list box.
Any help is appreciated. Cheers.
Solved!
Go to Solution.tdog wrote:
Hi All,
I'm currently working on an application that interfaces with an SQL database, and I seem to have ran into a roadblock.
I have a multicolumn list box on my front panel which is filled in with data extracted from the database. On selecting any of the rows in the list box, another one is opened displaying another set of data extracted by a generated SQL query. At the moment I am only selecting one row at a time to view it's related data, but I want to expand such that I can select mutiple rows from the list box at a time and see all of their corresponding data.
With only a single selection, I can pass the index value of the selection to an Index Array Function with the database as the other input and build my SQL statement.
But with multiple selections, I imagine I would have to build an array on index values and use those as a reference to build the SQL statment. And I am not sure how exactly to go about doing that.
Here is the code that I currently have working for a single selection from the list box.
Any help is appreciated. Cheers.
Regarding building the array:
I can see hat you multicolumn listbox has not multiselection enabled, and is limited to one or zero selected item at once. To enable multiselction; simply rightclick your multicolumn listbox and change your selection mode to support multiple selected items. The NewVal at the event structure should change from a single index number to a 1D array of indexed numbers. No coding needed. Then just retrive out all the items (since you know the indexes) and create the quiry. The quiry part I dont really know (long time no see SQL), but it looks like a for loop to create the string should do the trick? -
Help needed with pattern matching (analytics SQL ?)
Hello Forum Users,
I've got a curious problem on my hands that I am unable to think of an efficient way to code in Oracle SQL ....
(1) Background
Two tables :
MEASUREMENTS
ID NUMBER
M1 NUMBER
M2 NUMBER
M3 NUMBER
M4 NUMBER
INTERESTING_VALUES
ID NUMBER
M1 NUMBER
M2 NUMBER
M3 NUMBER
M4 NUMBER
(2) OUTPUT NEEDED
For each row in "MEASUREMENTS", count the number of matches in "INTERESTING_VALUES" (all rows). Please note that the matches might not be in the same column.... e.g. for a given row MEASUREMENTS M1 might match INTERESTING_VALUES M3.
I need to count 2,3 and 4 matches and provide the count values seperatley.
I am not interested in fuzzy matching (e.g. "greater than" or "less than"), the numbers only need to match exactly.
(You can use features up to 11g).
Thank you for your help.yup here you go...
SQL> select * from measurement;
ID M1 M2 M3 M4
1 30 40 110 120
2 12 24 175 192
3 22 35 147 181
SQL> select * from interesting;
ID M1 M2 M3 M4
1 16 171 30 110
2 40 171 30 110
5 181 147 35 22
4 175 12 192 24
3 175 86 192 24
SQL> SELECT id,
2 SUM(
3 CASE
4 WHEN LEN=1
5 THEN 1
6 ELSE 0
7 END) repeat2,
8 SUM(
9 CASE
10 WHEN LEN=2
11 THEN 1
12 ELSE 0
13 END) repeat3,
14 SUM(
15 CASE
16 WHEN LEN=3
17 THEN 1
18 ELSE 0
19 END) repeat4
20 FROM
21 (SELECT id,
22 spath ,
23 (LENGTH(spath)-LENGTH(REPLACE(LOWER(spath),',') ))/ LENGTH(',') LEN
24 FROM
25 (SELECT t.* ,
26 ltrim(sys_connect_by_path(cvalue,','),',') spath
27 FROM
28 (SELECT p.*,
29 row_number() over (partition BY id, id1 order by cvalue) rnum
30 FROM
31 (SELECT m.id,
32 m.m1 ,
33 m.m2 ,
34 m.m3 ,
35 m.m4 ,
36 (SELECT COUNT(*)
37 FROM interesting q
38 WHERE q.id=I.id
39 AND (q.m1 = column_value
40 OR q.m2 =column_value
41 OR q.m3 =column_value
42 OR m4 =column_value)
43 ) cnt ,
44 column_value cvalue,
45 i.id id1 ,
46 i.m1 m11 ,
47 i.m2 m21 ,
48 i.m3 m31 ,
49 i.m4 m41
50 FROM measurement m ,
51 TABLE(sys.odcinumberlist(m1,m2,m3,m4)),
52 interesting I
53 ORDER BY id,
54 id1 ,
55 cvalue
56 ) p
57 WHERE cnt=1
58 ) t
59 WHERE level >1
60 CONNECT BY prior id=id
61 AND prior id1 =id1
62 AND prior rnum <=rnum-1
63 --start with rnum=1
64 ORDER BY id,
65 id1 ,
66 cvalue
67 )
68 ORDER BY 1,2
69 )
70 GROUP BY id
71 ORDER BY 1;
ID REPEAT2 REPEAT3 REPEAT4
1 4 1 0
2 9 5 1
3 6 4 1I am posting the code without number formatting so that it gets easier for you to copy the code...
select id,sum(case when len=1 then 1 else 0 end) repeat2,sum(case when len=2 then 1 else 0 end) repeat3,sum(case when len=3 then 1 else 0 end) repeat4 from
(select id,spath,(LENGTH(spath)-LENGTH(REPLACE(LOWER(spath),',') ))/ LENGTH(',') len from
(select t.*
,ltrim(sys_connect_by_path(cvalue,','),',') spath
from (select p.*,row_number() over (partition by id, id1 order by cvalue) rnum from (SELECT m.id,
m.m1 ,
m.m2 ,
m.m3 ,
m.m4 ,
(SELECT COUNT(*)
FROM interesting q
WHERE q.id=I.id
AND (q.m1 = column_value
OR q.m2 =column_value
OR q.m3 =column_value
OR m4 =column_value)
) cnt ,
column_value cvalue,
i.id id1 ,
i.m1 m11 ,
i.m2 m21 ,
i.m3 m31 ,
i.m4 m41
FROM measurement m ,
TABLE(sys.odcinumberlist(m1,m2,m3,m4)),
interesting I
order by id,id1,cvalue
) p where cnt=1
) t where level>1
connect by prior id=id and prior id1=id1 and prior rnum<=rnum-1
order by id,id1,cvalue) order by 1,2) group by id order by 1Ravi Kumar
Edited by: ravikumar.sv on Sep 15, 2009 3:54 PM
Maybe you are looking for
-
How to detect if the user is using SSL
I use weblogic 5.1 sp6and NES 4.1. Netscape plug-in connects them together. I also install the verisign certificate on the NES 4.1. I want my JSP code to detect if the user is using http or https to visit my site. However, isSecure() will return fals
-
What internal hard drive can I get with 2007 Mac Pro?
Hello, I own a Mac Pro that I purchased sometime Early 2007 and I want to add an additional internal hard drive. I am a little confused as to what my options are after visiting the Apple online store. It seems they do not have a choice for 1 TB drive
-
2 different computers but want January upgrade
Hello - my ancient laptop houses my email (no additional space & not worth more $$) but I sync my tunes etc with my husbands's laptop - both Windows XP. The Apple Store in Toronto said I could buy the upgrade, by loading ITunes onto the ancient lapto
-
HT204053 how do I figure out what my icloud id is if it isn't my apple id?
how do I figure out what my icloud id is if it isn't my apple id?
-
Dear, I am writing regarding mentioned PO 4504101614/00074 , P/N 96468354 We order 3 pcs, we already received 2pcs -> GR (migo)was booked, also IR (miro) for 2pcs was booked, still is open 1pc, but in MD04 show us 2 and 1 = 3pcs. Pls can you explain