Insert two tables simultaneously
I want to insert records into two or several other table with a single statement. Is this possible in Oracle XE?How can I combine the following in a single statement?
insert into addressbook(name) values('test');
insert into email(email) values('[email protected]');
Thank you and best regards
Hello
It is possible to merge several inserts with 'all' BLOCinstruction, check
INSERT ALL
INTO addressbook(name)
VALUES('test')
INTO email(email)
VALUES('[email protected]')
SELECT * FROM dual
General synthax so is;
INSERT ALL
INTO VALUES ()
INTO VALUES ()
...
Concerning
Tags: Database
Similar Questions
-
Insert two tables with a single query (same ID)
Hello
I want to insert two tables at the same time (with a single request) provided that both records get inserted with the same identifier. How can I do this?
(a) insert in the first table, retrieve the id (can be usingTable Movies id name Table Category movie_id cat_type
and then insert into another table.my_sequence.currval
question: He brings three queries to the Database, I also suspect that when several people trying to insert there is a problem, I could be wrong.
I have no other idea.
Greatly appreciated!think you need to do as an anonymous pl/sql block.
Dim cn As New OracleConnection("DataSource = xx'; user id = xx; password = xx;") Try 'build the anonymous pl/sql Dim sb as New System.Text.StringBuilder sb.Append("declare") sb.Append(" l_N number;") sb.Append("begin") sb.Append("insert into movies (id,name) values (my_sequence.nextval, 'film1') returning id into l_N;") sb.Append( "insert into category values (l_N, 'Category type');") sb.Append(" END;") 'create commd object Dim cmd as New OracleCommand(sb.ToString,cn) cmd.Connection.Open() cmd.ExecuteNonQuerry() cmd.Connection.Close() cmd.dispose() Catch ex as Exception blah blah blah End try
Published by: pollywog on May 28, 2010 10:48
Published by: pollywog on May 28, 2010 10:49
-
I have a form with two fields that are added to a table of each. One or both can be filled and when the form is submitted, I use the code of the action below. Am I do it correctly? Thank you:
<!-if the form is sent to make the next->
< isDefined ("form.updatebtn") cfif >
<!-if the prive1 field is filled this - >< cfif FORM. GTE prive1 1 >
< CFQUERY name = "addsector" datasource = "salesdb" >
INSERT IN INDUSTRIES)
SECTORSNOM
)
VALUES)
< cfqueryparam cfsqltype = "cf_sql_longvarchar" value = "#trim (form." "Prive1) #" = null "" #isSECTORS1Null # "(/ >)"
< / CFQUERY >
< CFLOCATION URL = "member_welcome.cfm" ><!-if the ministere1 field is filled this - >
< cfelseif FORM. GTE ministere1 1 >
< CFQUERY name = "adddivision" datasource = "salesdb" >
INSERT IN THE DIVISION)
MINISTERE1
)
VALUES)
< cfqueryparam cfsqltype = "cf_sql_longvarchar" value = "#trim (form." "Ministere1) #" = null "" #isDEPARTMENT1Null # "/ >"
)
< / CFQUERY >
< CFLOCATION URL = "member_welcome.cfm" ><!-if the two fields are filled this - >
< cfelse >
< CFQUERY name = "addsector" datasource = "salesdb" >
INSERT IN INDUSTRIES)
SECTORSNOM
)
VALUES)
< cfqueryparam cfsqltype = "cf_sql_longvarchar" value = "#trim (form." "Prive1) #" = null "" #isSECTORS1Null # "(/ >)"
< / CFQUERY >< CFQUERY name = "adddivision" datasource = "salesdb" >
INSERT IN THE DIVISION)
MINISTERE1
)
VALUES)
< cfqueryparam cfsqltype = "cf_sql_longvarchar" value = "#trim (form." "Ministere1) #" = null "" #isDEPARTMENT1Null # "/ >"
)
< / CFQUERY >< / cfif >
The else block - seems duplication to me. The code is more or less equivalent to this shorter version:
INSERT INTO INDUSTRIES (SECTORSNOM)
VALUES (
INSERT IN DIVISION (DEPARTMENT1)
VALUES (
) -
Mr President.
I create a form based on two tables that have sequences also. When I create insert only row is inserted in the fields in table first and second fields of the table are empty. Why?
the page source is
<?xml version='1.0' encoding='UTF-8'?> <ui:composition xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:af="http://xmlns.oracle.com/adf/faces/rich" xmlns:f="http://java.sun.com/jsf/core"> <af:panelFormLayout id="pfl1"> <af:group id="Group"> <af:inputText value="#{bindings.VoucherId.inputValue}" label="#{bindings.VoucherId.hints.label}" required="#{bindings.VoucherId.hints.mandatory}" columns="#{bindings.VoucherId.hints.displayWidth}" maximumLength="#{bindings.VoucherId.hints.precision}" shortDesc="#{bindings.VoucherId.hints.tooltip}" id="it1"> <f:validator binding="#{bindings.VoucherId.validator}"/> <af:convertNumber groupingUsed="false" pattern="#{bindings.VoucherId.format}"/> </af:inputText> <af:inputDate value="#{bindings.VoucherDate.inputValue}" label="#{bindings.VoucherDate.hints.label}" required="#{bindings.VoucherDate.hints.mandatory}" columns="#{bindings.VoucherDate.hints.displayWidth}" shortDesc="#{bindings.VoucherDate.hints.tooltip}" id="id1"> <f:validator binding="#{bindings.VoucherDate.validator}"/> <af:convertDateTime pattern="#{bindings.VoucherDate.format}"/> </af:inputDate> <af:inputText value="#{bindings.Credit.inputValue}" label="#{bindings.Credit.hints.label}" required="#{bindings.Credit.hints.mandatory}" columns="#{bindings.Credit.hints.displayWidth}" maximumLength="#{bindings.Credit.hints.precision}" shortDesc="#{bindings.Credit.hints.tooltip}" id="it2"> <f:validator binding="#{bindings.Credit.validator}"/> </af:inputText> </af:group> <af:group id="g1"> <af:inputText value="#{bindings.Lineitem.inputValue}" label="#{bindings.Lineitem.hints.label}" required="#{bindings.Lineitem.hints.mandatory}" columns="#{bindings.Lineitem.hints.displayWidth}" maximumLength="#{bindings.Lineitem.hints.precision}" shortDesc="#{bindings.Lineitem.hints.tooltip}" id="it3"> <f:validator binding="#{bindings.Lineitem.validator}"/> <af:convertNumber groupingUsed="false" pattern="#{bindings.Lineitem.format}"/> </af:inputText> <af:inputText value="#{bindings.VoucherId1.inputValue}" label="#{bindings.VoucherId1.hints.label}" required="#{bindings.VoucherId1.hints.mandatory}" columns="#{bindings.VoucherId1.hints.displayWidth}" maximumLength="#{bindings.VoucherId1.hints.precision}" shortDesc="#{bindings.VoucherId1.hints.tooltip}" id="it4"> <f:validator binding="#{bindings.VoucherId1.validator}"/> <af:convertNumber groupingUsed="false" pattern="#{bindings.VoucherId1.format}"/> </af:inputText> <af:inputText value="#{bindings.Debit.inputValue}" label="#{bindings.Debit.hints.label}" required="#{bindings.Debit.hints.mandatory}" columns="#{bindings.Debit.hints.displayWidth}" maximumLength="#{bindings.Debit.hints.precision}" shortDesc="#{bindings.Debit.hints.tooltip}" id="it5"> <f:validator binding="#{bindings.Debit.validator}"/> </af:inputText> <af:inputText value="#{bindings.Credit1.inputValue}" label="#{bindings.Credit1.hints.label}" required="#{bindings.Credit1.hints.mandatory}" columns="#{bindings.Credit1.hints.displayWidth}" maximumLength="#{bindings.Credit1.hints.precision}" shortDesc="#{bindings.Credit1.hints.tooltip}" id="it6"> <f:validator binding="#{bindings.Credit1.validator}"/> </af:inputText> <af:inputText value="#{bindings.Particulars.inputValue}" label="#{bindings.Particulars.hints.label}" required="#{bindings.Particulars.hints.mandatory}" columns="#{bindings.Particulars.hints.displayWidth}" maximumLength="#{bindings.Particulars.hints.precision}" shortDesc="#{bindings.Particulars.hints.tooltip}" id="it7"> <f:validator binding="#{bindings.Particulars.validator}"/> </af:inputText> <af:inputText value="#{bindings.Amount.inputValue}" label="#{bindings.Amount.hints.label}" required="#{bindings.Amount.hints.mandatory}" columns="#{bindings.Amount.hints.displayWidth}" maximumLength="#{bindings.Amount.hints.precision}" shortDesc="#{bindings.Amount.hints.tooltip}" id="it8"> <f:validator binding="#{bindings.Amount.validator}"/> <af:convertNumber groupingUsed="false" pattern="#{bindings.Amount.format}"/> </af:inputText> </af:group> <f:facet name="footer"> <af:button text="Submit" id="b1"/> <af:button actionListener="#{bindings.CreateInsert.execute}" text="CreateInsert" disabled="#{!bindings.CreateInsert.enabled}" id="b2"/> <af:button actionListener="#{bindings.Commit.execute}" text="Commit" disabled="#{!bindings.Commit.enabled}" id="b3"/> <af:button actionListener="#{bindings.Rollback.execute}" text="Rollback" disabled="#{!bindings.Rollback.enabled}" immediate="true" id="b4"> <af:resetActionListener/> </af:button> </f:facet> </af:panelFormLayout> </ui:composition>
Concerning
Go to your VO Wizard, select the tab of the entity and to check if both the EO is editable or not.
See you soon
AJ
-
ORA-01776: I can not insert a view consisting of two tables
Hello:
I'm doing an insert on a view composed by the join of two tables (services and employees) and it failed.
The view is the following:
CREATE OR REPLACE FORCE VIEW 'EMPDPTO' ('EMPLOYE_ID', 'LAST_NAME', 'EMAIL', 'HIRE_DATE', 'JOB_ID""DEPARTMENT_ID","DEPARTMENT_NAME") AS
(
SELECT employe_id, last_name, email, hire_date, job_id, d.department_id, department_name
E employees, departments d
WHERE e.department_id = d.department_id
);
My insert command
INSERT INTO empdpto
VALUES (743, 'Bermejo', '[email protected]', 12 December 09 ', 'IT_PROG', 10, 'Administration');
get an ORA-01776: it is not possible to modify more than one table of base through a union to join.
On the other side, I saw in the documentation which, in certain circumstances, can do an insert on a complex view.
Is it possible to do an insert on a view consisting of two tables? Under what conditions?
Thank youReference of SQL CREATE VIEW http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_8004.htm#i2065510 views editable Notes section
>
If you want a view of join to be updated, then all of the following conditions must be met:*
The DML must assign only one underlying table of the join.
*An insert, the view does not create WITH CHECK OPTION, and all columns in which the values are inserted must come from a key preserved table. A key-preserved table is one for which each primary key or unique key in the base table value is also unique in the view of the join.
*For an UPDATE statement, the view does not create WITH CHECK OPTION, and all updated columns must be extracted from a preserved key table.
>
The first condition is not true for the view that you created.
Edited by: P. Forstmann on 26 Jan. 2010 20:17
-
Insert data into two tables in a single transaction
Hi all
I have a problem with the development of features.
Background:
I have two tables: OFFER_HEADER and OFFER_CONTENT
For now, user must insert and commit the OFFER_HEADER (single-row view), then content becomes accessible and OFFER_CONTENT(multi-row view) can be filled. It is done by selecting the save form PRODUCTS and integration of values in OFFER_CONTENT. Product data can be changed on the canvas of CONTENT form.
My goal:
I know this isn't a practical way to implement the functionality. I want to insert all the data (header and content) in a single transaction. What is the best way to do it?
Thanks in advance,
Best regards
BartekHai,
The error is now with the primary key. In order to check the value of the primary key as part of the operation.
Kind regards
Manu.
-
Help in mandatory query - pulling data from two tables and inserting a
Hi all
I need your help for the modification of the query to get the desired result.
I have two tables A and b. using source Insert and select the command, I need to extract data from tables A and B, then insert and C.
Data and table structures are available below.
Table (Source Table)
Status of payment $
MUL DC 20
ONLY DC 20
ONLY 40 PA
MUL NY 50
Table B (Source Table)
State of lang units
E DC 10
S DC 10
NY E 5
PA S 5
Based on query, I need the values in table C as mentioned below.
Table C (Table of Destination) (necessary output query must also be as below)
The State value
PA 8
DC 1
My query is
INSERT INTO C(STATE,VALUE)
SELECT A.STATE, SUM ($) /SUM (UNITS)
OF A, B
WHERE PAYMENT = "SINGLE".
AND A.STATE = B.STATE
GROUP OF A.STATE, B.STATE
But the output I get is
PA 8
DC 2
Essentially to DC, I should get 1, i.e., for payment only $ DC is 20 and divided by 20 DC must be 1.
Let me know where I'm missing.Hello
It will work you need to add units in the group by clause
SELECT a.state, SUM (dollars) / units FROM a, (SELECT state, SUM (units) units FROM b GROUP BY state) sub WHERE payment = 'SINGLE' AND a.state = sub.state GROUP BY a.state, units;
Concerning
-
Creating records from two Tables at the same time...
I would be very grateful if someone could help with the following query.
I have two Tables, Tbl1 and Tbl2. Tbl1 has the following columns: -.
Tbl1_Unique_ID, Description
Tbl1_Unique_ID is of type ' * number *' and ' * PK * ', Description is of type' * Varchar2 *'.
Tbl2 has the following columns: -.
Tbl2_Unique_ID, Description, Tbl1_Unique_ID
Tbl2_Unique_ID is of type ' * number *' and is the ' * PK * ', Description is of type' * Varchar2 *' and Tbl1_Unique_ID is of type ' * number *', is a ' * foreign key *' and is the ' * primary key *' from Tbl1.
While I can create a page to display and create folders in Tbl1, I'm not course coding required to view and create records Tbl1 and Tbl2 simultaneously, as well as regarding the two together at the same time.
I know that it involves one ' * INSERT *' statement, but I have problems the correct SQL query.
Can anyone provide any assistance will be appreciated.Have you tried to create a form master / detail page? Because it seems that is what you need...
-
I have two tables I want to fix the end to end. If I use the version table it creates an annexed table which is not what I want. essntially im doing the opposite of WBS. are there features that fit this description?
in fact, I just found out 'insert into array' worked for me. I'll try you method too next time
-
How to join two tables if you transpose the rows, columns and rows in one of the table
Hi guys,.
can someone help me please in the write request
I have two tables
Agents and Agent phones but in the agent phones table for the id of an agent it displays 4 rows because one of the column there types of different phones (office, mobile, home, fax)
So instead of display 4 rows, I used max(case...) to convert rows to columns
now how to reach it with another table
Requirement:
Database: 11.2.0.2.0
create the table AGENT_PHONE
(
agent_id NUMBER (20) not null,
agent_type_code VARCHAR2 (10) not null,
agent_type_prefix VARCHAR2 (10) not null,
Phone_Number VARCHAR2 (16) not null,
phone_type_code VARCHAR2 (10) not null
)
CREATE TABLEAGENTS
(
agent_id NUMBER (20) not null,
agent_type_code VARCHAR2 (10) not null,
agent_type_prefix VARCHAR2 (10) not null,
NAME VARCHAR2 (40) NOT NULL
)
INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)
VALUES (29709, ARE ', 'OFFICE', '4805551436', 'CELL');
INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)
VALUES (29709, ARE ', 'OFFICE', '1111111111', 'PHONE');
INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)
VALUES (29709, ARE ', 'OFFICE', '2223334444',' OFF');
INSERT INTO AGENT_PHONE(AGENT_ID,AGENT_TYPE_CODE,AGENT_TYPE_PREFIX,PHONE_NUMBER,PHONE_TYPE_CODE)
VALUES (29709, ARE ', 'OFFICE', '5556667788', 'FAX');
INSERT INTO VALUES AGENTS
(29709, ARE ', 'OFFICE', 'FLY');
INSERT INTO VALUES AGENTS
(1234, ARE ', 'OFFICE', 'MIKE');
SELECT * FROM AGENT_PHONES
AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX PHONE_NUMBER PHONE_TYPE_CODE ---------------------------------------------------------------------------------------------
29709 RE OFFICE 4805551436 CELL 29709 RE OFFICE 1111111111 PHONE 29709 RE OFFICE 2223334444 OFF 29709 RE OFFICE 5556667788 FAX
SELECT * AGENTS
AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX NAME
29709 RE OFFICE ROB 1234 RE OFFICE MIKE
This is so the data we have in both table
Now, I transposed rows to columns in the table of agent phones so I used the following query
SELECT AP. AGENT_ID,. AGENT_TYPE_CODE,. AGENT_TYPE_PREFIX.
MAX (CASE WHEN AP. PHONE_TYPE_CODE = 'CELL' THEN AP. PHONE_NUMBER END) AS CELL.
MAX (CASE WHEN AP. PHONE_TYPE_CODE = 'OFF' THEN AP PHONE_NUMBER END) AS TURNED OFF.
MAX (CASE WHEN AP. PHONE_TYPE_CODE = 'FAX' THEN AP. PHONE_NUMBER END) LIKE FAX,.
MAX (CASE WHEN PHONE_TYPE_CODE = 'PHONE'. THEN AP PHONE_NUMBER END) AS PHONE
AGENT_PHONE AP
WHERE AP. AGENT_ID = 29709
GROUP OF AP. AGENT_ID, AP. AGENT_TYPE_CODE, AP. AGENT_TYPE_PREFIX.
AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX CELL OFF FAX PHONE 1 29709 RE OFFICE 4805551436 2223334444 5556667788 1111111111 My question is how this to join the agents table so that my output should be like this...
I want to display all the results in the table of the Agent, even if they are not in the table of agent phones. As you can see there are other agent id 1234 is also populated
AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX NAME AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX CELL PHONE OFF FAX --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
29709 RE OFFICE ROB 29709 RE OFFICE 4805551436 1111111111 2223334444 5556667788 1234 RE OFFICE MIKE Currently, I run this query and I get the output as below
SELECT *.
AGENTS HAS
LEFT OUTER JOIN AGENT_PHONE AP
ON A.AGENT_ID = AP. AGENT_ID
AND A.AGENT_TYPE_CODE = AGENT_TYPE_CODE.
AND A.AGENT_TYPE_PREFIX = AGENT_TYPE_PREFIX.
AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX NAME AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX PHONE_NUMBER PHONE_TYPE_CODE 1 29709 RE OFFICE ROB 29709 RE OFFICE 4805551436 CELL 2 29709 RE OFFICE ROB 29709 RE OFFICE 1111111111 PHONE 3 29709 RE OFFICE ROB 29709 RE OFFICE 2223334444 OFF 4 29709 RE OFFICE ROB 29709 RE OFFICE 5556667788 FAX 5 1234 RE OFFICE MIKE I want id 29709 agent in a line with 1234 agent also id to display
You can rotate your phone number of agent in columns
Select *.
of AGENT_PHONE
pivot)
min (PHONE_NUMBER)
for PHONE_TYPE_CODE in ('CELL' as a 'CELL', 'PHONE' like 'PHONE', 'OFF' in the 'OFF', 'FAX' as 'FAX')
)
AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX CELL PHONE OFF FAX 29709 RE OFFICE 4805551436 1111111111 2223334444 5556667788 Then you can join to view inline or CTE
with AGENT_PHONE_PIVOT like)
Select *.
of AGENT_PHONE
pivot)
min (PHONE_NUMBER)
for PHONE_TYPE_CODE in ('CELL' as a 'CELL', 'PHONE' like 'PHONE', 'OFF' in the 'OFF', 'FAX' as 'FAX')
)
)
SELECT *.
AGENTS HAS
LEFT OUTER JOIN AGENT_PHONE_PIVOT AP
ON A.AGENT_ID = AP. AGENT_ID
AND A.AGENT_TYPE_CODE = AGENT_TYPE_CODE.
AND A.AGENT_TYPE_PREFIX = AGENT_TYPE_PREFIX.
AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX NAME AGENT_ID AGENT_TYPE_CODE AGENT_TYPE_PREFIX CELL PHONE OFF FAX 29709 RE OFFICE ROB 29709 RE OFFICE 4805551436 1111111111 2223334444 5556667788 1234 RE OFFICE MIKE - - - - - - - Is that what you're looking for?
-
Join two tables for desired out put
Hello
I have two tables with structures below:
TAB1:
LEAD_NUM (PRIMARY KEY), IMPERATIVE_1, IMPERATIVE_2, IMPERATIVE_3, IMPERATIVE_4
LEAD_NUM IMPERATIVE_1 IMPERATIVE_2 IMPERATIVE_3 IMPERATIVE_4 34HVJ CXM NULL VALUE DGH KKK TAB2:
LEAD_NUM (FOREIGN KEY), ACCOUNT_NAME, FISCAL_YEAR
LEAD_NUM ACCOUNT_NAME FISCAL_YEAR 34HVJ ATT 2010 34HVJ ATT 2011 34HVJ ATT 2012 I need the output in the format below:
ACCOUNT_NAME LEAD_NUM FISCAL_YEAR IMPERATIVES ATT 34HVJ 2010 CXM, DGH, KKK ATT 34HVJ 2011 CXM, DGH, KKK ATT 34HVJ 2012 CXM, DGH, KKK Can anyone help me please with the query?
Thanks in advance:
Arpit
create table TAB1
(
Key elementary school/LEAD_NUM varchar2 (100)
IMPERATIVE_1 varchar2 (100),
IMPERATIVE_2 varchar2 (100),
IMPERATIVE_3 varchar2 (100),
IMPERATIVE_4 varchar2 (100)
);
insert into tab1 values ("34HVJ", "CXM", "NULL", "DGH" 'KKK');
create table TAB2
(
LEAD_NUM varchar2 (100),
Account_name varchar2 (100)
NUMBER OF FISCAL_YEAR
);
ALTER TABLE TAB2
ADD CONSTRAINT fk_PerOrders
FOREIGN KEY (LEAD_NUM)
TAB1 (LEAD_NUM) REFERENCES
INSERT INTO VALUES TAB2 ('34HVJ', 'ATT', 2010);
INSERT INTO VALUES TAB2 ('34HVJ', 'ATT', 2011);
SELECT t2.account_name, t2.lead_num, t2.fiscal_year,
RTRIM (TRIM (CASE WHEN t1.imperative_1 IS NULL or t1.imperative_1 = 'NULL' THEN "ELSE t1.imperative_1 |)) ',' END |
CASE WHEN t1.imperative_2 IS NULL or t1.imperative_2 = 'NULL' THEN ' ELSE t1.imperative_2 | ',' END |
CASE WHEN t1.imperative_3 IS NULL or t1.imperative_3 = 'NULL' THEN ' ELSE t1.imperative_3 | ',' END |
CASE WHEN t1.imperative_4 IS NULL or t1.imperative_4 = 'NULL' THEN ' ELSE t1.imperative_4 | (',' END), ',') requirements
OF tab1 t1, t2 tab2
WHERE t1.lead_num = t2.lead_num
ORDER BY t2.fiscal_year
Answer: -.
-
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?
-
sqlloader to load two tables of the single data file in a single operation
Oracle 11.2.0.3 SE - One
Oracle Linux 5.6
I don't know if I need a second set of eyes or if I am missing something.
Problem: Given a file of text csv with header and detail records (identified by the first field in the file) use sql loader to load the header and detail of the tables in a single operation.
The header record is to take, but the detail records are rejected by omitting the WHEN clause.
More comments after reading through the exhibits:
In view of these two tables:
SQL > desc EDSTEST_HEADER
Name Null? Type
----------------------------------------- -------- ----------------------------
EDSTEST_HEADER_ID NOT NULL NUMBER
REC_TYPE VARCHAR2 (10)
SOLD_TO_ACCOUNT VARCHAR2 (50)
SCAC_RECEIVER_ID VARCHAR2 (50)
FORMAT_TYPE VARCHAR2 (10)
CLIENT_NAME VARCHAR2 (100)
CUSTOMER_PICKUP_ADDRESS VARCHAR2 (100)
CUSTOMER_PICKUP_CITY VARCHAR2 (50)
CUSTOMER_PICKUP_STATE VARCHAR2 (10)
CUSTOMER_PICKUP_ZIP VARCHAR2 (50)
INSERT_USER VARCHAR2 (50)
DATE OF INSERT_USER_DATE
INSERT_STATUS_CODE VARCHAR2 (10)
SQL > desc EDSTEST_DETAIL
Name Null? Type
----------------------------------------- -------- ----------------------------
EDSTEST_DETAIL_ID NOT NULL NUMBER
NUMBER OF EDSTEST_HEADER_ID
REC_TYPE VARCHAR2 (10)
SHIP_TO_NAME VARCHAR2 (100)
SHIP_TO_ADDRESS VARCHAR2 (100)
SHIP_TO_CITY VARCHAR2 (50)
SHIP_TO_STATE VARCHAR2 (10)
SHIP_TO_ZIP VARCHAR2 (50)
STATUS_OR_APPT_REASON_CD VARCHAR2 (10)
EVENT_DESCRIPTION VARCHAR2 (50)
SHIPMENT_STATUS_CD VARCHAR2 (10)
SHIPMENT_EVENT_DATE VARCHAR2 (10)
SHIPMENT_EVENT_TIME VARCHAR2 (10)
EVENT_TIME_ZONE VARCHAR2 (30)
EVENT_CITY VARCHAR2 (100)
EVENT_STATE VARCHAR2 (50)
EVENT_ZIP VARCHAR2 (50)
CUSTOMER_CONFIRM VARCHAR2 (100)
DELIVERY_CONFIRM VARCHAR2 (100)
TRACKING_NUMBER VARCHAR2 (50)
MAIL_REC_WEIGHT VARCHAR2 (20)
MAIL_REC_WEIGHT_CD VARCHAR2 (10)
MAIL_RED_QTY VARCHAR2 (10)
INSERT_USER VARCHAR2 (50)
DATE OF INSERT_USER_DATE
INSERT_STATUS_CODE VARCHAR2 (10)
In light of this data file:
Oracle: mydb$ cat eds_edstest.dat
HDR, 0005114090, MYORG, CSV, MY NAME OF THE COMPANY, 123 ELM ST, STUCKYVILLE, OH, 12345
DTL, TOADSUCK, NC, 27999, NS, ARRIVED at the UNIT, X 4, 20140726, 063100, AND, TOADSUCK, NC,.3861, 27999, 12345, 23456 lbs, 1
DTL, TOADSUCK, NC, 27999, lbs, 1 NS, SORTING COMPLETE, X 6, 20140726, 080000, AND TOADSUCK, NC,.3861, 27999, 12345, 23456
DTL, TOADSUCK, NC, 27999, NS, PRONOUNCED, D1, 20140726, 121800, TOADSUCK, NC, 27999, 12345, 23456,.3861, lbs and 1
Given this control sqlloader file:
Oracle: mydb$ cat eds_edstest_combined.ctl
Load
INFILE ' / xfers/oracle/myapp/data/eds_edstest.dat'
BADFILE ' / xfers/oracle/myapp/data/eds_edstest.bad'
DISCARDFILE ' / xfers/oracle/myapp/data/eds_edstest.dsc'
ADD
IN THE TABLE estevens.edstest_header
WHERE (rec_type = 'HDR')
FIELDS TERMINATED BY ', '.
SURROUNDED OF POSSIBLY "" "
TRAILING NULLCOLS
(rec_type CHAR,
sold_to_account TANK,
scac_receiver_id TANK,
format_type TANK,
client_name TANK,
customer_pickup_address TANK,
customer_pickup_city TANK,
customer_pickup_state TANK,
customer_pickup_zip TANK,
INSERT_USER "1"
INSERT_USER_DATE sysdate,
INSERT_STATUS_CODE CONSTANT 'I')
IN THE TABLE estevens.edstest_detail
WHERE (rec_type = 'PIF')
FIELDS TERMINATED BY ', '.
SURROUNDED OF POSSIBLY "" "
TRAILING NULLCOLS
(rec_type CHAR,
ship_to_name TANK,
ship_to_address TANK,
ship_to_city TANK,
ship_to_state TANK,
ship_to_zip TANK,
status_or_appt_reason_cd TANK,
event_description TANK,
shipment_status_cd TANK,
shipment_event_date TANK,
shipment_event_time TANK,
event_time_zone TANK,
event_city TANK,
Event_State TANK,
event_zip TANK,
customer_confirm TANK,
delivery_confirm TANK,
tracking_number TANK,
mail_rec_weight TANK,
mail_rec_weight_cd TANK,
mail_red_qty TANK,
INSERT_USER "1"
INSERT_USER_DATE sysdate,
INSERT_STATUS_CODE CONSTANT 'I')
-END CONTROL FILE
And the time of execution of transactions:
SQL * Loader: release 11.2.0.3.0 - Production the kill Jul 29 07:50:04 2014
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Control file: /xfers/oracle/myapp/control/eds_edstest_combined.ctl
Data file: /xfers/oracle/myapp/data/eds_edstest.dat
Bad leadership: /xfers/oracle/myapp/data/eds_edstest.bad
Delete the file: /xfers/oracle/myapp/data/eds_edstest.dsc
(Allow all releases)
Number of loading: ALL
Number of jump: 0
Authorized errors: 50
Link table: 10000 lines, maximum of 256000 bytes
Continuation of the debate: none is specified
Path used: classics
Silent options: your COMMENTS
Table ESTEVENS. EDSTEST_HEADER, loaded when REC_TYPE = 0 X 484452 (character "HDR") add the option in effect for this table: APPEND TRAILING NULLCOLS option in effect
Column Position Len term Encl. Datatype name
------------------------------ ---------- ----- ---- ---- ---------------------
FIRST REC_TYPE *, O ("") CHARACTER
SOLD_TO_ACCOUNT NEXT *, O ("") CHARACTER
SCAC_RECEIVER_ID NEXT *, O ("") CHARACTER
FORMAT_TYPE NEXT *, O ("") CHARACTER
CLIENT_NAME NEXT *, O ("") CHARACTER
CUSTOMER_PICKUP_ADDRESS NEXT *, O ("") CHARACTER
CUSTOMER_PICKUP_CITY NEXT *, O ("") CHARACTER
CUSTOMER_PICKUP_STATE NEXT *, O ("") CHARACTER
CUSTOMER_PICKUP_ZIP NEXT *, O ("") CHARACTER
INSERT_USER NEXT *, O ("") CHARACTER
The SQL string for the column: "1."
INSERT_USER_DATE SYSDATE
CONSTANT INSERT_STATUS_CODE
The value is 'I '.
Table ESTEVENS. EDSTEST_DETAIL, loaded when REC_TYPE = 0X44544c ('PIF' character) in effect for this table insert option: APPEND TRAILING NULLCOLS option in effect
Column Position Len term Encl. Datatype name
------------------------------ ---------- ----- ---- ---- ---------------------
REC_TYPE NEXT *, O ("") CHARACTER
SHIP_TO_NAME NEXT *, O ("") CHARACTER
SHIP_TO_ADDRESS NEXT *, O ("") CHARACTER
SHIP_TO_CITY NEXT *, O ("") CHARACTER
SHIP_TO_STATE NEXT *, O ("") CHARACTER
SHIP_TO_ZIP NEXT *, O ("") CHARACTER
STATUS_OR_APPT_REASON_CD NEXT *, O ("") CHARACTER
EVENT_DESCRIPTION NEXT *, O ("") CHARACTER
SHIPMENT_STATUS_CD NEXT *, O ("") CHARACTER
SHIPMENT_EVENT_DATE NEXT *, O ("") CHARACTER
SHIPMENT_EVENT_TIME NEXT *, O ("") CHARACTER
EVENT_TIME_ZONE NEXT *, O ("") CHARACTER
EVENT_CITY NEXT *, O ("") CHARACTER
EVENT_STATE NEXT *, O ("") CHARACTER
EVENT_ZIP NEXT *, O ("") CHARACTER
CUSTOMER_CONFIRM NEXT *, O ("") CHARACTER
DELIVERY_CONFIRM NEXT *, O ("") CHARACTER
TRACKING_NUMBER NEXT *, O ("") CHARACTER
MAIL_REC_WEIGHT NEXT *, O ("") CHARACTER
MAIL_REC_WEIGHT_CD NEXT *, O ("") CHARACTER
MAIL_RED_QTY NEXT *, O ("") CHARACTER
INSERT_USER NEXT *, O ("") CHARACTER
The SQL string for the column: "1."
INSERT_USER_DATE SYSDATE
CONSTANT INSERT_STATUS_CODE
The value is 'I '.
value used for the parameter LINES increased from 10000 to 30 sheet 2: discarded - failed all WHEN clauses.
Sheet 3: Discarded - failed all WHEN clauses.
Folder 4: Discarded - failed all WHEN clauses.
Table ESTEVENS. EDSTEST_HEADER:
1 row loaded successfully.
0 rows not loaded due to data errors.
3 rows not loading because all WHEN clauses were failed.
0 rows not populated because all fields are null.
Table ESTEVENS. EDSTEST_DETAIL:
0 rows successfully loaded.
0 rows not loaded due to data errors.
4 rows not loading because all WHEN clauses were failed.
0 rows not populated because all fields are null.
The space allocated to bind table: 247800 byte (30 lines)
Bytes of read buffer: 1048576
Total logical records ignored: 0
Total logical records read: 4
Total rejected logical records: 0
Logical records discarded total: 3
Run started the kill Jul 29 07:50:04 2014
Run finished on Tue Jul 29 07:50:04 2014
Time was: 00:00:00.07
Time processor was: 00:00:00.01
It works on linux, and the file data calculated from a Windows system to the time we get to it, but it's in the * nix format - with a simple x '0A' as the line terminator.
If, in the control file, I comment on the block of INSERTION for the header table, retail inserts very well.
If, in the control file, (return to the initial charge, two tables) I change the line
INFILE ' / xfers/oracle/myapp/data/eds_edstest.dat'
To read
INFILE ' / xfers/oracle/myapp/data/eds_edstest.dat' "str" | "» \n' »
The saved result becomes
Table ESTEVENS. EDSTEST_HEADER:
1 row loaded successfully.
0 rows not loaded due to data errors.
0 rows not loading because all WHEN clauses were failed.
0 rows not populated because all fields are null.
Table ESTEVENS. EDSTEST_DETAIL:
0 rows successfully loaded.
0 rows not loaded due to data errors.
1 row not loaded because all WHEN clauses were failed.
0 rows not populated because all fields are null.
I try to help the developer on this, and it resists change to use external tables. Even if I can overcome that, I now have a puzzle I want to solve, just to add to my knowledge. Plus, I have some concerns at this stage that whatever it is that miss me here could also come into play if I convert external tables.
Ed,
Are you sure that put you the post in the right place? It should be located in the first definition of the following field each time after the first when clause clause. Put after the first when the clause is optional. When I use the following with what you have provided, it loads 1 record in the table header and 3 records in the Details table. Did you actually do or tell your developer to do and wish that he understood and put it in the right place?
Load
INFILE 'eds_edstest.dat '.
BADFILE "eds_edstest.bad."
DISCARDFILE 'eds_edstest.dsc '.
ADD
IN THE TABLE edstest_header
WHERE (rec_type = 'HDR')
FIELDS TERMINATED BY ', '.
SURROUNDED OF POSSIBLY "" "
TRAILING NULLCOLS
(rec_type CHAR,
sold_to_account TANK,
scac_receiver_id TANK,
format_type TANK,
client_name TANK,
customer_pickup_address TANK,
customer_pickup_city TANK,
customer_pickup_state TANK,
customer_pickup_zip TANK,
INSERT_USER "1"
INSERT_USER_DATE sysdate,
INSERT_STATUS_CODE CONSTANT 'I')
IN THE TABLE edstest_detail
WHERE (rec_type = 'PIF')
FIELDS TERMINATED BY ', '.
SURROUNDED OF POSSIBLY "" "
TRAILING NULLCOLS
(rec_type POSITION (1) TANK,
ship_to_name TANK,
ship_to_address TANK,
ship_to_city TANK,
ship_to_state TANK,
ship_to_zip TANK,
status_or_appt_reason_cd TANK,
event_description TANK,
shipment_status_cd TANK,
shipment_event_date TANK,
shipment_event_time TANK,
event_time_zone TANK,
event_city TANK,
Event_State TANK,
event_zip TANK,
customer_confirm TANK,
delivery_confirm TANK,
tracking_number TANK,
mail_rec_weight TANK,
mail_rec_weight_cd TANK,
mail_red_qty TANK,
INSERT_USER "1"
INSERT_USER_DATE sysdate,
INSERT_STATUS_CODE CONSTANT 'I')
-
Left join of the two tables and multiple values into a single value separated by commas
Hello
I have following tables with their structures and their data as below.
CREATE TABLE 'BETODI '. "" BETINFO ".
(
VARCHAR2 (8 BYTE) "CURRENTPRESS."
ENABLE 'TYPEIDCONTAINER' VARCHAR2 (30 BYTE) NOT NULL
)
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A24G', 'PMC');
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A24D', 'Pensky-MARTENS');
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ("A25D", "CMP");
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A25G', 'PMC');
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A26D', 'PMC');
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A26G', 'PMC');
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ("A32G", "V-BFC3");
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A32D', "V-BFC2");
CREATE TABLE 'BETODI '. "" BETMASTER ".
(
ACTIVATE THE "CUREPRESS" TANK (5 BYTES) NOT NULL,
ACTIVATE THE "TYPE" VARCHAR2 (5 BYTE) NOT NULL,
NUMBER (5.0) "LASTPCIRIM".
)
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A24', '45 M 8', 15);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A25', 42 16', 15);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A26", 16' 45, 15);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A27", '45 M 34', 16);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A28', '45 M 34', 16);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A29', '45 M 34', 16);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A30', '45MCH', 15);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A31", "45MCH", 16);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A32', '45MCH', 16);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A33', '45MCH', 16);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A34", "45MCH", 16);
These two tables have left join as
BETMASTER. CUREPRESS = substr (BETINFO. CURRENTPRESS, 1, 3)
now I want to have the data in the two tables with fields Curepress, Lastpcirim, typeidcontainer.
Also something like
Make a group of typeidcontainer if this value is greater than 1 by press separated the values of semicolon (;)
So, for example above, we should be given as
A24 PMC 15; PENSKY-MARTENS
A25 15 PMC
A26 15 PMC
A27 16 (NULL)
A28 16 (NULL)
A30 15 (NULL)
A31 16 (NULL)
A32 16 BFC2-V; V BFC3
A33 16 (NULL)
A34 16 (NULL)
How could do?
My current request is as
Select distinct Curepress, lastpcirim, typeidcontainer
BETMASTER STD left join INF BETINFO
on the trim (STD. CUREPRESS) = substr (trim (INF. CURRENTPRESS), 1, 3)
but I am unable to get the values separated by commas.
Any help would be appreciated.
Thank you
Mahesh.
Hi, Mahesh,
If you want to only 1 row of output for each distinct combination of currentpress and lastpcirim? This sounds like a job for GROUP BY.
And you want the row to contain a list of all different typidcontainers-delimited? This sounds like a job for the aggregate LISTAGG function.
WITH joined_data AS
(
SELECT DISTINCT
MST.curepress, mst.lastpcirim, inf.typeidcontainer
OF betmaster STD
LEFT JOIN betinfo ON TRIM (mst.curepress) inf = SUBSTR (TRIM (inf.currentpress)
1
3
)
)
SELECT curepress, lastpcirim
LISTAGG (typeidcontainer, ',')
THE Group (ORDER BY typeidcontainer) AS container_list
OF joined_data
Curepress GROUP, lastpcirim
;
Unfortunately, you can't say LISTAGG (DISTINCT ...), so you should always get the separate containers how you already are. (Note that the subquery is just what you posted).
Thanks for posting the CREATE TABLE and INSERT statements; It is very useful. Don't forget to tell what version of Oracle you are using. LISTAGG was new in Oracle 11.2.
Why not add CHECK constraints (and perhaps triggers) to your tables, so that curepress and currentpress are not stored with the head or trailing spaces? Then you wouldn't need to use the PAD in queries like this, and your code would be simpler and more effective.
-
I have two tables I have merged into a single view.
All rows from both tables to merge into a single view.
Not table 1 no criteria:
Table 2 criteria:MATERIAL PLANT QUANTITY UNIT POSTING_DATE
The view should look like this:MATERIAL PLANT SALES_QUANTITY UNIT POSTING_DATE RECORD_TYPE Where RECORD_TYPE IN('O','U')
I'm not going anywhere, what should I do?MATERIAL PLANT QUANTITY UNIT POSTING_DATE
Hello
Maybe you want something like this:
CREATE OR REPLACE VIEW table_1_and_ou_from_2 AS -- SELECT material, plant, quantity, unit, posting_date FROM table1 -- UNION ALL -- SELECT material, plant, sales_quantity, unit, posting_date FROM table2 WHERE record_type IN ('O', 'U') ;
The columns in the view will have the same names that the columns of the 1st branch of the UNION, then the 3rd column will be called quantity, not sales_quantity.
I hope that answers your question.
Otherwise, then, as mentioned above, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data (that is, the content of the view).
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum {message identifier: = 9360002}
Maybe you are looking for
-
Can satellite L350 - I use the the L300 recovery disk?
Mate has a L350 who is tired and unfortunately has no recovery disk. I could use my recovery disc for my L300 model or making worse it?
-
Satellite A210 - screen goes black without any reason!
I got my satellite A210-171 for a few years and a few months ago, everything was OK.But our when I'm working or watching a web my screen goes black and nothing seems to work?The only way around this is to turn off the power switch on the laptop then
-
I want an Inbox rule to the letters, I create on a device to synchronize on the other device, so any machine, I'm on my mail goes into the right folder, is transmitted, etc.. I use Mail 9.2 on an early 2009 24 "iMac and a MacAir 2013 and will replace
-
G72-B60US notebook computer touchpad scroll bar
Hello. I have through most of these postings & can't find anything related to my problem. On the touchpad I sometimes get this tiny scroll bar. It is very annoying & I would like to get rid of him. Is it possible to do & if so how? I can't describe w
-
amplification of the strain by using the cDAQ
Hello I am a newbie in the use of DAQ hardware and hope someone can help out me. I recently bought a cDAQ with the NI 9237 to measure the strains. The strains that I try to measure are very small 1 series micro. A bit of research showed me that I nee