INSERT INTO with SELECT CASE
Hi allI have this problem: Insert Table_A Table_B values... with a derivatives/calculated filed.
Example of
INSERT INTO Table_A (id_part, vendtype, origin, proven, desc)
SELECT id_p, vendt, origin, proven, <calculate/derivated_field_desc>
FROM Table_B
The rules for calculating the desc field inserted on Table_A are1. IF vendt='V' AND origin='N' AND proven!='04' THEN ---> desc='TRANSFER'
2. IF vendt='M' AND origin='N' AND proven!='04' THEN ---> desc='IMPORTED'
3. IF proven='04' THEN ---> desc='BAD'
So what I use on my INSERT INTO statement < calculate/derivated_field_desc >?Can I use a SELECT BOX WHEN block... or only DECODE is a good solution?
Published by: November 15, 2010 12.51 trebbia
Two things I noticed: 1. you should remove the "SELECT" before the CASE and 2. There is an incompatibility of single quotation mark (').
Tags: Database
Similar Questions
-
Insert into MDQ_OLD select * from table (lt_monitorMdq);
I'm trying to insert into a table that has only a single column, which is a column of a user defined type (UDT). The UDT is nested, that is one of the attributes of the UDT is an another UDT.
I aim to insert into the table like this pseudo-code:
INSERT INTO T1 SELECT * FROM THE UDT;
CREATE TABLE MDQ_OLD (myMDQ UDT_T_MONITOR_MDQ)
NESTED TABLE myMDQ
(T1_NEW) ACE STORE
THE NESTED TABLE MONITOR_MDQ_PRIM_RIGHTS
STORE AS T2_NEW);
The MONITOR_MDQ_CLI procedure. Read below returns the parameter lt_monitorMdq which is a UDT type as announced. The statement "insert into select MDQ_OLD * table (lt_monitorMdq);" fails, while the second insert statement works.
Is it possible to get the first statement of work?
I'm on Oracle 11 g 2.
DECLARE
lt_monitorMdq UDT_T_MONITOR_MDQ;
BEGIN
MONITOR_MDQ_CLI. Reading (TRUNC (SYSDATE),
TRUNC (SYSDATE),
NULL,
NULL,
"MILLION BTU.
lt_monitorMdq); -Note lt_monitorMdq is an OUT parameter
-This insert does not work
Insert into MDQ_OLD select * from table (lt_monitorMdq);
BECAUSE me in 1... lt_monitorMdq.count
LOOP
Dbms_output.put_line ('lt_monitorMdq: ' | .mdq_id lt_monitorMdq (i));
-This integration works
INSERT INTO MDQ_OLD (MYMDQ)
VALUES (UDT_T_MONITOR_MDQ (UDT_R_MONITOR_MDQ)
lt_monitorMdq (i) .gasday,
1,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
() UDT_T_MONITOR_MDQ_PRIM_RIGHT
() UDT_R_MONITOR_MDQ_PRIM_RIGHT
1,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
(NULL)));
END LOOP;
END;
have you tried:
INSERT INTO MDQ_OLD (myMDQ) VALUES (lt_MonditorMDq);
curiosity:
Is there a particular reason, why you have created a table with a single column of type UDT instead of:
CREATE TABLE... OF UDT_T_MONITOR_MDQ;
I can tell you from experience that using a nested table, you can easily query the data in the nested table.
MK
-
Insert Into with subquery less 00947. 00000 - not enough of"values."
I'm writing an insert using LESS but can't seem to get the syntax right or it will even work?
I use less because it is more accurate with the data in the table.
INSERT INTO PROVIDER_TESTS (PROVIDER_TESTS_ID, PROVIDER_ID, ALL_CODE_ID, ORDINAL, GENERIC_DESCRIPTION, FASTING_HOURS, EMERGENCY, ABN_INDICATOR, PROCEDURE_ID, COMPENDIUM_ID)
VALUES (SEQ_PROVIDER_TESTS_ID. NEXTVAL, 2395350,)
(SELECT ALL_CODE_ID, ORDINAL, GENERIC_DESCRIPTION, FASTING_HOURS, EMERGENCY, ABN_INDICATOR, PROCEDURE_ID, COMPENDIUM_ID
OF PROVIDER_TESTS WHERE PROVIDER_ID = 921
LESS
SELECT ALL_CODE_ID, ORDINAL, GENERIC_DESCRIPTION, FASTING_HOURS, EMERGENCY, ABN_INDICATOR, PROCEDURE_ID, COMPENDIUM_ID
OF PROVIDER_TESTS WHERE PROVIDER_ID = 2395350));
Thank youThis is because the values clause only supports scalar subquery expressions. This means that the query may return only as a column and a row. You should be able to restructure your query like this:
INSERT INTO PROVIDER_TESTS ( PROVIDER_TESTS_ID , PROVIDER_ID , ALL_CODE_ID , ORDINAL , GENERIC_DESCRIPTION , FASTING_HOURS , URGENCY , ABN_INDICATOR , PROCEDURE_ID , COMPENDIUM_ID ) SELECT SEQ_PROVIDER_TESTS_ID.NEXTVAL , 2395350 , a.* FROM ( SELECT ALL_CODE_ID , ORDINAL , GENERIC_DESCRIPTION , FASTING_HOURS , URGENCY , ABN_INDICATOR , PROCEDURE_ID , COMPENDIUM_ID FROM PROVIDER_TESTS WHERE PROVIDER_ID =921 MINUS SELECT ALL_CODE_ID , ORDINAL , GENERIC_DESCRIPTION , FASTING_HOURS , URGENCY , ABN_INDICATOR , PROCEDURE_ID , COMPENDIUM_ID FROM PROVIDER_TESTS WHERE PROVIDER_ID = 2395350 ) a;
-
Select dynamic in - insert into SQL
Hello
I need some advice on how can I change my dynamic SQL code (select in - insert in) to manage changes to the underlying tables.
My apologies for the long post - I tried to put a minimum, but all the details necessary to explain my situation.
I have several tables who are employed (pl/sql package) purge [all lines that are three months – based on the value of creation_date]. For example, DDL for tables of the sample and its ARCHIVE for:
This work of purging archives also some data according to the needs of the company. Archiving is done using a dynamic sql as below:create table actual_table (col1 varchar2(100), col2 varchar2(100), col3 varchar2(100), creation_date date) create table actual_table_arc (col1 varchar2(100), col2 varchar2(100), col3 varchar2(100), creation_date date, archive_date date)
Note: Please note that I use sysdate in select above to populate the archive_date column.v_arc_sql_stmt := ' INSERT INTO actual_table_arc' || ' SELECT '|| get_column_name_list('ACTUAL_TABLE') ||', sysdate FROM actual_table ' || ' WHERE col1 = :a'; EXECUTE IMMEDIATE DBMS_LOB.SUBSTR (v_arc_sql_stmt, 32000, 1) USING v_some_id;
Code for the get_column_name_list() function is below:
Now: it is necessary to add a new column to the ACTUAL_TABLE table. So new table looks like this:FUNCTION get_column_name_list (p_table_name VARCHAR2) RETURN CLOB IS CURSOR col_name_cur IS SELECT a.column_name FROM all_tab_columns a WHERE a.table_name = UPPER(p_table_name)||'_ARC' AND EXISTS (SELECT 'Y' FROM all_tab_columns b WHERE b.table_name = UPPER(p_table_name) AND b.column_name = a.column_name) ORDER BY a.column_id; v_column_list CLOB; BEGIN FOR rec IN col_name_cur LOOP v_column_list := v_column_list || rec.column_name ||',' ; END LOOP; v_column_list := SUBSTR(v_column_list, 0, LENGTH(v_column_list)-1); RETURN v_column_list; END get_column_name_list;
The table of ARC after changing to include the new column looks like this:actual_table : col1 varchar2(100), col2 varchar2(100), col3 varchar2(100), creation_date date, new_column varchar2(100)
Now the dynamic SQL above won't work because of the order of the columns in the table of ARC and SELECT it.actual_table_arc : col1 varchar2(100), col2 varchar2(100), col3 varchar2(100), creation_date date, archive_date date, new_column varchar2(100)
Please tell us how I can change the dynamic SQL to absorb this change [and all these changes in the future].
Thank you
Published by: Amer-user12033597 22-Aug-2011 08:06Hello
I think that partitioning is included in enterprise edition, you can check which features that you can use with
select * from v$option
Of what you said
I have several tables who are employed (pl/sql package) purge [all lines that are three months – based on the value of creation_date].
You could split the actual_table the date of creation to give monthly partitions - daily or weekly depending on how often you plan to run the purge job. When the job runs, you would identify all partitions of the table that contains data is superior to 3 months - personally I use a naming convention to do it like this.
DTYLER_APP@pssdev2> CREATE TABLE dt_acutal_table 2 ( col1 varchar2(100), 3 col2 varchar2(100), 4 col3 varchar2(100), 5 creation_date date 6 ) 7 PARTITION BY RANGE (creation_date) 8 ( PARTITION ptn_201101 VALUES LESS THAN (TO_DATE('01/02/2011','dd/mm/yyyy')), 9 PARTITION ptn_201102 VALUES LESS THAN (TO_DATE('01/03/2011','dd/mm/yyyy')), 10 PARTITION ptn_201103 VALUES LESS THAN (TO_DATE('01/04/2011','dd/mm/yyyy')), 11 PARTITION ptn_201104 VALUES LESS THAN (TO_DATE('01/05/2011','dd/mm/yyyy')), 12 PARTITION ptn_201105 VALUES LESS THAN (TO_DATE('01/06/2011','dd/mm/yyyy')), 13 PARTITION ptn_201106 VALUES LESS THAN (TO_DATE('01/07/2011','dd/mm/yyyy')), 14 PARTITION ptn_201107 VALUES LESS THAN (TO_DATE('01/08/2011','dd/mm/yyyy')), 15 PARTITION ptn_201108 VALUES LESS THAN (TO_DATE('01/09/2011','dd/mm/yyyy')), 16 PARTITION ptn_201109 VALUES LESS THAN (TO_DATE('01/10/2011','dd/mm/yyyy')), 17 PARTITION ptn_201110 VALUES LESS THAN (TO_DATE('01/11/2011','dd/mm/yyyy')), 18 PARTITION ptn_201111 VALUES LESS THAN (TO_DATE('01/12/2011','dd/mm/yyyy')), 19 PARTITION ptn_201112 VALUES LESS THAN (TO_DATE('01/01/2012','dd/mm/yyyy')), 20 PARTITION ptn_MaxValue VALUES LESS THAN (MAXVALUE) 21 ) 22 / Table created. DTYLER_APP@pssdev2> CREATE TABLE dt_acutal_table_arc 2 ( col1 varchar2(100), 3 col2 varchar2(100), 4 col3 varchar2(100), 5 creation_date date 6 ) 7 PARTITION BY RANGE (creation_date) 8 ( PARTITION ptn_201101 VALUES LESS THAN (TO_DATE('01/02/2011','dd/mm/yyyy')), 9 PARTITION ptn_201102 VALUES LESS THAN (TO_DATE('01/03/2011','dd/mm/yyyy')), 10 PARTITION ptn_201103 VALUES LESS THAN (TO_DATE('01/04/2011','dd/mm/yyyy')), 11 PARTITION ptn_201104 VALUES LESS THAN (TO_DATE('01/05/2011','dd/mm/yyyy')), 12 PARTITION ptn_201105 VALUES LESS THAN (TO_DATE('01/06/2011','dd/mm/yyyy')), 13 PARTITION ptn_201106 VALUES LESS THAN (TO_DATE('01/07/2011','dd/mm/yyyy')), 14 PARTITION ptn_201107 VALUES LESS THAN (TO_DATE('01/08/2011','dd/mm/yyyy')), 15 PARTITION ptn_201108 VALUES LESS THAN (TO_DATE('01/09/2011','dd/mm/yyyy')), 16 PARTITION ptn_201109 VALUES LESS THAN (TO_DATE('01/10/2011','dd/mm/yyyy')), 17 PARTITION ptn_201110 VALUES LESS THAN (TO_DATE('01/11/2011','dd/mm/yyyy')), 18 PARTITION ptn_201111 VALUES LESS THAN (TO_DATE('01/12/2011','dd/mm/yyyy')), 19 PARTITION ptn_201112 VALUES LESS THAN (TO_DATE('01/01/2012','dd/mm/yyyy')), 20 PARTITION ptn_MaxValue VALUES LESS THAN (MAXVALUE) 21 ) 22 / Table created. DTYLER_APP@pssdev2> CREATE TABLE dt_acutal_table_exch 2 ( col1 varchar2(100), 3 col2 varchar2(100), 4 col3 varchar2(100), 5 creation_date date 6 ) 7 / DTYLER_APP@pssdev2> insert 2 into 3 dt_acutal_table 4 ( col1, 5 col2, 6 col3, 7 creation_date 8 ) 9 SELECT 10 TO_CHAR(rownum), 11 TO_CHAR(rownum), 12 TO_CHAR(rownum), 13 SYSDATE - ROWNUM 14 FROM 15 dual 16 CONNECT BY 17 LEVEL <= 365 18 / 365 rows created. DTYLER_APP@pssdev2> commit; Commit complete. DTYLER_APP@pssdev2> CREATE OR REPLACE FUNCTION f_Get_Partition 2 ( ad_PurgeDate IN DATE, 3 as_Table IN VARCHAR2 4 ) 5 RETURN user_tab_partitions.partition_name%TYPE 6 IS 7 8 ls_Partition user_tab_partitions.partition_name%TYPE; 9 BEGIN 10 11 SELECT 12 partition_name 13 INTO 14 ls_Partition 15 FROM 16 user_tab_partitions 17 WHERE 18 partition_name = 'PTN_'|| TO_CHAR 19 ( ad_PurgeDate, 20 'YYYYMM' 21 ) 22 AND 23 table_name = UPPER(as_Table); 24 25 RETURN ls_Partition; 26 27 EXCEPTION 28 WHEN NO_DATA_FOUND THEN 29 RAISE_APPLICATION_ERROR 30 ( -20001, 31 'Partition could not be found for table '||as_Table||' and date '||TO_CHAR(ad_PurgeDate) 32 ); 33 END; 34 / Function created. DTYLER_APP@pssdev2> CREATE OR REPLACE PROCEDURE p_Arc 2 ( ad_PurgeDate IN DATE, 3 as_SourceTable IN VARCHAR2 4 ) 5 IS 6 7 ls_ExchSQL VARCHAR2(4000); 8 ls_ArcSQL VARCHAR2(4000); 9 ls_ArcTable user_tables.table_name%TYPE; 10 ls_ExchTable user_tables.table_name%TYPE; 11 ls_PartitionName user_tab_partitions.partition_name%TYPE; 12 13 BEGIN 14 15 ls_PartitionName := f_Get_Partition 16 ( ad_PurgeDate, 17 as_SourceTable 18 ); 19 20 ls_ArcTable := as_SourceTable||'_arc'; 21 ls_ExchTable := as_SourceTable||'_exch'; 22 23 ls_ExchSql := ' ALTER TABLE '||as_SourceTable||' 24 EXCHANGE PARTITION '||ls_PartitionName||' 25 WITH TABLE '||ls_ExchTable 26 ; 27 28 EXECUTE IMMEDIATE ls_ExchSql; 29 30 ls_ArcSql := ' ALTER TABLE '||ls_ArcTable||' 31 EXCHANGE PARTITION '||ls_PartitionName||' 32 WITH TABLE '||ls_ExchTable 33 ; 34 35 EXECUTE IMMEDIATE ls_ArcSql; 36 37 END; 38 / Procedure created. DTYLER_APP@pssdev2> exec p_Arc(TO_DATE('01/06/2011','dd/mm/yyyy'),'dt_acutal_table') PL/SQL procedure successfully completed. DTYLER_APP@pssdev2> select count(*) from dt_acutal_table partition( ptn_201106); COUNT(*) ---------- 0 1 row selected. DTYLER_APP@pssdev2> select count(*) from dt_acutal_table_arc partition( ptn_201106); COUNT(*) ---------- 30 1 row selected. DTYLER_APP@pssdev2> alter table dt_acutal_table add (newcol number); Table altered. DTYLER_APP@pssdev2> alter table dt_acutal_table_exch add (newcol number); Table altered. DTYLER_APP@pssdev2> alter table dt_acutal_table_arc add (newcol number); Table altered. DTYLER_APP@pssdev2> exec p_Arc(TO_DATE('01/05/2011','dd/mm/yyyy'),'dt_acutal_table') PL/SQL procedure successfully completed.
HTH
David
-
Insert into select * from table 3. -is on the agenda by the needless?
I've got an example of script, it will work for any table, so I don't bother with the full ddl.
----------------------------------------------------------------------------
create table test in select * from hotels where 1 = 2;
Insert into test select * from Hotels by city;
Select the city from the trial;
-drop table test is serving;
-----------------------------------------------------------------------------
The amazing thing is, that the city is ordered alphabetically,
but you would say it is that an operation order is irrelevant.
Any ideas on that?
This will still work?
Edited by: FourEyes on December 8, 2008 22:55
Edited by: FourEyes on 8 December 2008 22:56
Edited by: FourEyes on 8 December 2008 22:56Hello
The [SQL Oracle 10 language reference | http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_9014.htm#sthref9371] manual says:
«In regards to the ORDER BY clause from the subquery in the DML_table_expression_clause, you place your order is guaranteed only for the inserted rows and only within each extension table.» Orders new lines with regard to existing lines is not guaranteed. »
-
INSERT INTO... SELECT FROM XMLTABLE()
I'm trying to insert using a query to 11.2.0.3. The table is defined as follows:
CREATE TABLE book_master AS TABLE OF XMLTYPE XMLTYPE STORE AS SECUREFILE BINARY;
The insert statement is structured in this way:
INSERT INTO book_master SELECT t.invt_data FROM XMLTable( XmlNamespaces('http://www.mrbook.com/InventoryData' AS "invtdata", 'http://www.mrbook.com/book' AS "book"), '/book:BOOKS' PASSING ? COLUMNS invt_data XMLTYPE PATH 'invtdata:INVT_DATA' ) t;
The parameter '?' is passed through JDBC.
When I run the present, I get the error:
Error report: SQL Error: ORA-19010: Cannot insert XML fragments 19010. 00000 - "Cannot insert XML fragments" *Cause: XML fragments got from extractNode cannot be inserted into the database. *Action: Convert the fragment into a proper XML document before insertion.
Is it possible to cast the XMLTYPE returned by XMLTable in a comprehensive document, instead of a node?
Is it possible to cast the XMLTYPE returned by XMLTable in a comprehensive document, instead of a node?
Well, the error message is pretty clear: you are trying to insert fragments, not a document (only root of content). It is not allowed.
I guess that the query returns several items INVT_DATA, right?
SQL > INSERT INTO book_master
2. SELECT
3 t.invt_data
4
(5) XMLTable
6 ' / BOOKS»
7 PASSAGE xmltype ('
"")8 COLUMNS
9 invt_data XMLTYPE PATH 'INVT_DATA '.
(10) t;
INSERT INTO book_master
*
ERROR on line 1:
ORA-19010: cannot insert XML fragments
We must build a document by encapsulating the fragments returned in a single root element.
-
CAPTURE THE OUTPUT IN INSERT INTO SELECT AND DELETE
Hi all
INSERT into employee_history_arch select * from employee_history where employee_status = 'CP' and action_dt < (sysdate-32);
commit;
delete from employee_history where employee_status = 'CP' and action_dt < (sysdate-32);
commit;
I must capture both the output of the insert and delete the sql query and compare the two values for validation. I shouldn't use select count (*) before the delete statement. I shud exactly capture the output... How to do? Please help meWe will have ' 30 deleted rows' or ' 30 inserted rows"in our tool... I need to capture that 'put out' in a variable and validate against the other
This should be easy.
SQL> set serverout on SQL> DECLARE 2 v_rows_inserted PLS_INTEGER; 3 v_rows_deleted PLS_INTEGER; 4 BEGIN 5 INSERT INTO emp_temp 6 SELECT * FROM emp WHERE deptno = 20; 7 v_rows_inserted := SQL%ROWCOUNT; 8 dbms_output.put_line('Rows Inserted: ' || v_rows_inserted); 9 DELETE FROM EMP WHERE deptno = 20; 10 v_rows_deleted := SQL%ROWCOUNT; 11 dbms_output.put_line('Rows Deleted: ' || v_rows_deleted); 12 IF v_rows_inserted = v_rows_deleted THEN 13 dbms_output.put_line('They are same!'); 14 ELSE 15 dbms_output.put_line('They are NOT same!'); 16 END IF; 17 END; 18 / Rows Inserted: 7 Rows Deleted: 7 They are same! PL/SQL procedure successfully completed.
-
Insert into a table... with order by
Oracle 10.2.0.3
I want to insert into a table, records from another table ordered in a certain way. We want a specific order that we want the data grouped the disk.
No idea why it does not work?
If I leave aside the order, it works fine...create table test_a ( id number primary key, value1 varchar2(20)); insert into test_a (id, value1) values (1,'ccc'); insert into test_a (id, value1) values (2,'bbb'); insert into test_a (id, value1) values (3,'aaa'); create table test_b ( id number primary key, value1 varchar2(20)); insert into test_b (id, value1) (select id, value1 from test_a order by value1) * ERROR at line 1: ORA-00907: missing right parenthesis
This does not work either:SQL> insert into test_b (id, value1) (select id, value1 from test_a); 3 rows created.
create table test_b as (select id, value1 from test_a order by value1) * ERROR at line 1: ORA-00907: missing right parenthesis
Lose the parenthesis.
TUBBY_TUBBZ?create table test_b as select id, value1 from test_a order by value1; Table created. Elapsed: 00:00:00.02
Or
TUBBY_TUBBZ? insert into test_b select id, value1 from test_a order by value1; 3 rows created. Elapsed: 00:00:00.01 TUBBY_TUBBZ?
-
insert into multiple tables by using select in stored procedure
I use oracle 10g R2. I want to insert records in two tables by using a select query (insert into tablename select...) in a stored procedure. How can I insert records into a table two at the same time using a select statement?
My second question is also related to the first... can I use mechanism clustering here because the two tables are based on the same structure and data? One contains data from 24 hours and there are records of 10 days.
Thank you.If you find the answer of Aman as useful/correct, please mark her answer respectively and close the debate. I think his answer is correct as always / a lot of time.
Concerning
Girish Sharma -
Hi all
It is a strange question that I am. I'm parsing XML and fill my paintings based on XML
Here is my first code
with sample_data as (SELECT XMLType(xml_input_file) xmldoc FROM BIBIN_XML_TABLE WHERE file_id = 9) SELECT record_id , tab_name , property_name ,property_value FROM ( select Student1.record_id record_id ,'Students' tab_name , Student2.property_name PROPERTY_NAME ,Student2.property_value PROPERTY_VALUE from sample_data t , xmltable( '/StudentsImport/Students/Student' passing t.xmldoc columns record_id for ordinality , properties xmltype path '*' ) Student1 , xmltable( '*' passing Student1.properties columns property_name varchar2(30) path 'local-name(.)' , property_value varchar2(30) path '.' ) Student2 UNION ALL select teacher1.record_id record_id ,'teacher' tab_name , teacher2.property_name PROPERTY_NAME ,teacher2.property_value PROPERTY_VALUE from sample_data t1 , xmltable( '/StudentsImport/teachers/teacher' passing t1.xmldoc columns record_id for ordinality , properties xmltype path '*' ) teacher1 , xmltable( '*' passing teacher1.properties columns property_name varchar2(30) path 'local-name(.)' , property_value varchar2(30) path '.' ) teacher2)
It works fine and I get all my necessary files.
However, when I try to insert data into a table, by adding
with sample_data as (SELECT XMLType(xml_input_file) xmldoc FROM BIBIN_XML_TABLE WHERE file_id = 9) INSERT INTO xml_splitter SELECT record_id , tab_name , property_name ,property_value FROM ( select Student1.record_id record_id ,'Students' tab_name , Student2.property_name PROPERTY_NAME ,Student2.property_value PROPERTY_VALUE from sample_data t , xmltable( '/StudentsImport/Students/Student' passing t.xmldoc columns record_id for ordinality , properties xmltype path '*' ) Student1 , xmltable( '*' passing Student1.properties columns property_name varchar2(30) path 'local-name(.)' , property_value varchar2(30) path '.' ) Student2 UNION ALL select teacher1.record_id record_id ,'teacher' tab_name , teacher2.property_name PROPERTY_NAME ,teacher2.property_value PROPERTY_VALUE from sample_data t1 , xmltable( '/StudentsImport/teachers/teacher' passing t1.xmldoc columns record_id for ordinality , properties xmltype path '*' ) teacher1 , xmltable( '*' passing teacher1.properties columns property_name varchar2(30) path 'local-name(.)' , property_value varchar2(30) path '.' ) teacher2
I get an error message saying ORA-00928: lack of SELECT key word. Are there some problems with the insert in and union all?
Correct me if I'm wrong.
Thank you
B1
B1,
You got. Insert syntax is a little different using the clause. He is asked to SELECT just after code below
WITH sample_data AS
(SELECT XMLType (xml_input_file) FROM BIBIN_XML_TABLE WHERE file_id xmldoc = 9
)
SELECT - It expects SELECT here and the reason why you got the error.
Try code below.
INSERT INTO xml_splitter
WITH sample_data AS
(SELECT XMLType (xml_input_file) FROM BIBIN_XML_TABLE WHERE file_id xmldoc = 9
)
SELECT record_id
table_name,
property_name,
name
Of
(SELECT Student1.record_id record_id,
Table_name "students."
Student2.property_name PROPERTY_NAME,
Student2.property_value name
OF sample_data t,.
XMLTable ("/ StudentsImport/students/pupils ' by the way the ordinalite of FOR record_id columns t.xmldoc, xmltype property path ' *') Student 1.
XMLTable (' * ' from Student1.properties of property_name VARCHAR2 columns (30) path 'local - name (.)', name VARCHAR2 (30) path '.') Student2
UNION ALL
SELECT Teacher1.record_id record_id;
table_name 'Professor ',.
teacher2.property_name PROPERTY_NAME,
teacher2.property_value name
OF sample_data t1,.
XMLTable (' / StudentsImport/teachers/teachers "from the ordinalite of FOR record_id columns t1.xmldoc, xmltype property path ' *') teacher1,.
XMLTable (' * ' in passing teacher1.properties property_name VARCHAR2 columns (30) path 'local - name (.)', name VARCHAR2 (30) path '.')
) teacher2
PS: The initial brackets I put just before Teacher2 is always necessary, I guess. You can tell it better
Ishan
-
insert into the summary table of the table.
I was wondering if there is a smart way to do it with SQL, but I'm not sure. I would like to consult you yo guys.
I have a table like this
I would like to at the rate of an update and you end up withCREATE TABLE "TEMPLE_FINANCE"."TEST" ( "COLUMN1" VARCHAR2(10 BYTE), "COLUMN2" VARCHAR2(10 BYTE), "COLUMN3" VARCHAR2(10 BYTE), "COLUMN4" VARCHAR2(10 BYTE) ) ; Insert into TEST (COLUMN1,COLUMN2,COLUMN3,COLUMN4) values ('1','2','50.00',null); Insert into TEST (COLUMN1,COLUMN2,COLUMN3,COLUMN4) values ('1','2','50.00',null);
What update statement can run for this?"COLUMN1" "COLUMN2" "COLUMN3" "COLUMN4" "1" "2" "100.00"
I would enter in the summary of the lines based on the column 1 and column2 and get rid of repeative lines.
I have try this insert statement, but it's bascially just adding an extra record in the table.
any help would be grateful.INSERT INTO TEST (SELECT COLUMN1, COLUMN2, SUM(COLUMN3), COLUMN4 FROM TEST GROUP BY COLUMN1, COLUMN2,COLUMN4);
Published by: mlov83 on January 25, 2013 12:45
Published by: mlov83 on January 25, 2013 13:03Hello
I can't help but wonder if you have the best design of table for what it is, you need to do.
The best solution would be to create a new table, using the SUM (TO_NUMBER (Column3)) and GROUP BY, and then delete the original table and rename a new one to the old name. While you're at it, change Column3 as a NUMBER and add a primary key.
In collaboration with just the existing table, INSERT one won't work. INSERT always adds new lines. You want something that can INSERT new lines (or update some existing routes) and DELETE lines at the same time. FUSION can do it all. Here's a way to use the MERGE:
MERGE INTO test dst USING ( SELECT column1, column2, column4 , SUM (TO_NUMBER (column3)) OVER (PARTITION BY column1, column2, column4) AS column3_total , ROWID AS r_id , MIN (ROWID) OVER (PARTITION BY column1, column2, column4) AS min_r_id FROM test ) src ON (src.r_id = dst.ROWID) WHEN MATCHED THEN UPDATE SET dst.column3 = TO_CHAR ( src.column3_total , 'FM9999999.00' ) DELETE WHERE src.r_id != src.min_r_id ;
Published by: Frank Kulash on January 25, 2013 16:07
-
Insert into another table through dynamic suite
Hello
I need to insert data from one table to the other dynamic thereafter. The reason we use where condition can vary in the select statement. Can someone tell me the logic to use
the sql statement is like that
INSERT INTO table1
SELECT * FROM table2 WHERE condition
the condition can vary as because it must come forward
Any ideas will be greatly appreciated
Thank you
MartineMartine wrote:
HelloI need to insert data from one table to the other dynamic thereafter. The reason we use where condition can vary in the select statement. Can someone tell me the logic to use
the sql statement is like that
INSERT INTO table1
SELECT * FROM table2 WHERE condition
the condition can vary as because it must come forward
Any ideas will be greatly appreciated
Thank you
MartineI advise generally live by using dynamic SQL, because it is difficult to develop, hard to debug, hard to maintain and very difficult to resolve. He peut seem reasonable in the situation you described, but think first about the other possibilities. If you have only two or three variants, it is probably easier to use IF and INSERTs hard-coded logic.
If you must use dynamic SQL build the SQL text and use EXECUTE IMMEDIATE to do INSERTIONS and SO logical to concatenate the WHERE clause as necessary, something like
v_text_c := 'insert into my_table(col1)'||chr(13)|| 'select col1'||chr(13)|| ' from my_table2'||chr(13)'|| ' where 1 = 1'; if (whatever) then v_text_c := v_text_c||' and col2 = 'whatever'); end if;
' WHERE 1 = 1' is a placeholder for any or any other predicates. Chr (13) is a line break to make the generated SQL code readable appears.
I find it also useful to create a table with a column CLOB to put the SQL code generated for future reference of error handling.
Good luck!
-
Oracle 9 error: insert into temp-table collection (nested table)
Hello everyone
I have an urgent problem. I have a package which has been developed against 10g but must now be deployed on 9i as well. I don't use 10 g - features and packages compile well on 9.
Somehow, I get the following runtime error: failed execution: ORA-22905: cannot access the rows of a no nested table item.
The Code I use to the particular line is
insert into tmp_report_calculation (select from table (calculations)); *
tmp_report_calculation is a temporary table and calculations holds a collection type that is a nested table. I do not understand why the error is complaining about "No nested table. Less than 10g everything run took place.
Can someone help me out here? Furthermore, it is important that I put the results in this temp-table (since I can't use the multiset on Oracle 9)
concerning
-Marc
Try
insert into tmp_report_calculation (select * from table(cast(calculations as your_collection_type)));
replace"your_collection_type" with your name in the actual collection of course...
-
Error when inserting into a table
Hello
I run this insert stmt
SQL > insert into cntct select * from CUSTSRV_ADMN.cntct_bk1;
*
ERROR on line 1:
ORA-01733: virtual column not allowed here
This is the structure of the table.
SQL > cntct desc;
Name Null? Type
----------------------------------------- -------- ----------------------------
CNTCT_KEY NOT NULL NUMBER (10)
CNTCT_NUM NOT NULL CHAR (12)
SRC_SYS_DESC NOT NULL VARCHAR2 (5)
ACTVTY_DT NOT NULL DATE
CNTCT_TYPE_DESC NOT NULL VARCHAR2 (15)
CNTCT_INIATR_CD NOT NULL CHAR (1)
CNTCT_INIATR_DESC NOT NULL VARCHAR2 (10)
CNTCT_INIATR_NAME NOT NULL VARCHAR2 (30)
CNTCT_INIATR_PHONE_NUM VARCHAR2
CNTCT_STUS_CD NOT NULL CHAR (1)
CNTCT_STUS_DESC NOT NULL VARCHAR2 (10)
CNTCT_AGE_DAYS_CNT NOT NULL NUMBER 4
CNTCT_ELPSD_TIME_SEC_CNT NOT NULL NUMBER (10)
CNTCT_RCVD_DT NOT NULL DATE
CNTCT_OPEN_DT NOT NULL DATE
CNTCT_RSLTN_DT NOT NULL DATE
CNTCT_NEW_IND NOT NULL CHAR (1)
HIGHST_NMIS_CD NOT NULL NUMBER (1)
INIATNG_AGENT_KEY NOT NULL NUMBER (5)
CLSNG_AGENT_KEY NOT NULL NUMBER (5)
CNTCT_ID NOT NULL VARCHAR2 (20)
IMG_NUM NOT NULL VARCHAR2 (13)
PRVDR_NPI NOT NULL VARCHAR2 (10)
PRVDR_TIN NOT NULL VARCHAR2 (9)
CNTCT_OPEN_DTIME NOT NULL DATE
CNTCT_RSLTN_DTIME NOT NULL DATE
Please notify.
Kind regards
NarayanThe table where you try to insert data, is a table or a view.
Please check the details of the error.
ORA-01733: virtual column not allowed here
Cause: An attempt was made to use an INSERT, UPDATE, or DELETE statement on an expression in a view.
Action: INSERT, update, or DELETE data in the base tables, instead of the view. -
validation for each 1,000 records to be inserted in the select statement
Hi, I have the following INSERTION in the SELECT statement.
The SELECT statement (who joined) data fo about 6 crores. I need to insert this data into another table.
Please suggest me the best way to do it.
I use the INSERT in the SELECT statement, but I want to use the statement commit for each 1,000 records.
How can I do this...
Thank youinsert into emp_dept_master select e.ename ,d.dname ,e.empno ,e.empno ,e.sal from emp e , dept d where e.deptno = d.deptno ------ how to use commit for every 1000 records .
Method 4 is the best
You could combine method 3 and 1 (without dynamic SQL)
Method 2 is the less optimal solution from the list.
Maybe you are looking for
-
Closing firefox removes so much history I want what he
Too bad, that's when I close it, sometimes the processes continue to run.
-
I use iMessage to the text of my Macbook. For some reason, it will not let me send a text message to a particular group (everyone has iMessage/iPhones) to my computer, but works well on my iPhone. All messages always appear on my Macbook iMessage, bu
-
How to set up DAQ devices to send data line by line
Hello I need to send the data below line of data acquisition. So first of all, I should send the first line and then the second line and finally the third line. For this I used a loop and I create and close a task in each itearation. What makes my pr
-
Execution of Multisim with Labview
Hey,. I'm trying to convert a series of laboratories studying for a class of dynamic systems run on a newer, better set up. Previously, the laboratory, I'm working on that took input from a sensor, fed entry through an analog circuit that feeds the
-
Microsoft Visual Studio 6.0 Professional Edition is compatible with Windows 7?
Is this compatible with Windows 7?