Mutiple Rows from a Single Row using SQL
How can i get Multiple rows from a single row using sql ?
Example : one row contains the complete address separated by delimiter say comma (,) as address1,address2,city,state,zip,country
I want to split this row and get the output in multiple rows as address1 address2 city state zip country using sql query.
Thanks,
Hi,
The solution above assumes that the |-delimited entries always contain at least one character. If you have a string like
1 Elm Street|||Sioux City|IA||it will think 'Siuox City' is address2.
If you have empty entries, like that, then you need something a little more complicated:
INSERT INTO table2
( address1
, address2
, address3
, city
, state
, postal
, country
SELECT SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 1), 2) -- address1
, SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 2), 2) -- address2
, SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 3), 2) -- address3
, SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 4), 2) -- city
, SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 5), 2) -- state
, SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 6), 2) -- postal
, SUBSTR (REGEXP_SUBSTR ('|' || txt, '\|[^|]*', 1, 7), 2) -- country
FROM table1
;
Similar Messages
-
Creating two rows from a single row information
Hi,
I have data that will always be returned as a single row from a join of tables t1, t2.
However I want the single row to be split into two rows. i.e First row containing some fields and second row containing th remaining fields.
I think there might be a thread already existing. Can you please point me in the right direction if it is.
select t1.c1, t1.c2, t2.c1, t2.c2
from t1, t2
where t1.c3 = t2.c3
I expect the output 2 rows like the following
t1.c1 t2.c1
t1.c2 t2.c2
ThanksSQL>WITH t1 AS (SELECT 't1c1_' || ROWNUM AS c1, 't1c2_' || ROWNUM AS c2, ROWNUM AS c3
2 FROM DUAL
3 CONNECT BY LEVEL <= 3),
4 t2 AS (SELECT 't2c1_' || ROWNUM AS c1, 't2c2_' || ROWNUM AS c2, ROWNUM AS c3
5 FROM DUAL
6 CONNECT BY LEVEL <= 3),
7 t3 AS (SELECT t1.c1 AS c11, t1.c2 AS c12, t2.c1 AS c21, t2.c2 AS c22, ROWNUM AS r
8 FROM t1, t2
9 WHERE t1.c3 = t2.c3)
10 SELECT a, b
11 FROM (SELECT c11 AS a, c21 AS b, r, 1 AS s
12 FROM t3
13 UNION ALL
14 SELECT c12, c22, r, 2 AS s
15 FROM t3)
16 ORDER BY r, s;
A B
t1c1_1 t2c1_1
t1c2_1 t2c2_1
t1c1_2 t2c1_2
t1c2_2 t2c2_2
t1c1_3 t2c1_3
t1c2_3 t2c2_3Urs -
How do I insert multiple rows from a single form ...
How do I insert multiple rows from a single form?
This form is organised by a table. (just as in an excel format)
I have 20 items on a form each row item has five field
+++++++++++ FORM AREA+++++++++++++++++++++++++++++++++++++++++++++++++++++
+Product| qty In | Qty Out | Balance | Date +
+------------------------------------------------------------------------+
+Item1 | textbox1 | textbox2 | textbox3 | date +
+ |value = $qty_in1|value= &qty_out1|value=$balance1|value=$date1 +
+------------------------------------------------------------------------+
+Item 2 | textbox1 | textbox2 | textbox4 | date +
+ |value = $qty_in2|value= $qty_out1|value=$balance2|value=$date2 +
+------------------------------------------------------------------------+
+ Item3 | textbox1 | textbox2 | textbox3 | date +
+------------------------------------------------------------------------+
+ contd | | | +
+------------------------------------------------------------------------+
+ item20| | | | +
+------------------------------------------------------------------------+
+ + + SUBMIT + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Database Structure
+++++++++++++++++
+ Stock_tabe +
+---------------+
+ refid +
+---------------+
+ item +
+---------------+
+ Qty In +
+---------------+
+ Qty Out +
+---------------+
+ Balance +
+---------------+
+ Date +
+++++++++++++++++
Let's say for example user have to the use the form to enter all 10 items or few like 5 on their stock form into 4 different textbox field each lines of your form, however these items go into a "Stock_table" under Single insert transaction query when submit button is pressed.
Please anyone help me out, on how to get this concept started.Hello,
I have a way to do this, but it would take some hand coding on your part. If you feel comfortable hand writing php code and doing manual database calls, specificaly database INSERT calls you should be fine.
Create a custom form using the ADDT Custom Form Wizard that has all the rows and fields you need. This may take a bit if you are adding the ability for up to 20 rows, as per your diagram of the form area. The nice thing about using ADDT to create the form is that you can setup the form validation at the same time. Leave the last step in the Custom Form Wizard blank. You can add a custom database call here, but I would leave it blank.
Next, under ADDT's Forms Server Behaviors, select Custom Trigger. At the Basic tab, you enter your custom php code that will be executed. Here you are going to want to put your code that will check if a value has been entered in the form and then do a database INSERT operation on the Stock_table with that row. The advanced tab lets you set the order of operations and the name of the Custom Trigger. By default, it is set to AFTER. This means that the Custom Trigger will get executed AFTER the form data is processed by the Custom Form Transaction.
I usually just enter TEST into the "Basic" tab of the Custom Trigger. Then set my order of operations in the "Advanced" tab and close the Custom Trigger. Then I go to the code view for that page in Dreamweaver and find the Custom Trigger function and edit the code manually. It's much easier this way because the Custom Trigger wizard does not show you formatting on the code, and you don't have to keep opening the Wizard to edit and test your code.
Your going to have to have the Custom Trigger fuction do a test on the submitted form data. If data is present, then INSERT into database. Here's a basic example of what you need to do:
In your code view, the Custom Trigger will look something like this:
function Trigger_Custom(&$tNG) {
if($tNG->getColumnValue("Item_1")) {
$item1 = $tNG->getColumnValue("Item_1");
$textbox1_1 = $tNG->getColumnValue("Textbox_1");
$textbox1_2 = $tNG->getColumnValue("Textbox_2");
$textbox1_3 = $tNG->getColumnValue("Textbox_3");
$date1 = $tNG->getColumnValue("Textbox_3");
$queryAdd = "INSERT INTO Stock_table
(item, Qty_In, Qty_Out, Balance, Date) VALUES($item1, $textbox1_1, $textbox1_2, $textbox1_3, $date1)"
$result = mysql_query($queryAdd) or die(mysql_error());
This code checks to see if the form input field named Item_1 is set. If so, then get the rest of the values for the first item and insert them into the database. You would need to do this for each row in your form. So the if you let the customer add 20 rows, you would need to check 20 times to see if the data is there or write the code so that it stops once it encounters an empty Item field. To exit a Custom Trigger, you can return NULL; and it will jump out of the function. You can also throw custom error message out of triggers, but this post is already way to long to get into that.
$tNG->getColumnValue("Item_1") is used to retrieve the value that was set by the form input field named Item_1. This field is named by the Custom Form Wizard when you create your form. You can see what all the input filed names are by looking in the code view for something like:
// Add columns
$customTransaction->addColumn("Item_1", "STRING_TYPE", "POST", "Item_1");
There will be one for each field you created with the Custom Form Wizard.
Unfortunately, I don't have an easy way to do what you need. Maybe there is a way, but since none of the experts have responded, I thought I would point you in a direction. You should read all you can about Custom Triggers in the ADDT documentation/help pdf to give you more detailed information about how Custom Triggers work.
Hope this helps.
Shane -
Select a single row from a billion row table
This is a fictitious scenario, how would you write a select statement on a table with a billion rows. It never returns anything,right? Somebody was suggesting a stored procedure.
As an example : Assuming a Table with columns Account(int), TransDate(DateTime), TransNum(int) and few other columns. I need a transaction that happened on 03-05-2014 8:15PM. Clustered index on Account. Non- clustered on TransDate.
I was suggested to create a stored procedure, inside the SP you have 3 parameters: min_date, max_date, avg= min_date+max_date/2. You create a loop and feed the avg value to the max_date or min_date depending on where the row is. This is a suggestion
that I am not clear my-self but wanted to see if you guys can help me develop this idea.
Also please suggest how you would do it in your world. You guys could have much better ideas probably much simpler one's. Thanks in advance.
svkI basically just need transaction for one particular datetime. Not any span. One of our senior developers suggested that a simple select statement takes for ever to return a single row from a billion rows and suggested a vague idea as above.
Either there is a suitable index on the column, and the SELECT will be fast.
Or there is no index on the column, and in that case it will take quite some time to find the row. The only reason to loop is that you don't want to take out a table lock, but in that case you would do something like looping one account at a time. Looping
over different time values will only mean that you will scan the table multiple times.
Erland Sommarskog, SQL Server MVP, [email protected] -
Display distinct rows from Oracle table without using "DISTINCT" keyword.
How to retrieve distinct rows from oracle table without using 'DISTINCT' keyword in SQL?
Thanks in advance.
MihirWelcome to the forum.
Besides GROUP BY you can use UNIQUE instead of DISTINCT as well, but that's probably not wanted here ;) , and the ROW_NUMBER() analytic:
SQL> create table t as
2 select 1 col1 from dual union all
3 select 1 from dual union all
4 select 2 from dual union all
5 select 3 from dual union all
6 select 4 from dual union all
7 select 4 from dual;
Table created
SQL> select col1 from t;
COL1
1
1
2
3
4
4
6 rows selected
SQL> select distinct col1 from t;
COL1
1
2
3
4
SQL> select unique col1 from t;
COL1
1
2
3
4
SQL> select col1 from t group by col1;
COL1
1
2
3
4
SQL> select col1
2 from ( select col1
3 , row_number() over (partition by col1 order by col1) rn
4 from t
5 )
6 where rn=1;
COL1
1
2
3
4 -
Merging two rows into a single row
Hi ,
I wish to merge few columns of tow rows into a single row.
if i use union it gives two rows as o/p.
What is the exact sql statement for that?
ThanksHi Sridhar,
This is my code for merging and i used union.
Suggest me good solution.
CREATE OR REPLACE VIEW INSPECTINT.INSPECT_LOC_TRACKING_RPT_VIEW AS
SELECT
VEN_COMPANY_NAME VEN_COMPANY_NAME,
VEN_COMPANY_NAME_2 VEN_COMPANY_NAME_2,
VEN_CONTACT_FIRST_NAME VEN_CONTACT_FIRST_NAME,
VEN_CONTACT_MIDDLE_NAME VEN_CONTACT_MIDDLE_NAME,
VEN_CONTACT_LAST_NAME VEN_CONTACT_LAST_NAME,
VEN_ADDRESS_LINE_1 VEN_ADDRESS_LINE_1,
VEN_ADDRESS_LINE_2 VEN_ADDRESS_LINE_2,
VEN_CITY VEN_CITY,
VEN_CNT_COUNTY_CODE VEN_CNT_COUNTY_CODE,
VEN_STC_STATE_CODE VEN_STC_STATE_CODE,
VEN_ZIP_CODE VEN_ZIP_CODE,
VEN_PHONE_NO_1 VEN_PHONE_NO_1,
VEN_PHONE_EXTN_1 VEN_PHONE_EXTN_1,
VEN_PHONE_NO_2 VEN_PHONE_NO_2,
VEN_PHONE_EXTN_2 VEN_PHONE_EXTN_2,
VEN_FAX_NO_1 VEN_FAX_NO_1,
VEN_VENDOR_NO VEN_VENDOR_NO,
VEN_APV_AP_VENDOR_ID VEN_APV_AP_VENDOR_ID,
VEN_EMAIL_ADDRESS VEN_EMAIL_ADDRESS,
--all these should be null
to_number(NULL) PHY_LCN_PARAMETER_ID,
to_char(NULL) PHY_LCN_CURRENT_ADDRESS_IND,
to_char(NULL) PHY_LCN_STATUS_CODE,
to_char(NULL) PHY_LCN_LTY_LOCATION_TYPE,
to_char(NULL) PHY_LCN_ADT_ADDRESS_TYPE,
to_char(NULL) PHY_LCN_HOUSE_NO,
to_char(NULL) PHY_LCN_ADDRESS_LINE_1,
to_char(NULL) PHY_LCN_ADDRESS_LINE_2,
to_char(NULL) PHY_LCN_CITY,
to_char(NULL) PHY_LCN_STC_STATE_CODE,
to_char(NULL) PHY_LCN_ZIP_CODE,
to_char(NULL) PHY_LCN_CNT_COUNTY_CODE,
to_date(NULL) PHY_END_DATE,
to_number(NULL) PHY_LCN_VEN_VENDOR_ID_GTA,
to_char(NULL) PHY_LCN_SUB_LOCATION_GTA,
to_char(NULL) PHY_LCN_DIRECTION_GTA,
---all these should be null
to_char(NULL) LOW_LCN_PARAMETER_ID,
to_char(NULL) LOW_LCN_CURRENT_ADDRESS_IND,
to_char(NULL) LOW_LCN_STATUS_CODE,
to_char(NULL) LOW_LCN_LTY_LOCATION_TYPE,
to_char(NULL) LOW_LCN_ADT_ADDRESS_TYPE,
to_char(NULL) LOW_LCN_HOUSE_NO,
to_char(NULL) LOW_LCN_ADDRESS_LINE_1,
to_char(NULL) LOW_LCN_ADDRESS_LINE_2,
to_char(NULL) LOW_LCN_CITY,
to_char(NULL) LOW_LCN_STC_STATE_CODE,
to_char(NULL) LOW_LCN_ZIP_CODE,
to_char(NULL) LOW_LCN_CNT_COUNTY_CODE,
to_char(NULL) LOW_LCN_LANDLORD,
to_number(NULL) LOW_LCN_LANDLORD_PHONE,
to_date(NULL) LOW_END_DATE,
to_char(NULL) LOW_LCN_SUB_LOCATION_GTA,
to_char(NULL) LOW_LCN_DIRECTION_GTA
FROM LOCATIONS LOC , VENDORS VEN
WHERE LOC.LCN_VEN_VENDOR_ID_GTA IS NOT NULL
AND LOC.LCN_VEN_VENDOR_ID_GTA = VEN_VENDOR_ID
AND LOC.LCN_LTY_LOCATION_TYPE ='AS'
UNION ALL
SELECT
to_char(NULL) VEN_COMPANY_NAME,
to_char(NULL) VEN_COMPANY_NAME_2,
to_char(NULL) VEN_CONTACT_FIRST_NAME,
to_char(NULL) VEN_CONTACT_MIDDLE_NAME,
to_char(NULL) VEN_CONTACT_LAST_NAME,
to_char(NULL) VEN_ADDRESS_LINE_1,
to_char(NULL) VEN_ADDRESS_LINE_2,
to_char(NULL) VEN_CITY,
to_char(NULL) VEN_CNT_COUNTY_CODE,
to_char(NULL) VEN_STC_STATE_CODE,
to_char(NULL) VEN_ZIP_CODE,
to_number(NULL) VEN_PHONE_NO_1,
to_number(NULL) VEN_PHONE_EXTN_1,
to_number(NULL) VEN_PHONE_NO_2,
to_number(NULL) VEN_PHONE_EXTN_2,
to_number(NULL) VEN_FAX_NO_1,
to_char(NULL) VEN_VENDOR_NO,
to_char(NULL) VEN_APV_AP_VENDOR_ID,
to_char(NULL) VEN_EMAIL_ADDRESS,
decode(lcn_adt_address_type,'P',to_number(LCN_PARAMETER_ID),to_number(NULL)) PHY_LCN_PARAMETER_ID,
decode(lcn_adt_address_type,'P',LCN_CURRENT_ADDRESS_IND,to_char(NULL)) PHY_LCN_CURRENT_ADDRESS_IND,
decode(lcn_adt_address_type,'P',LCN_STATUS_CODE,to_char(NULL)) PHY_LCN_STATUS_CODE,
decode(lcn_adt_address_type,'P',LCN_STATUS_CODE,to_char(NULL)) PHY_LCN_LTY_LOCATION_TYPE,
decode(lcn_adt_address_type,'P',LCN_ADT_ADDRESS_TYPE,to_char(NULL)) PHY_LCN_ADT_ADDRESS_TYPE,
decode(lcn_adt_address_type,'P',LCN_HOUSE_NO,to_char(NULL)) PHY_LCN_HOUSE_NO,
decode(lcn_adt_address_type,'P',LCN_ADDRESS_LINE_1,to_char(NULL)) PHY_LCN_ADDRESS_LINE_1,
decode(lcn_adt_address_type,'P',LCN_ADDRESS_LINE_2,to_char(NULL)) PHY_LCN_ADDRESS_LINE_2,
decode(lcn_adt_address_type,'P',LCN_CITY,to_char(NULL)) PHY_LCN_CITY,
decode(lcn_adt_address_type,'P',LCN_STC_STATE_CODE,to_char(NULL)) PHY_LCN_STC_STATE_CODE,
decode(lcn_adt_address_type,'P',LCN_ZIP_CODE,to_char(NULL)) PHY_LCN_ZIP_CODE,
decode(lcn_adt_address_type,'P',LCN_CNT_COUNTY_CODE,to_char(NULL)) PHY_LCN_CNT_COUNTY_CODE,
decode(lcn_adt_address_type,'P',END_DATE,to_char(NULL)) PHY_END_DATE,
decode(lcn_adt_address_type,'P',LCN_VEN_VENDOR_ID_GTA,to_char(NULL)) PHY_LCN_VEN_VENDOR_ID_GTA,
decode(lcn_adt_address_type,'P',LCN_SUB_LOCATION_GTA,to_char(NULL)) PHY_LCN_SUB_LOCATION_GTA,
decode(lcn_adt_address_type,'P',LCN_DIRECTION_GTA,to_char(NULL)) PHY_LCN_DIRECTION_GTA,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_PARAMETER_ID,to_char(NULL)) LOW_LCN_PARAMETER_ID,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_CURRENT_ADDRESS_IND,to_char(NULL)) LOW_LCN_CURRENT_ADDRESS_IND,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_STATUS_CODE,to_char(NULL)) LOW_LCN_STATUS_CODE,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_LTY_LOCATION_TYPE,to_char(NULL)) LOW_LCN_LTY_LOCATION_TYPE,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_ADT_ADDRESS_TYPE,to_char(NULL)) LOW_LCN_ADT_ADDRESS_TYPE,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_HOUSE_NO,to_char(NULL)) LOW_LCN_HOUSE_NO,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_ADDRESS_LINE_1,to_char(NULL)) LOW_LCN_ADDRESS_LINE_1,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_ADDRESS_LINE_2,to_char(NULL)) LOW_LCN_ADDRESS_LINE_2,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_CITY,to_char(NULL)) LOW_LCN_CITY,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_STC_STATE_CODE,to_char(NULL)) LOW_LCN_STC_STATE_CODE,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_ZIP_CODE,to_char(NULL)) LOW_LCN_ZIP_CODE,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_CNT_COUNTY_CODE,to_char(NULL)) LOW_LCN_CNT_COUNTY_CODE,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_LANDLORD,to_char(NULL)) LOW_LCN_LANDLORD,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_LANDLORD_PHONE,to_char(NULL)) LOW_LCN_LANDLORD_PHONE,
decode(LCN_ADT_ADDRESS_TYPE,'D',END_DATE,to_char(NULL)) LOW_END_DATE,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_SUB_LOCATION_GTA,to_char(NULL)) LOW_LCN_SUB_LOCATION_GTA,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_DIRECTION_GTA,to_char(NULL)) LOW_LCN_DIRECTION_GTA
FROM LOCATIONS LOC
WHERE (LCN_LTY_LOCATION_TYPE ='AS' OR LCN_ADT_ADDRESS_TYPE='D')
AND LCN_CURRENT_ADDRESS_IND ='Y'
thanks -
Need help converting multipe rows in a single row
I want to convert multiple rows into a single row. Oracle version is 10.2
SQL> with abc
2 as
3 (select 1 a, 2 b, 3 c from dual union
4 select 4, 5, 6 from dual)
5 select * from abc;
A B C
1 2 3
4 5 6I want the output as
A B C
1,4 2,5 3,6Thanks,
Gangadhar
Edited by: GR on Feb 6, 2012 9:35 PMGR wrote:
I want to convert multiple rows into a single row. Oracle version is 10.2
SQL> with abc
2 as
3 (select 1 a, 2 b, 3 c from dual union
4 select 4, 5, 6 from dual)
5 select * from abc;
A B C
1 2 3
4 5 6I want the output as
A B C
1,4 2,5 3,6
You haven't specified if there's a particular order to the data, so I've assumed one...
SQL> ed
Wrote file afiedt.buf
1 with t as (select 1 a, 2 b, 3 c from dual union
2 select 4, 5, 6 from dual)
3 --
4 -- end of test data
5 --
6 select trim(',' from sys_connect_by_path(a,',')) as a
7 ,trim(',' from sys_connect_by_path(b,',')) as b
8 ,trim(',' from sys_connect_by_path(c,',')) as c
9 from (select a,b,c,row_number() over (order by a) as rn from t)
10 where connect_by_isleaf = 1
11 connect by rn = prior rn+1
12* start with rn = 1
SQL> /
A B C
1,4 2,5 3,6
SQL> -
Multiple rows in a single row.
I want to know how can I store the values of multiple rowe in a single row.for an example..
machine name manchine no frequency month
Lathe MOO1 yearly jan
Lathe MOO1 halfyearly feb
Lathe MOO1 weekly march and so on
I want this in a single row..
like jan feb march
Lathe M001 yearly halfyearly weekly.
and in a single row I want this as per the month specified .
In my report I have 12 months distribution for each machine.Taruna,
Just make sure understand the scenario correctly. Would you like to store the row in DB like this:
Lathe MOO1 yearly jan,feb,mar
then you expect to show in the report like this:
Lathe MOO1 yearly jan
Lathe MOO1 yearly feb
Lathe MOO1 yearly mar
Yes, you can do it this way, but somehow break the 1st principle of DB schema design - Atomic
Of course, you need to convert jan,feb,mar into list and display for each row.
string monthStr = "jan,feb,mar";
string [] months = monthStr.Split(",");
Kind Regards
-Yatsea -
How to insert multiple rows in a single shot using insert command?
Hi,
If we insert one row, we can use "insert into" command. I want to insert multiple rows into the table in a single shot. Is there any SQL command for insert multiple rows into the table?
Plese give the solution.
Thanks,
chelladuraiIf you would like to do it with SQL, this would be one of the ways to achive it:
SQL*Plus: Release 10.2.0.4.0 - Production on Fri Sep 25 10:12:59 2009
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, Data Mining and Real Application Testing options
SQL>
SQL> desc leap
Name Null? Type
FIRST_PRICE NUMBER(16,6)
NEXT_PRICE NUMBER(16,6)
SQL>
SQL> select * from leap;
no rows selected
SQL>
SQL>
SQL> !vi multirow_insert.sql
SQL> !cat multirow_insert.sql
insert into leap(first_price, next_price) values (1,2);
insert into leap(first_price, next_price) values (3,4);
insert into leap(first_price, next_price) values (5,6);
SQL>
SQL> @multirow_insert.sql
1 row created.
1 row created.
1 row created.
SQL> commit;
Commit complete.
SQL>
SQL>
SQL> select * from leap;
FIRST_PRICE NEXT_PRICE
1 2
3 4
5 6
SQL> -
How to pass all rows from a VO to PL/SQL API
Hi,
My requirement is to pass all the rows of a View Object (shown on Page as a Table) to PL/SQL API. I am not allowed to pass information row by row using single array (JTF_VARCHAR2_TABLE_200).
How do we pass multidimensional information to the PL/SQL API. Any pointers to this would be welcome.
ThanksSumeet,
sorry for delay in code snippet.
Here is a sample code assuming you want to send 2 attributes name and desc from your VO rows.
I wrote the code during weekend and hence i doubt its working ;)
public oracle.sql.ARRAY getVoArray()
Connection conn = this.tx.getJdbcConnection();
OAViewObject vo = (OAViewObject)this.appModule.findViewObject("TestVO");
try
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor
("TABLE_OF_BELOW_ROW_TYPE"
,conn
StructDescriptor voRowStructDesc = StructDescriptor.createDescriptor
("XXX_TO_BE_SEND_ROW_TYPE"
,conn
TestVORowImpl row = null;
String name;
String desc;
int fetchedRowCount = vo.getFetchedRowCount();
STRUCT [] finalStruct = new STRUCT[fetchedRowCount];
Object[] attrField = new Object[1];
RowSetIterator entityIdIter1 = vo.createRowSetIterator("entityIdIter1");
if (fetchedRowCount > 0)
entityIdIter1.setRangeStart(0);
entityIdIter1.setRangeSize(fetchedRowCount);
for (int i = 0; i < fetchedRowCount; i++)
row = (TestVORowImpl )entityIdIter1.getRowAtRangeIndex(i);
name = (String)row.getName();
desc = (String)row.getDesc();
attrField[0] = (String)name;
finalStruct[i] = new STRUCT(voRowStructDesc, conn, attrField);
entityIdIter1.closeRowSetIterator();
oracle.sql.ARRAY yourArray = new oracle.sql.ARRAY(descriptor, conn, finalStruct);
return yourArray;
return null;
catch(java.sql.SQLException ex)
throw OAException.wrapperException(ex);
Let me know if you are still having issues.
--Saroj -
SQL Query to convert multiple rows to a single row output
I have the following sql query;
SELECT B.ClientID,
B.BillNo, B.[BillDate],
B.CurrencyCode,
B.BAmount
FROM tblCompanyDetails CD
CROSS
APPLY (
SELECT TOP 5 B1.ClientID,
B1.[BillNumber],
B1.[BillDate], B1.[CurrencyCode] AS CCY,
B1.[BillAmount]
FROM tblBills B1
WHERE ROUND(B1.[BillAmount],2)<>0
AND B1.ClientID=CD.CompanyID
AS B
WHERE CD.ContactId=235405
ORDER
BY B.ClientID,B.BillNo
DESC
This gives me the following row output;
ClientID
BillNo
BillDate
CurrencyCode
BAmount
94466
425616
2015-04-07
GBP
5000
94466
424517
2015-01-15
GBP
6000
94466
424455
2014-10-15
GBP
4000
However, I would like the ouput to appear like this;
ClientID
BillNo1
BillDate
CCY
BAmount
BillNo2
BillDate
CCY
BAmount
BillNo3
BillDate
CCY
BAmount
94466
425616
2015-04-07
GBP
5000
424517
2015-01-15
GBP
6000
424455
2014-10-15
GBP
4000I have tried to create a sample based on your question
CREATE TABLE MyTable
ClientID INT ,
BillNo INT,
BillDate DATE,
CurrencyCode varchar(5),
BAmount INT
INSERT INTO MyTable
VALUES (94466,425616,'2015-04-07','GBP',5000),
(94466,424517,'2015-01-15','GBP',6000),
(94466,424455,'2014-10-15','GBP',4000)
Then I have used another table to put ranking in that, you can actually tweak your statement to include rank also
CREATE TABLE RowTable
ClientID INT ,
BillNo INT,
BillDate DATE,
CurrencyCode varchar(5),
BAmount INT,
Ranking INT
INSERT INTO RowTable
SELECT * , ROW_NUMBER() OVER (ORDER BY ClientID) as row
FROM MyTable
Once your data is ready then execute below dynamic query
DECLARE @cols AS NVARCHAR(MAX),
@query AS NVARCHAR(MAX)
select @cols = STUFF((SELECT ',' + QUOTENAME(col+cast(Ranking as varchar(10)))
from RowTable
cross apply
select 'BillNo', 1 union all
select 'BillDate', 2 union all
select 'CurrencyCode', 3 union all
select 'BAmount' , 4
) c (col, so)
group by col, so, Ranking
order by Ranking, so
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)')
,1,1,'')
set @query = 'SELECT ClientId,' + @cols + '
from
select clientid, col+cast(Ranking as varchar(10)) col, value
from RowTable
cross apply
SELECT ''BillNo'', cast(BillNo as varchar(20)) union all
SELECT ''BillDate'', cast(BillDate as varchar(20)) union all
SELECT ''CurrencyCode'', CurrencyCode union all
SELECT ''BAmount'', CAST(BAmount as varchar(10))
) c (col, value)
) x
pivot
max(value)
for col in (' + @cols + ')
) p '
execute sp_executesql @query;
Output:
Hope this will help. -
How to expande multiple table row from a single button
I am trying to create an expanding table that expands multiple rows when a single button is clicked.
So far I have managed to create a table that expands a single row at a time using -
click
this.parent.parent.instanceManager.insertInstance();
I also tried using the following code from an existing woking file that adds a column when a button is clicked -
Table1.HeaderRow._Col3SF.addInstance(0);
Table1.Row1._Col3SF.addInstance(0);
Table1.Row2._Col3SF.addInstance(0);
Table1.Row3._Col3SF.addInstance(0);
I adapted the code to suite my own file -
click
form1.Sub1.Sub3.Table1.Row1.addInstance(0);
form1.Sub1.Sub3.Table1.Row2.addInstance(0);
form1.Sub1.Sub3.Table1.Row3.addInstance(0);
form1.Sub1.Sub3.Table1.Row4.addInstance(0);
form1.Sub1.Sub3.Table1.Row5.addInstance(0);
However I receive the following error -
click Invalid property get operation; subform doesn't have property 'addInstance'
Regards MaxwellI managed to acheive what I needed to do using LCD's Action Builder.
The Action builder makes it so easy to create advanced content.
I selected my button obect for the list, then chose - create add a new instance,
then chose my table from the list.
I now have a table with multiple rows that expand when a single button is clicked, fantastic!
Regards Maxwell -
Extract Multiple Rows from a Single Table into a Single Row in a New Table
I have a table in a database that contains contact data like name, address, phone number, etc.
The folks who designed the database and wrote the application wrote it so that all contact records are placed in that table, regardless of contact type. In fact, the contacts table does not even have a column for "type" even though there are many
different types of contacts present in that table.
I am trying to write a mail merge style report in SRSS, that gets sent to a specific type of contact, based on criteria provided that must be obtained from another table, and that data is then used to get back to a specific set of contacts from the contacts
table.
The attached file directly below describes my problem and all related information in an extremely detailed way.
SRSSMailMergeIssue.pdf
Unless there is a way to make a SRSS Tablix point to two different data sets in SRSS, it looks like I have to combine multiple rows from the same table into a new table.
If anyone can review the details in the attached pdf file and possibly point me in the direction I need to run to solve this probelm, I would greatly appreciate it.
I also included a document (below) that shows the tables I reference in the probelm description.
dbtables.pdfI found a solution.... and posted it below
select
dk.ucm_docketnumber [UCM DocketNumber],
dk.ucm_docketid [UCM DocketID],
vc.FirstName [Victim FirstName],
vc.MiddleName [Victim MiddleName],
vc.LastName [Victim LastName],
vc.Suffix [Victim Suffix],
vc.Address1_Line1 [Victim AddressLine1],
vc.Address1_Line2 [Victim AddressLine2],
vc.Address1_Line3 [Victim AddressLine3],
vc.Address1_City [Victim City],
vc.Address1_StateOrProvince [Victim StateProvince],
vc.Address1_PostalCode [Victim Postalcode],
oc.FirstName [Offender FirstName],
oc.MiddleName [Offender MiddleName],
oc.LastName [Offender LastName],
oc.Suffix [Offender Suffix],
oc.Address1_Line1 [Offender AddressLine1],
oc.Address1_Line2 [Offender AddressLine2],
oc.Address1_Line3 [Offender AddressLine3],
oc.Address1_City [Offender City],
oc.Address1_StateOrProvince [Offender StateProvince],
oc.Address1_PostalCode [Offender Postalcode],
pc.FirstName [Arresting Officer FirstName],
pc.MiddleName [Arresting Officer MiddleName],
pc.LastName [Arresting Officer LastName],
pc.Address1_Line1 [Arresting Officer AddressLine1],
pc.Address1_Line2 [Arresting Officer AddressLine2],
pc.Address1_Line3 [Arresting Officer AddressLine3],
pc.Address1_City [Arresting Officer City],
pc.Address1_StateOrProvince [Arresting Officer StateProvince],
pc.Address1_PostalCode [Arresting Officer Postalcode]
FROM ucm_docket dk
left outer join ucm_victim v on dk.ucm_docketid = v.ucm_docketnumber
left outer join contact vc on vc.contactid = v.ucm_victimlookup
left outer join ucm_offender o on o.ucm_offenderid = dk.ucm_offenderlookup
left outer join contact oc on oc.contactid = o.ucm_individualid
left outer join contact pc on pc.contactid = dk.ucm_ArrestingOfficerLookup
WHERE (dk.ucm_docketnumber = @DocketNUM) -
Delete a row from a data object using an AQ-driven EMS
Hello, technetwork.
I need to show the contents of a table that changes frequently (inserts, updates and deletes) at ORDBMS 10g in my BAM dashboard.
What i have done is:
- Create two different queue tables, queues.
- Create two triggers: one for "AFTER insert or UPDATE" and the other for "BEFORE DELETE".
- Create two EMS, one configured to Upsert operations and the other to Delete.
- The Upsert EMS works, but the Delete EMS does not.
- Both EMS Metrics say that they work fine and commit the messages i send to the ADC.
- Testing showed records are populated and updated in the ADC but never deleted.
There is a detailed user case for "Creating an EMS Against Oracle Streams AQ JMS Provider" in the Fusion Midleware Developer's Guide for SOA Suite, but it deals only with Upserts. I am using the last versions of SOA suite and Weblogic. The official support has no information either.
I hope writing a web service client isn't the only way to delete a row from a data object. Am i missing something? Any help will be much appreciated.
My EMS config:
Initial Context Factory: weblogic.jndi.WLInitialContextFactory.
JNDI Service Provider URL: t3://<spam>:80.
Topic/Queue Connection Factory Name: jms/BAMAQTopicCF.
Topic/Queue Name: jms/ProdGlobalBAMD_flx.
JNDI Username: .
JNDI Password: .
JMS Message Type: TextMessage.
Durable Subscriber Name (Optional): BAM_ProdGlobalBAMD.
Message Selector (Optional): .
Data Object Name: /bam/ProdGlobalBAM_flx.
Operation: Delete.
Batching: No.
Transaction: No.
Start when BAM Server starts: No.
JMS Username (Optional): .
JMS Password (Optional): .
XML Formatting
Pre-Processing
Message Specification
Message Element Name: row
Column Value
Element Tag
Attribute
Source to Data Object Field Mapping
Key Tag name Data Object Field
. BARCODE. BarCode.
Added my EMS configRam_J2EE_JSF wrote:
How to accomplish this using JavaScript?Using Javascript? Well, you know, Javascript runs at the client side and intercepts on the HTML DOM tree only. The JSF code is completely irrelevant. Open your JSF page in your favourite webbrowser and view the generated HTML source. Finally just base your Javascript function on it. -
Multiple rows Converge to Single row and join
Hi Folks,
I am facing a tricky challenge to join a table with multiple rows and converge into a single row (based on ID, period) and join with another table to get a single row. Let me explain.
Table 1: DTL_TABLE (id, period, course, names, title, type)
1 2010 mat john null null
1 2010 mat jim null null
1 2010 cam null officer null
1 2010 cam null Prof null
1 2010 phy null null Inclass
1 2010 phy null null Online
Join with
Table 2: ID_TABLE(id, period, Loc, Dept, Code)
1 2010 nj 101 CC.
Output format (id, period, course, names, title, type, Loc, Dept, Code)
result : 1 2010 mat,cam,phy john,jim officer,prof inclass,online nj 101 CC
I have created all the DDLs and DMLs if that help. Kindly let me know if a Join SQL query is possible.
Thank you,
Aj
CREATE TABLE DTL_TABLE
ids VARCHAR2 (10),
period VARCHAR2 (10),
course VARCHAR2 (10),
names VARCHAR2 (10),
title VARCHAR2 (10),
TYPE VARCHAR2 (10)
INSERT INTO DTL_TABLE
VALUES ('1',
'2010',
'mat',
'jim',
NULL,
NULL);
INSERT INTO DTL_TABLE
VALUES ('1',
'2010',
'mat',
'john',
NULL,
NULL);
INSERT INTO DTL_TABLE
VALUES ('1',
'2010',
'mat',
'kale',
NULL,
NULL);
INSERT INTO DTL_TABLE
VALUES ('1',
'2010',
'cam',
NULL,
'officer',
NULL);
INSERT INTO DTL_TABLE
VALUES ('1',
'2010',
'cam',
NULL,
'prof',
NULL);
INSERT INTO DTL_TABLE
VALUES ('1',
'2010',
'phy',
NULL,
NULL,
'inclass');
INSERT INTO DTL_TABLE
VALUES ('1',
'2010',
'phy',
NULL,
NULL,
'online');
COMMIT;
CREATE TABLE id_table
ids VARCHAR2 (10),
period VARCHAR2 (10),
loc VARCHAR2 (10),
dept VARCHAR2 (10),
code VARCHAR2 (10)
INSERT INTO id_table
VALUES ('1',
'2010',
'nj',
'101',
'cc');
COMMIT;Aj09 wrote:
Hi Folks,
I am facing a tricky challenge to join a table with multiple rows and converge into a single row (based on ID, period) and join with another table to get a single row. Let me explain.
Table 1: DTL_TABLE (id, period, course, names, title, type)
1 2010 mat john null null
1 2010 mat jim null null
1 2010 cam null officer null
1 2010 cam null Prof null
1 2010 phy null null Inclass
1 2010 phy null null Online
Join with
Table 2: ID_TABLE(id, period, Loc, Dept, Code)
1 2010 nj 101 CC.
Output format (id, period, course, names, title, type, Loc, Dept, Code)
result : 1 2010 mat,cam,phy john,jim officer,prof inclass,online nj 101 CC
I have created all the DDLs and DMLs if that help. Kindly let me know if a Join SQL query is possible.
SELECT TBL.id,
DTLperiod,
course,
names,
title,
TYPE,
Loc,
Dept,
Code
FROM ID_TABLE TBL,
DTL_TABLE DTL
WHERE TBL.ID = DTL.ID
AND TBL.PERIOD = DTL.PERIOD; it not good to use RESERVED WORDS like "ID" or "TYPE" as column names
Maybe you are looking for
-
How can I copy a home movie onto another DVD with my MacBook Pro?
How can I copy a home movie onto another DVD with my MacBook Pro?
-
Disable Add Attach Button in the Interactive PDF form
Hi all, Can you please let me know if is possible to disable the Add Attachment Button for the interactive form? I need to show the attachment icon on the toolbar (setShowOption method from IWDPDFDocumentAppearance interface) but I need to disable th
-
ERROR 1604 when trying to restore my ipod Touch
Hi all, I am trying to do a restore on my ipod Touch(32GB)but get the message "Unable to restore...unknown error 1604." Anyone know what this error is? I'm trying to restore and every time it comes up with this error and what is happening is that it
-
TS1424 "Cannot connect to iTunes Store" - what's the problem?
I am unable to buy apps or update apps from the iTunes Store. Internet works. Gmail freezes when I click on links.
-
Im running newest IoS on my ipod (4th gen, 5.1.1) and after i reset my ipod it lost most of the apps it started with, like camera and safari. How can i recover these?