INSERT INTO table (columns...) with table_tmp in select... ...
Hi guru,.Is less than a valid SQL | Statement of PLSQL? or several instructions and what it does?
insert into table (col1, col2, col3, col4)
with table_tmp as
(select ccol1, ccol2, ccol3, ccol4, ccol5, ccol6
from table1, table2 t2 t1
where t1.id = t2.id
and t2.start > sysdate()
)
Select tcol1, tcol2, tcol3, tcol4
of table_tmp tt1, table3 t3
where tt1.id = tt3.id;
I checked the SQL quick reference card and don't see anything similar to this... I wonder where I can find a better book of reference for the syntax.
Thanks in advance
KH
user5885318 wrote:
Is less than a valid SQL | Statement of PLSQL? or several instructions and what it does?
It inserts data into the table
insert into table (col1, col2, col3, col4)
(ok, ignoring the fact that you can't have a table named table)
using the select statement located below
with table_tmp as
(select ccol1, ccol2, ccol3, ccol4, ccol5, ccol6
from table1, table2 t2 t1
where t1.id = t2.id
and t2.start > sysdate()
)
Select tcol1, tcol2, tcol3, tcol4
of table_tmp tt1, table3 t3
where tt1.id = tt3.id;
I checked the SQL quick reference card and don't see anything similar to this... I wonder where I can find a better book of reference for the syntax.
SQL reference documentation contains the complete syntax for Oracle SQL, so how can you find a better reference for the syntax. I think your concept to better is all simply because you are not familiar with things and don't know where to find things. SQL is a huge beast, so you cannot expect to find things very quickly in all cases, especially if you don't really know what you are looking for.
I'm guessing you are struggling to find information about the clause "WITH"?
It is called subquery factoring and lie under the SELECT statement in the SQL reference:
http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/statements_10002.htm#i2161315
An equivalent statement without the WITH clause (using your insert as a base statement)...
insert into table(col1, col2, col3, col4)
select tcol1, tcol2, tcol3, tcol4
from (select ccol1, ccol2, ccol3, ccol4, ccol5, ccol6
from table1 t1, table2 t2
where t1.id=t2.id
and t2.start > sysdate()
) tt1
, table3 t3
where tt1.id=tt3.id;
The done WITH clause takes the subquery in the main query. This is useful if the same subquery is needed more than once in the main query.
Tags: Database
Similar Questions
-
The values of cursor two corresponding and insertion into tables
I ' am using sql developer oracle 11g.
I have 3 tables called
PRODUCT_NOTIFICATION
RECORD
PCS_NOTIFICATION
--------------------
PRODUCT_NOTIFICATION
ID TITLE Message 21 sale 50% discount on all brand products RECORD
ID REGNAME ACTIVATIONCODESTATUS MOBILENUM 747407931107 TEST THERE 12345 39717371107 TESTuco1 THERE 6789 Now, I want to take only the message of product_notification table column and
pick up the registered customer of registration table where the activationcode_status = 'Y '.
PCS_NOTIFICATION
Output of desire in the PCS_NOTIFICATION TABLE
ID MOBILENUM Message 1 12345 50% discount on all brand products 2 6789 50% discount on all brand products THEN insert the message in pcs_notification.
It is the procedure goes as...
create or replace
PROCEDURE sp_notification)
p_out_msg OUT VARCHAR2
)
AS
CURSOR C_product_notification
IS
Select the description of product_notification;
-Search for registered customer
CURSOR C_registered
IS
Select * from registration where activation_code = 'Y ';
for k C_INSERT
LOOP
THEN
BEGIN
If C_product_notification = C_registered THEN
INSERT INTO PRODUCT_CLOUD_NOTIFICATION VALUES () - stuck here
---------------------
---------------------------------
--------------------------------------
Goal is to send the generic message for every individual mobile numbers of registered customers.
Help, please...
Create a sequence object to fill PCS_NOTIFICATION.ID. allows you to call him PCS_NOTIFICATION_ID_SEQ.
Now all you need is a simple insert statement.
insert into pcs_notification (id, mobilenum, message) select pcs_notification_id_seq.nextval, r.mobilenum, pn.message from product_notification pn cross join registration r where r.activationcodestatus = 'Y';
-
Insert/update the column with the clob data type
Hi all
ORCL Version: 11g.
I have a table with the clob data type.
Test12
(col1 clob);
I'm trying to insert/update to update the column with more than 4000 characters.
But due to the limitation of tank 4000, I could not Insert/Update.
Need your help in resolving this issue.
THX
Rod.
The limit of 4000 characters is incorrect. That pertains only to the varchar2 data type. A clob can hold more than 4 G.
Here is an example that shows how to insert it, I found...
Otherwise, here is a way 'dirty' to do.
insert into your_table (COLA, COLB)
values
(PRIMARY_KEY, PART 1 OF DATA)
;
Update your_table
Define COLB = COLB | PART 2 OF BIG DATA
where COLA = PRIMARY_KEY;
Update your_table
Define COLB = COLB | PART 3 OF BIG DATA
where COLA = PRIMARY_KEY;
.. and so on...
I don't know that I personally recommend the second style... But he could do the job.
-
Insert into table primary key (automatic numbering) for back in class resultset
Hello
I connect to Oracle 10 g via JDBC (ojdbc14.jar is).
My SQL statement is:
INSERT into student (studentName, phone, e-mail, address) values ('Jason', '12345678', 'test', 'test');
SELECT Student_studentId_SEQ. NEXTVAL FROM DUAL;
FYI - the Student table has a trigger to support the generation of a primary key (integer) based on a sequence when a new record is inserted.
The above will do (from the point of view of Java app) is to create a school record and automatically select the student card and student card is accessible via the resultset in Java.
I get the error message ' ORA-00911: invalid character '. Can you please help?
Kind regards
Jason
Published by: user10394130 on October 13, 2008 02:40As I said already try using a refcursor like that.
DECLARE
seqNbr_studentId NUMBER (12): = 0;
stud_cur SYS_REFCURSOR;
BEGIN
INSERT into student (studentName, phone, e-mail, address) values ('Jason', '12345678', 'test', 'test')
StudentId INTO seqNbr_studentId RETURN;
Stud_cur OPEN to SELECT seqNbr_studentId OF MODEL;
END;Thank you
Knani. -
When I use the function 'insert into array' index(like 5), it does not work. When I put the index zero, it works, and inserts the new item at the end of the table. ?. ?
Hello
I think the problem is that you have not initialized your table to which you will add an element. You must double clik and adds a number. You can inicialize, only the last element and the other elements will also be inicialized.
Try looking at the photo.
Hope it helps
-
Insertion in a column with &; value
Hello
When I run under instruction, it asks me to enter a & D cause input value of & sign in the value.
any suggestion
INSERT INTO xxgdv_legacy_inv_ord VALUES (545566,16778, 'S & D BUILD', NULL);
Thank you
Hello
2795332 wrote:
Hello
When I run under instruction, it asks me to enter a & D cause input value of & sign in the value.
any suggestion
INSERT INTO xxgdv_legacy_inv_ord VALUES (545566,16778, 'S & D BUILD', NULL);
Thank you
The simplest thing is to turn off the feature of variable substitution. In SQL * Plus, the way to do it is:
SET DEFINE OFF
You should only do this once, before the Insert; It will remain in force until the end of the SQL * Plus the term. If you want to re - activate (for example, if you call other scripts later, and they may need this feature) so you can light it using the
ALL SET ON
Other ways to treat &, see Re: & value as variable substitution in select
-
CS5, don't know how that Word...
In the previous version of ID, if I had a graph in a framework, I could drag the image around inside this image with the direct Selection tool. I can always do with CS5, but he seems to want to show the entire image in a manner of ghosts that is outside of the framework. Is there a way to disable this type of song look as if it was in previous versions? I want sound slow down my computer to the low bigtime because I am facing a large image. Whenever I click to drag, everything slows to a crawl and unusable.
Go to the preferences and delayed the Live Drawing screen value.
-
Reading data from a file txt and inserting into table
I have a text file and have uploaded data in this text file in an internal table,
the data is normally placed online and I managed to recover most of the data, but I have problems by inserting a few conditions
OK, well it goes like this.
I got the right reailer id,
Well, I have a table with all the columns in the file. Now it I'll try to throw it out as simple as I can
Reseller 1
column 1 column 1 column 1 column 1 column 1 column 1 column 1 column 1
===============
Total 0 0 0 0 0 0 0
-------------------------------------
Distributor 2
column 1 column 1 column 1 column 1 column 1 column 1 column 1 column 1
===============
X 1123... .. .. .. .. ..
234 Y... .. .. .. .. ..
Total 23... .. .. .. .. ..
see the problem is I have to associate the retailer number to their corresponding x and y and also not all retailers have values X and Y
The remains of standard file format but only the values of the columns may change, but they must be inserted in the table according to the number of retailers.
U understand what I mean...How about you, including both terminal number (just for the fun of it... hehe!):
SQL> ed Wrote file afiedt.buf 1 select retailer_no, terminal_no, retailer_name, val1, val2, val3, val4, val5, val6, val7, val8, val9, val10 2 from ( 3 select case when retailer_no is null then lag(retailer_no, decode(val1, 'Loto', 1, 'Inst Tk', 2, 3)) over (order by line_no) else null end as retailer_no 4 ,case when terminal_no is null then lag(terminal_no, decode(val1, 'Loto', 1, 'Inst Tk', 2, 3)) over (order by line_no) else null end as terminal_no 5 ,case when retailer_name is null then lag(retailer_name, decode(val1, 'Loto', 1, 'Inst Tk', 2, 3)) over (order by line_no) else null end as retailer_name 6 ,val1, val2, val3, val4, val5, val6, val7, val8, val9, val10 7 from ( 8 select rownum as line_no 9 ,case when regexp_like(line, '^Retailer Number:') then regexp_replace(line, '^Retailer Number: +([0-9]+).*$', '\1') else null end as retailer_no 10 ,case when regexp_like(line, '^Retailer Number:') then regexp_replace(line, '^.* Terminal Number: +([0-9]+).*$', '\1') else null end as terminal_no 11 ,case when regexp_like(line, '^Retailer Number:') then regexp_replace(line, '^.* Retailer Name: +(.*)$', '\1') else null end as retailer_name 12 ,case when regexp_like(line, '^( +Loto | +Inst Tk|Totals)') then trim(substr(line, 1, 15)) else null end as val1 13 ,case when regexp_like(line, '^( +Loto | +Inst Tk|Totals)') then regexp_substr(line, '[^ ]+', 16, 1) else null end as val2 14 ,case when regexp_like(line, '^( +Loto | +Inst Tk|Totals)') then regexp_substr(line, '[^ ]+', 16, 2) else null end as val3 15 ,case when regexp_like(line, '^( +Loto | +Inst Tk|Totals)') then regexp_substr(line, '[^ ]+', 16, 3) else null end as val4 16 ,case when regexp_like(line, '^( +Loto | +Inst Tk|Totals)') then regexp_substr(line, '[^ ]+', 16, 4) else null end as val5 17 ,case when regexp_like(line, '^( +Loto | +Inst Tk|Totals)') then regexp_substr(line, '[^ ]+', 16, 5) else null end as val6 18 ,case when regexp_like(line, '^( +Loto | +Inst Tk|Totals)') then regexp_substr(line, '[^ ]+', 16, 6) else null end as val7 19 ,case when regexp_like(line, '^( +Loto | +Inst Tk|Totals)') then regexp_substr(line, '[^ ]+', 16, 7) else null end as val8 20 ,case when regexp_like(line, '^( +Loto | +Inst Tk|Totals)') then regexp_substr(line, '[^ ]+', 16, 8) else null end as val9 21 ,case when regexp_like(line, '^( +Loto | +Inst Tk|Totals)') then regexp_substr(line, '[^ ]+', 16, 9) else null end as val10 22 from cdc_file 23 where regexp_like(line, '^( +Loto | +Inst Tk |Totals|Retailer Number:)') 24 ) 25 ) 26 where retailer_no is not null 27* order by 1, decode(val1, 'Loto', 1, 'Inst Tk', 2, 3) SQL> / RETAILER_N TERMINAL_N RETAILER_NAME VAL1 VAL2 VAL3 VAL4 VAL5 VAL6 VAL7 VAL8 VAL9 VAL10 ---------- ---------- ------------------------------ ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 10000 1000006 XXXX XXXX XX Default Location Totals 0.00 0.00 0 0.00 0 0.00 0 0.00 0 10000 1000008 XXXX XXXX XX Default Location Totals 0.00 0.00 0 0.00 0 0.00 0 0.00 0 200101 20010100 XXXXXXX Popular Store Loto 36,100.00 0.00 0 0.00 36 -5,646.00 0 0.00 0 200101 20010100 XXXXXXX Popular Store Inst Tk 22,000.00 0.00 0 0.00 166 -9,360.00 0 0.00 0.00 200101 20010100 XXXXXXX Popular Store Totals 58,100.00 0.00 0 0.00 202 -15,006.00 0 0.00 0 200103 20010300 XX XXXXXXXX Snack Loto 35,980.00 0.00 0 0.00 20 -3,426.00 0 0.00 0 200103 20010300 XX XXXXXXXX Snack Inst Tk 14,000.00 0.00 0 0.00 157 -9,180.00 0 0.00 0.00 200103 20010300 XX XXXXXXXX Snack Totals 49,980.00 0.00 0 0.00 177 -12,606.00 0 0.00 0 8 rows selected. SQL>
Published by: BluShadow on January 22, 2010 13:37
added the retailer's name as well, but out anonymous that we dislike the actual data on the forums... ;) -
How is it, I can't insert into table inside the function?
If I have a simple function that takes the same data with SELECT... IN... and then the information I need to insert back to the same table, but the error message says I can't insert, update, delete on a table I'm working on, but I understand that is SELECT... Will be actually copy the data from a select query in these variables that I use in my SQL function. So why, after completing Select I can't update in my SELECT stopped working already on the table.Procedures may not be called from a SQL statement.
However, you can [call procedures PHP | http://www.oracle.com/technology/pub/articles/oracle_php_cookbook/fuecks_sps.html].
Justin
-
Update/insert into table in another schema
Hello
I have a custom table that is located in another schema used by our dashboard for custom tables. I want to allow users to add/edit users and the security groups for dashboards.
I see two possible solutions to this issue, I was wondering if anyone has done so and has a better solution or pointers.
Possible solutions:
1. move the table to the APEX workspace. Not desirable, would lead to changes in the Production for the pools of connections in the repository.
2. create a temporary table where you would load the security table data when the user wishes to add/modify records in the security table and then use triggers to update the table by using the synonym to the table.
Any help would be appreciated.
Thank you
RobModify the procedure to look like to...
create or replace PROCEDURE UPDATE_TABLE(p_table IN VARCHAR2, p_column IN VARCHAR2, p_value IN VARCHAR2, p_condition IN VARCHAR2) AS v_sql_stmt VARCHAR2(4000); BEGIN v_sql_stmt := 'UPDATE ' || p_table || ' SET ' || p_column || ' = ' || p_value || ' WHERE ' || p_condition; EXECUTE IMMEDIATE v_sql_stmt; COMMIT; END UPDATE_TABLE; {code} Edited by: Tyson Jouglet on Sep 25, 2008 8:03 AM
-
help join you a table nested with ordinary table
IM creating a nested table object prtcnpt_info codelist. In a block anonymous im saying t_code as type nested table codelist.
Now when I try to join the table nested to ordinary table oracle DB and I get the error: PL/SQL: ORA-00904: "COLUMN_VALUE": invalid identifier.
Please help me on this and provide link tutorial about this concepts... Here is the code I wrote
-Start code.
create or replace type prtcnpt_info as an object (identification number
, name varchar2 (200)
(, code varchar2 (30));
create type codelist is the prtcnpt_info table;
declare
t_code codelist.
Start
Select prtcnpt_info (b.pid, b.name, pt.code) in bulk collect into t_code
party pt
mc_code b
where pt.cd in ("AAA", "BBB")
and pt.ptype_id = b.pt_type_id;
INSERT INTO table (ID
RUN_ID
DATA
P_ID
)
SELECT id
run_id
data
prtct.id-> 1
IN table_2 t2
, (by selecting column_value in table (t_code)) prtct
WHERE prtct.id = t2. P_ID; -> 2
end;
-End code;
also of the anonymous block
1 = > is this right until you get the id value (b.pid) of the tablet_code nested as prtct alias?
2 = > is this right until you reach the nested with ordinary table table? I want to join the id column in the tables.
Published by: 914912 on April 30, 2012 02:11Write the insert like this and try
insert into table ( id , run_id , data , p_id ) select id, run_id, data, prtct.id from table_2 t2 table(t_code) prtct where prtct.id = t2.p_id;
-
Insert into table1 from table1
Hello
I tried to insert into table - from select col1, col2, col3 from table b where
Table - b.change_dt between 't1d' and 'T2D.
can someone help me with the query
Thank youinsert into table-A from select col1,col2,col3 from table-b where table-b.change_dt between 'dt1' and 'dt2'
you have an additional 'from', so it will be:
insert into table-A(col1,col2,col3) (select col1, col2, col3 from table b where)
Table - b.change_dt between 't1d' and "T2D")Please, close your threads, try to clean up the forum.
-
Select the statement to insert into a table by using a loop
Hello
what I want to do is create 3 records based on this one in a loopcreate table uploadtab( itema varchar2(3), xtype varchar2(1), salesa number, margina number, salesb number, marginb number, salesc number, marginc number); insert into uploadtab (itema, xtype, salesa, margina, salesb, marginb, salesc, marginc) values ('abc', 'a', 100, .40, 300, .10, 450, .25); create table testinsert(itema varchar2(3), xtype varchar2(1), sales number, margin number);
so here's my desired for testinsert output
I don't want to use 3 insert tables if possibleabc a 100 .40 abc a 300 .10 abc a 450 .25
any help would be greatly appreciated
Thanks in advance
Published by: DM on July 7, 2010 14:22This gives a shot:
INSERT INTO testinsert ( itema , xtype , sales , margin ) SELECT itema , xtype , DECODE ( RN , 1,salesa , 2,salesb , 3,salesc ) , DECODE ( RN , 1,margina , 2,marginb , 3,marginc ) FROM uploadtab CROSS JOIN ( SELECT ROWNUM RN FROM dual CONNECT BY LEVEL <= 3 ) ;
-
divide a column value and insert it into several columns
Hello
am new to plsql.
I want to divide a characters in a column and insert into multiple columns
I tried the function substr used the symbol ',' vary its place dynamically, so I can't apply the substr function.
for example: before split
col1:
col2:
COL3:
COL4:
colu5: adsdf, fgrty, erfth, oiunth, okujt
after separation
col1: adsd
col2: fgrty
COL3: erfth
COL4: oiunth
col5: adsdf, fgrty, erfth, oiunth, okujt
can someone help me
Thank you
Published by: 800324 on December 23, 2010 08:28
Published by: 800324 on December 23, 2010 08:36What:
SQL> create table t 2 (col1 varchar2(30) 3 ,col2 varchar2(30) 4 ,col3 varchar2(30) 5 ,col4 varchar2(30) 6 ,col5 varchar2(30) 7 ); Table created. SQL> insert into t (col5) values ('adsdf,fgrty,erfth,oiunth,okujt'); 1 row created. SQL> insert into t (col5) values ('x,y'); 1 row created. SQL> insert into t (col5) values ('a,b,c,d'); 1 row created. SQL> select * from t; COL1 COL2 COL3 COL4 COL5 ------------------------------ ------------------------------ ------------------------------ ------------------------------ ------------------------------ adsdf,fgrty,erfth,oiunth,okujt x,y a,b,c,d 3 rows selected. SQL> SQL> merge into t a 2 using ( with t1 as ( select col5||',' col5 3 from t 4 ) 5 select substr(col5, 1, instr(col5, ',', 1, 1)-1) col1 6 , substr(col5, instr(col5, ',', 1, 1)+1, instr(col5, ',', 1, 2)- instr(col5, ',', 1, 1)-1) col2 7 , substr(col5, instr(col5, ',', 1, 2)+1, instr(col5, ',', 1, 3)- instr(col5, ',', 1, 2)-1) col3 8 , substr(col5, instr(col5, ',', 1, 3)+1, instr(col5, ',', 1, 4)- instr(col5, ',', 1, 3)-1) col4 9 , rtrim(col5, ',') col5 10 from t1 11 ) b 12 on ( a.col5 = b.col5 ) 13 when matched then update set a.col1 = b.col1 14 , a.col2 = b.col2 15 , a.col3 = b.col3 16 , a.col4 = b.col4 17 when not matched then insert (a.col1) values (null); 3 rows merged. SQL> select * from t; COL1 COL2 COL3 COL4 COL5 ------------------------------ ------------------------------ ------------------------------ ------------------------------ ------------------------------ adsdf fgrty erfth oiunth adsdf,fgrty,erfth,oiunth,okujt x y x,y a b c d a,b,c,d 3 rows selected. SQL>
Assuming you're on 9i...
-
insert into the table all the permutations of values
Hello
I need writing pl/sql code to insert data into a table for the test. I need to insert into 4 columns all the permutations of a, b, c, and null. Can someone help me with this please? It's in Oracle 11 g. For eg., if I have a table with the columns col1 and col2, col3 col4. I want to have all kinds of permutations of a, b, c and nothing in there which means there will be 256 rows after insertion.You can create a table to SELECT it:
select ta.fld, tb.fld, tc.fld, td.fld from (select 'a' fld from dual union all select 'b' from dual union all select 'c' from dual union all select null from dual) ta, (select 'a' fld from dual union all select 'b' from dual union all select 'c' from dual union all select null from dual) tb, (select 'a' fld from dual union all select 'b' from dual union all select 'c' from dual union all select null from dual) tc, (select 'a' fld from dual union all select 'b' from dual union all select 'c' from dual union all select null from dual) td ;
Maybe you are looking for
-
Update the BIOS for Satellite U400-10O required
Hello world I have a SATELLITE U400-10 oC (PSU40E-00R00EG3). It is an old product, but once I always love use regularly. Recently, I bought a battery for this device upgrade. Unfortunately, it does not recognize the laptop. The work of the battery, b
-
Its satellite A210-131 driver does not support DirectSound entry
From Premiere Pro CS3, an error message is displayed: -"Der zurzeit installierte Soundkartentreiber unterstuetzt keine DirectSound-Eingaenge"Es ist keine Audioaufnahme possible".-"The its installed card driver does not support the entry of DirectSoun
-
Why when I get an email there go on pop and don't stay in my Inbox. all my mail will remain in the pop and the Inbox will remain empty. can someone please.
-
Subvi output displayed dynamically on XY graph
Hi, I'm trying to implement a VI to apply a voltage signal ramp up to a door of transistor and measure the current resulting from the source to the drain. It is necessary that the data is graphically in real time as it is acquired. I managed to do it
-
The speed at which messages are approved?
I posted a message earlier, hoping to get help, but this message has not yet been approved. How long message approval usually take? Thank you Gerry