Several lines to a format of columns from two tables
Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit ProductionThe difficulty to return several lines simple lines/columns in two tables.
Table 1:
ID BOOK_NBR
1 1001
1 2001
2 1010
3 1020
Table 2:
AUTHOR BOOK_NBR
1001 JOHN_1
2001 JOHN_2
MARY 1010
1020 JUNE
Desired output:
ID BOOK_NBR AUTHOR BOOK_NBR AUTHOR
1 1001 JOHN_1 2001 JOHN_2
2 MARY 1010
3-1020 JUNE
There are an unknown number of BOOK_NBR to one ID.
Any guidance would be appreciated.
Tags: Database
Similar Questions
-
How to match columns from two tables with
Hello:
I have two tables as below:
Table1::(Base Table)
Country | Prefix | Prefix_Length
Travel | 001 | 3
CountryB. 0012 | 4
PaysC | 00443 | 5
CountryD | 0091 | 4
:(Detail Table) table2
The population | Area | Prefix
500 | AreaA | 0015921
1000 | AreaB | 00122
400. AreaC. 00443743
300. ALIS | 0091333
100. AreaA | 001
I need to match these two tables with prefix columns (whose length is not fixed in the two tables: but it starts with 00 in the two tables). Two different countries the prefix may be similar up to a certain length. Thus, Prefix_Length can be used to determine (exactly) how much time should be taken in the search of Table2.
Output:
Country | Prefix | Area | Population
Travel | 001 | AreaA | 600
CountryB. 0012 | AreaB | 1000
PaysC | 00443 | AreaC. 400
CountryD | 0091 | ALIS | 300
Please help me with your valuable comments.
-TenderTry this
with base_table as ( select 'CountryA' country,'001' prefix,3 prefix_length from dual union all select 'CountryB','0012',4 from dual union all select 'CountryC','00443',5 from dual union all select 'CountryD','0091',4 from dual ), detail_table as ( select 10 no_of_call,'0015921' prefix from dual union all select 3,'00122' from dual union all select 50,'00443743' from dual union all select 50,'00443643' from dual union all select 300,'0091333' from dual union all select 60,'001' from dual ) SELECT country, prefix,sum(no_of_call) FROM ( select country, b.prefix,no_of_call, decode(no_of_call,lead(no_of_call,1,0) over(partition by no_of_call order by b.prefix,no_of_call),'y','n') y_or_no from base_table b, detail_table d where b.prefix = substr(d.prefix,1,prefix_length)) where y_or_no !='y' group by country, prefix order by country, prefix;
Published by: Vi on 20 February 2012 01:07
-
Find unmatched columns from two tables
Hello guys,.
I am trying to compare two tables based on a key of the indexed columns.
Here is an example of what I'm trying to achieve:
Table A: A_ID A_Name A_Income A_housecount
Jess 11 9 2
Rauny 4 6 22
Table b: B_ID B_Income B_housecount
11-5-2
22 6 4
In the example above data columns A_ID and B_Id are same in both tables. I'm trying to compare A_Income with B_Income & & A_housecount with B_housecount. The results of this series of samples would be:
11-9-2
11-5-2
as income in the same id is different.
As I have large amount of data in the two tables can you please give me some ideas on how I can get my results? Let me know if the explanation is not clear for you.
Thanks in advanceselect hshold_id,hsold_income,hshold_size, 'abc.' || case count(src1) when 0 then 'demo' else 'hshold' end the_source from (select hshold_id,hsold_income,hshold_size, 1 src1, to_number(null) src2 from abc.hshold union all select hshold_id,hsold_income,hshold_size, to_number(null) src1, 2 src2 from abc.demo ) group by hshold_id,hsold_income,hshold_size having count(src1) != count(src2)
Concerning
Etbin
Edited by: Etbin on 11.2.2011 18:00
correction of alignment -
Delete rows in a table when the columns from two tables match
Hello
I have following two tables.
===========================================
create the table empbooth as
(
Select 1 empid, 1 double cabin Union all the
Select option 2, Union 1 double all the
Select 3, Union 1 double all the
Select option 4, Union 2 double all the
Select option 5, 2 double
);
create the table attsht as
(
Select 1 empid, 240 reg, 0 unpaid all double union
Select option 2, reg 200, 0 unpaid of all the double union
Select 3, 240 reg, 0 unpaid all double them union
Select 4 480 reg, 0 unpaid all double union
Select 5 240 reg, unpaid double 0
);
=================================================
I want to remove rows from attsht where corresponding booth (which is stored in the empbooth table) is 1.
The condition is 'where attsht.empid = empbooth.empid and empbooth.booth = 1 '.
I use oracle 10g.
Help, please
delete from attsht where a.empid in (select b.empid from empbooth b where b.booth = 1)
or
remove from attsht a
where exists (select null
of empbooth b
where b.booth = 1
and b.empid = a.empid)
-
histogram with just a few columns from a table
I want to get a histogram of a few columns from a table (4 - 6-... 22)
-
Update multiple columns from multiple tables in a single UPDATE request
Hello
I'm trying to figure if I'm heading in the right direction.
I want to update multiple columns from multiple tables in a single UPDATE request. Also, I would like to update multiple columns in a table from the tables.
Scenario 1
UPDATE Table2, Table 3 SET T2.Column1 = T1.Column1 ,T2.Column2 = T1.Column2 ,T3.Column2 = T1.Column2 FROM Table1 T1, Table2 T2, Table3 T3 WHERE T1.id = T2.id and T1.id = T3.id
Scenario 2
UPDATE Table3 SET T3.Column1 = T1.Column1 T3.Column2 = T1.Column2 ,T3.Column3 = T2.Column3 ,T3.Column4 = T2.Column4 FROM Table1 T1, Table2 T2, Table3 T3 WHERE T3.id = T1.id and T3.id = T2.id
Hello
For scenario 1, you must write separate instructions UPDATE table2 and table3.
To guard against someone else change one of these tables while you act so you can copy all relevant data in a global temporary table and update this global temporary table table3.
ENGAGE only when two tables have been changed.
You can write a procedure or an INSTEAD OF trigger to do all this.
For scenario 2, you can reference many tables that you need when new table3. It might be more efficient and simpler to use the MERGER rather than UPDATED. For example:
MERGE INTO table3 dst
WITH THE HELP OF)
SELECT t1.id
t1.column1
t1.column2
t2.column3
t2.column4
FROM table1 t1
JOIN table2 t2 ON t1.id = t2.id
) src
WE (dst.id = src_id
WHEN MATCHED THEN UPDATE
SET dst.column1 = src.column1
dst.column2 = src.column2,
dst.column3 = src.column3,
dst.column4 = src.column4,
;
-
How to remove a column from a table in a dell identtiymananger 7.0
How to remove a column from a table in a dell identtiymananger 7.0
Hello
In Version 7 of the removal of a single custom column can be accomplished by a stored procedure, available in the database called: QBM_PColumnDrop
Hope that helps.
Cordially Fatih
-
To find common data in 2 columns from two different tables.
Hello
Could someone help me with a querry to discover common data of 2 columns from two different tables?
Thank you
RajeshTry as below.
select col1 ,col2 from tab1 intersect select col1 ,col2 from tab2;
-
Extraction of data from two tables without discounting
Hi friends,
I have a problem I want to extract data from two tables without discount in the text field when I will enter any value in a text field, then the value of corressponding must come to textfield corressponding.
for example. There are two table A and B.
Table A has Colunm
S_ID number;
C_ID Varchar2 (30);
VARCHAR2 (4) s;
Second table B Colunm name
S_ID number;
What varchar (30);
L_Name varchar (20);
When I enter in a text field then the c_id 101 s_id, dry, first_name and last_name should come to corressponding text without refresh fields.
How can I do that.
Thank you
MauryYou can use Ajax and there are tons of good examples out there for this purpose;
For example [http://apex.oracle.com/pls/otn/f?p=31517:236:1876567353842241] -
Swivel... Several lines in simple row, multiple column
Dear Oracle Guru
I have a table
emp_req_order
the fields are
EmpNo, Deptno, req_order
I need to find the max of Req_order for all dept
so my request was
SELECT max (req_order) emp_req_order Maxorder
Deptno group
put it was
MaxOrder
-----------
45
34
23
17
I want the output of a line like
45 34 23 17
Instead of four rows data must be in a line, but four columns
I searched the forum I even had a proposal as follows:
Max (SELECT Decode(deptno,101,req_order)) const1,
Const2 Max (decode(DEPTNO,102,req_order)),
Const3 Max (decode(DEPTNO,103,req_order)),
Const4 Max (decode(DEPTNO,104,req_order)),
Of emp_req_order
Group By deptno
The output was still in several lines
Kindly guide me in this regard
with the best regards
RSSSSR,
Just drag the group clause for the purpose.
Kind regards
Rob. -
Get columns from the table shown in the iterator
Hello...
I have the table in a collection of standard panel. So, I can show/hide certain columns in the table using the columns in the view menu.
Then I'm trying to do is export to excel (using apache poi) by looping through the table iterator. What I can't do is search if the column is not displayed. I don't want all the columns that are exported without worrying. How can I achieve this?
My bean is similar to the following for loop through the iterator:
BindingContext bindingContext = BindingContext.getCurrent ();
BindingContainer bindingContainer = bindingContext.getCurrentBindingsEntry ();
DCIteratorBinding dcIteratorBinding = (DCIteratorBinding) bindingContainer.get ("EmployeesIterator");
lines [] oracle.jbo.Row = dcIteratorBinding.getAllRowsInRange ();
for (oracle.jbo.Row line: lines) {}
{for (String colName: {row.getAttributeNames ())}
output to excel cell here using row.getAttribute (colName) m:System.NET.SocketAddress.ToString)
}
}
Thank you.
Hello
It's like ask the engine in your car to what colors the seats have. The iterator doesn't know anything about the visible state of a column. If the displayed columns must be determined from the table instance (richeTableau)
The following article solves exactly the requirement that you have: Oracle ADF: Build Your Own it comes with a sample that you can download here: http://www.oracle.com/technetwork/issue-archive/2013/13-jul/o43adf-1940728.zip
Have a look at CustomPanelCollectionBean.java:
The method and code that you want to look for is:
private String getRowHtml (row rw) {}
StringBuffer rowHtmlBuf = new StringBuffer();
Read visible columns in the table of the table instance. This way the
PanelCollection can be used to show/hide columns and exclude
printing to HTML
Table richeTableau = this.getRichTable ();
the list of columns determine the print attributes
The list of columns in
= table.getChildren (); int attrCount = columns.size ();
rowHtmlBuf.append (this.addRowStart ());
for (int i = 0; i)< attrcount;="" i++)="">
for all visible columns, add columns to print
If (((RichColumn) columns.get (i)) .isVisible ()) {}
If (rw.getAttribute (i) instanceof ViewRowSetImpl) {}
ignore the collections of detail used for master/detail example
constraints in British Colombia ADF
} ElseIf (rw.getAttribute (i) instanceof oracle.jbo.domain.Timestamp) {}
shorten date to exclude the infromation times
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
String dateFormatString = sdf.format (((Timestamp) rw.getAttribute (i)) .getData ());
rowHtmlBuf.append (this.addDataCell (dateFormatString));
} else {}
Prnt attribute values and if sure that null values don't raise a NPE. Add a white character to NULL
attribute values
rowHtmlBuf.append (this.addDataCell (rw.getAttribute (i)! = null? rw.getAttribute (i) m:System.NET.SocketAddress.ToString ():))
" "));
}
}
}
rowHtmlBuf.append (this.addRowEnd ());
Return rowHtmlBuf.toString ();
}
You need to access the Rich Table instance (for example using the JSF component binding) to then compare the attribute in the iterator with the visibility of the column
Frank
-
Hi Experts,
I have a DB table has columns of more than 50.
I question this table, it should only return one line at any time. as sqldeveloper below image.
here, I need to build block pl/sql-query, Discover the column in the table as a key and query result as values.
Eg: Key - Value
TASK_EVENT_ID - 1765
EVENT_TYPE - ASR_UPDATE
... etc until all of the columns in my table.
Experts please comment on that point, appreciate your help on this.
Thank you
-Vincent.
Here is an approach using DBMS_SQL to iterate over the columns of key / value to assign... (Little code snipped for brevity)
create or replace procedure (task_expired)
v_store_id in full,
v_task_action_id in full,
v_job_id in full
)
as
-[SNIP code...]
v_sql VARCHAR2 (4000): = ' select * from my_table where PK = 123'; -Your SQL here!
v_v_val VARCHAR2 (4000);
v_n_val NUMBER;
v_d_val DATE;
v_ret NUMBER;
c NUMBER;
d NUMBER;
col_cnt INTEGER.
f BOOLEAN;
rec_tab DBMS_SQL. DESC_TAB;
col_num NUMBER;
vAsString VARCHAR2 (4000);
BEGIN
-[SNIP code...]
Message_properties. CORRELATION: = "EDF_EVENT";
MSG: = SYS. AQ$ _JMS_BYTES_MESSAGE. Construct();
Msg.set_string_property ('queueName', ' shipping/csi_cth');
Msg.set_string_property ('MODE', 'CR8');
c: = DBMS_SQL. OPEN_CURSOR;
DBMS_SQL. PARSE (c, v_sql, DBMS_SQL. NATIVE);
d: = DBMS_SQL. Execute (c);
DBMS_SQL. DESCRIBE_COLUMNS (c, col_cnt, rec_tab);
1.col_cnt J
LOOP
CASE rec_tab (j) .col_type
WHEN 2 THEN
DBMS_SQL. DEFINE_COLUMN (c, j, v_n_val); -Number
WHEN 12 CAN
DBMS_SQL. DEFINE_COLUMN (c, j, v_d_val); -Date
ON THE OTHER
DBMS_SQL. DEFINE_COLUMN (c, j, v_v_val, 2000); -Else treat as varchar2
END CASE;
END LOOP;
LOOP
v_ret: = DBMS_SQL. FETCH_ROWS (c);
WHEN OUTPUT v_ret = 0;
1.col_cnt J
LOOP
-Fetch each column to the correct data type based on coltype
CASE rec_tab (j) .col_type
WHEN 2 THEN
DBMS_SQL. COLUMN_VALUE (c, j, v_n_val);
vAsString: = to_char (v_n_val);
WHEN 12 CAN
DBMS_SQL. COLUMN_VALUE (c, j, v_d_val);
vAsString: = to_char (v_d_val, ' DD/MM/YYYY HH24:MI:SS');
ON THE OTHER
DBMS_SQL. COLUMN_VALUE (c, j, v_v_val);
vAsString: = v_v_val;
END CASE;
Msg.set_string_property (rec_tab (j) .col_name, vAsString);
END LOOP;
END LOOP;
DBMS_SQL. CLOSE_CURSOR (c);
DBMS_AQ. ENQUEUE (queue_name-online 'cbus.aqjms_common',
Enqueue_options => Enqueue_options,
Message_properties => Message_properties,
Payload-online msg,
Msgid => Message_handle);
dbms_output.put_line ('00 Msgid =' |) Message_handle);
dbms_output.put_line('===Done=');
-[SNIP code...]
END;
/
-
Extract single line transformed from two tables
I have two tables T1 and T2 with the same set of columns. The columns are C1, C2, C3, COND1. I need to issue a query that returns a line transformed in order to respect the following rules:
1. the returned line may contain values from both tables based on the values of column in table T1.
2 return the column C1 in table T1; If it is NULL, then return to any value is present in the column C1 of T2.
3. article 2 above apply to all columns like C1, C2 etc.
I published the following query. The problem is that if a subquery does not reach the entire query fails. Someone help me please. Probably there is another simple method.
SELECT NVL (T1.c1, T2.c1) c1, c2 (T1.c2, T2.c2) NVL NVL (T1.c3, T2.c3) c3
FROM (SELECT c1, c2, c3
FROM T1
WHERE cond1 = 'T10') T1
(SELECT c1, c2, c3
THE T2
WHERE cond1 = "T200") T2;
Hello
user4274403 wrote:
I have two tables T1 and T2 with the same set of columns. The columns are C1, C2, C3, COND1. I need to issue a query that returns a line transformed in order to respect the following rules:
1. the returned line may contain values from both tables based on the values of column in table T1.
2 return the column C1 in table T1; If it is NULL, then return to any value is present in the column C1 of T2.
3. article 2 above apply to all columns like C1, C2 etc.
I published the following query. The problem is that if a subquery does not reach the entire query fails. Someone help me please. Probably there is another simple method.
SELECT NVL (T1.c1, T2.c1) c1, c2 (T1.c2, T2.c2) NVL NVL (T1.c3, T2.c3) c3
FROM (SELECT c1, c2, c3
FROM T1
WHERE cond1 = 'T10') T1
(SELECT c1, c2, c3
THE T2
WHERE cond1 = "T200") T2;
Are you saying that if there is no row in t1 that satisfy the condition cond1 = "T10", then you want to keep seeing the lines (and values) of the t2?
And even, if there is no row in t2 that satisfy the cond1 = "T200" condition, then you want to keep seeing the lines (and values) from t1?
If so, this looks like a job for a full outer join.
You can change the join in a full outer join as follows:
SELECT NVL (T1.c1, T2.c1) AS c1
, NVL (T1.c2, T2.c2) C2
NVL (T1.c3, T2.c3) AS c3
FROM T1
FULL OUTER JOIN T2 ON t1.cond1 = 'T10 '.
AND t2.cond1 = 'T200.
WHERE t1.cond1 = 'T10 '.
OR t2.cond1 = "T200"
;
If you would care to post CREATE TABLE and INSERT instructions for some examples of data, then I could test this.
What happens if no table has all the lines that have good values in cond1?
-
transfer of some columns from one table to another table...?
I had 2 table... .one is PAYMAST n other TBL... In PEXMAST & TBL 10 collar each, I had and I want to transfer 4 columns of TBL to PEXMAST...
How do I do this. ???A table must be regarded as line and column.
When you say a column, it should be associated with a line.
Here is an example
Let's say I have two table T1 (ID, NAME) and T2 (ID, Name1)
Now if I say I want to spend for T2 T1 name1, what I will do?
1 create a column name1 in T1.
alter table t1 add name1 varchar2(50)
2. put up-to-date T1 by joining T1.ID and T2.ID like that.
update t1 set t1.name1 = (select t2.name1 from t2 where t2.id = t1.id)
As you can see you need a column ID to define the relationships between the two table T1 and T2. If you have one, you can do the same with yours.
-
Remove the column from the table compress
I try drop column from table DPRUEBA, with compression option:
Any idea?SQL>select * from v$version 2 / BANNER ---------------------------------------------------------------- Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi PL/SQL Release 10.2.0.4.0 - Production CORE 10.2.0.4.0 Production TNS for Linux: Version 10.2.0.4.0 - Production NLSRTL Version 10.2.0.4.0 - Production 5 filas seleccionadas. Transcurrido: 00:00:00.09 SQL> SQL>CREATE TABLE DPRUEBA 2 (COL1 NUMBER, 3 COL2 NUMBER) COMPRESS 4 / Tabla creada. Transcurrido: 00:00:00.06 SQL> SQL>ALTER TABLE DPRUEBA DROP COLUMN COL2 2 / ALTER TABLE DPRUEBA DROP COLUMN COL2 * ERROR en línea 1: ORA-39726: operación de agregación/borrado de columnas no soportada en tablas comprimidas Transcurrido: 00:00:00.06
You can always do something like this
SQL> CREATE TABLE DPRUEBA 2 (COL1 NUMBER, 3 COL2 NUMBER) COMPRESS 4 / Table created. SQL> SQL> ALTER TABLE DPRUEBA DROP COLUMN COL2 2 / ALTER TABLE DPRUEBA DROP COLUMN COL2 * ERROR at line 1: ORA-12996: cannot drop system-generated virtual column SQL> SQL> create table new_DPRUEBA 2 as 3 select col1 4 from DPRUEBA 5 / Table created. SQL> SQL> drop table DPRUEBA 2 / Table dropped. SQL> SQL> rename new_DPRUEBA to DPRUEBA 2 / Table renamed. SQL> SQL> desc DPRUEBA Name Null? Type ----------------------------------------- -------- ---------------------- COL1 NUMBER SQL> SQL> SQL> drop table DPRUEBA 2 / Table dropped. SQL> SQL>
Note: you must take care of the constraints and triggers, and others
Maybe you are looking for
-
Emergency assistance: can't remember the password!
Hi all, I use an iPod Touch 4th gen and it is running iOS 7. When I turn on my iPod Touch I tells me to enter in a 4digit passcode, but I do not remember what and I don't want to get locked into the iPod Touch. I have my AppleID so can I use this som
-
I don't know how or when I get a new phone with the upgrade program! Help!
I have the iPhone Upgrade Program. I signed up last year and I have a 6 s more. I want a 7 (I have later), but it wouldn't kill me if it does not work. This is my experience: 0) I went to 2 stores in the last three days and called APPLE 1-800-MY - I
-
Is it possible to remote access to my Mac Boot Camp partition?
I know this may sound stupid, because my Mac partition is offline due to Boot Camp, but I just wanted to know if it was possible to remote access and open terminal applications / mac from my Mac at a training Camp. I don't mean for the use of Google
-
Problem with the translation into Chinese of msgrte.txt
With the help of LabWindows/CVI 2012 SP1. I am trying to create a Chinese version of one of our applications. I have a msgrte.txt that has been translated into Chinese, and I ran countmsg.exe on update magic numbers. Countmsg.exe reports of success,
-
I got a call today two microsoft workers online / call center agents calling from London, although they all Indian accents. They made me see the viewer certmgr.msc and events and showed some errors. Then they said to install teamviewer. They said all