Insert using select statement
Hi,
I am trying to insert values using select statement. But this is not working
INSERT INTO contribution_temp_upgrade
(PRO_ID,
OBJECT_NAME,
DELIVERY_DATE,
MODULE_NAME,
INDUSTRY_CATERGORIZATION,
ADVANTAGES,
REUSE_DETAILS)
VALUES
SELECT
:P1_PROJECTS,
wwv_flow.g_f08(vRow),
wwv_flow.g_f09(vRow),
wwv_flow.g_f10(vRow),
wwv_flow.g_f11(vRow),
wwv_flow.g_f12(vRow),
wwv_flow.g_f13(vRow)
FROM DUAL;
Please let me know what i am missing..
Thanks
Sudhir
Try this
INSERT INTO contribution_temp_upgrade
(PRO_ID,
OBJECT_NAME,
DELIVERY_DATE,
MODULE_NAME,
INDUSTRY_CATERGORIZATION,
ADVANTAGES,
REUSE_DETAILS)
SELECT
:P1_PROJECTS,
wwv_flow.g_f08(vRow),
wwv_flow.g_f09(vRow),
wwv_flow.g_f10(vRow),
wwv_flow.g_f11(vRow),
wwv_flow.g_f12(vRow),
wwv_flow.g_f13(vRow)
FROM DUAL;Note: when you are selecting a value using select statement, you should not specify the keyword "values".
i assume you have already assigned value for your bind variable :P1_PROJECTS and rest of the functions will return some value.
Regards,
Prazy
Similar Messages
-
Number of rows inserted is different in bulk insert using select statement
I am facing a problem in bulk insert using SELECT statement.
My sql statement is like below.
strQuery :='INSERT INTO TAB3
(SELECT t1.c1,t2.c2
FROM TAB1 t1, TAB2 t2
WHERE t1.c1 = t2.c1
AND t1.c3 between 10 and 15 AND)' ....... some other conditions.
EXECUTE IMMEDIATE strQuery ;
These SQL statements are inside a procedure. And this procedure is called from C#.
The number of rows returned by the "SELECT" query is 70.
On the very first time call of this procedure, the number rows inserted using strQuery is *70*.
But in the next time call (in the same transaction) of the procedure, the number rows inserted is only *50*.
And further if we are repeating calling this procedure, it will insert sometimes 70 or 50 etc. It is showing some inconsistency.
On my initial analysis it is found that, the default optimizer is "ALL_ROWS". When i changed the optimizer mode to "rule", this issue is not coming.
Anybody faced these kind of issues?
Can anyone tell what would be the reason of this issue..? any other work around for this...?
I am using Oracle 10g R2 version.
Edited by: user13339527 on Jun 29, 2010 3:55 AM
Edited by: user13339527 on Jun 29, 2010 3:56 AMYou have very likely concurrent transactions on the database:
>
By default, Oracle Database permits concurrently running transactions to modify, add, or delete rows in the same table, and in the same data block. Changes made by one transaction are not seen by another concurrent transaction until the transaction that made the changes commits.
>
If you want to make sure that the same query always retrieves the same rows in a given transaction you need to use transaction isolation level serializable instead of read committed which is the default in Oracle.
Please read http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10471/adfns_sqlproc.htm#ADFNS00204.
You can try to run your test with:
set transaction isolation level serializable;If the problem is not solved, you need to search possible Oracle bugs on My Oracle Support with keywords
like:
wrong results 10.2Edited by: P. Forstmann on 29 juin 2010 13:46 -
How to get the inserted row primary key with out using select statement
how to return the primary key of inserted row ,with out using select statement
Edited by: 849614 on Apr 4, 2011 6:13 AMyes thanks to all ,who helped me .its working fine
getGeneratedKeys
String hh = "INSERT INTO DIPOFFERTE (DIPOFFERTEID,AUDITUSERIDMODIFIED)VALUES(DIPOFFERTE_SEQ.nextval,?)";
String generatedColumns[] = {"DIPOFFERTEID"};
PreparedStatement preparedStatement = null;
try {
//String gen[] = {"DIPOFFERTEID"};
PreparedStatement pstmt = conn.prepareStatement(hh, generatedColumns);
pstmt.setLong(1, 1);
pstmt.executeUpdate();
ResultSet rs = pstmt.getGeneratedKeys();
rs.next();
// The generated order id
long orderId = rs.getLong(1); -
How to pass parameter in Function by using select statement?
Hi,
I got a problem. I cant pass in parameter to function by using select statement. But it can pass in parameter by using 'hardcode' method. How can I solve this problem?
Eg,
select * from table (SplitFunction('HS750020,HS750021')) <<< this work.
but
select * from table (SplitFunction(select LOT_NO from TRACER_SEARCH_SCHEDULE where JOB_ID = '36')) <<< do not work.
Thanks for who try to help. Thanks.skymonster84 wrote:
I have try this before. But it not work.here is an example
create or replace type stringlist as table of varchar2(100)
create or replace function splitstring(pstring in varchar2) return stringlist
as
lstringlist stringlist;
begin
select regexp_substr(pstring,'[^,]+',1, level) bulk collect into lstringlist
from dual
connect by level <= length(pstring)-length(replace(pstring,','))+1;
return lstringlist;
end;
select * from table(select splitstring('xx,yy,zz') from dual)
create table t(str varchar2(100))
insert into t values('x,y,z')
insert into t values('a,b,c')
select * from table(select splitstring(str) from t where rownum<2)
/If you supply multiple values then it will fail.
select * from table(select splitstring(str) from t)
/ -
Insert Using SELECT & Sub-SELECT
Hi All,
I am trying to insert records into a table using SELECT statement. The SELECT statement has a Sub-SELECT statement as follows:
INSERT INTO table1(c1,c2,c3,c4,c5)
SELECT c1,c2, (SELECT MAX(C3)+a1.c3
FROM table1
WHERE c1 = var1
AND c2 = a1.c2
GROUP BY c3),c4,c5,
FROM table1 a1
WHERE c1 = var1
The above works fine when run from SQL*PLUS but gives compilation error when included in PL/SQL pacakge.
I am using Oracle 8.1.7.
Could you any one please tell me if I have missed something?
Thanks,
Satyen.In 8i, you will need to use dynamic SQL to execute this statement because the PL/SQL parser does not understand all SQL syntax (including SELECT in a column list).
execute immediate
'INSERT INTO table1(c1,c2,c3,c4,c5)' ||
' SELECT c1, c2, (SELECT MAX(C3)+a1.c3 FROM table1 WHERE c1 = :var1 AND c2 = a1.c2 GROUP BY c3), c4, c5' ||
' FROM table1 a1 WHERE c1 = :var1' using var1, var1; -
Using Select statement in IF condition?
hi all,
Can i use select statement in IF COndition in pl sql ?
eg like- if( select 1 from ASD) then
end if;There is no way to do any kind of select statement inside if conditions.
Why don't test simple cases like this first?
An example to show it.
SQL> begin
2 if exists (select 1 from dual) then
3 dbms_output.put_line('ok');
4 end if;
5 end;
6 /
if exists (select 1 from dual) then
ERRORE alla riga 2:
ORA-06550: line 2, column 5:
PLS-00204: function or pseudo-column 'EXISTS' may be used inside a SQL
statement only
ORA-06550: line 2, column 2:
PL/SQL: Statement ignored
SQL> begin
2 if ( (select count(*) from dual) > 0 ) then
3 dbms_output.put_line('ok');
4 end if;
5 end;
6 /
if ( (select count(*) from dual) > 0 ) then
ERRORE alla riga 2:
ORA-06550: line 2, column 8:
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
( - + case mod new not null others <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev sum variance
execute forall merge time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
<an alternatively-quoted string literal with character set specification>
<an alternativ
ORA-06550: line 2, column 33:
PLS-00103: Encountered the symbol ")" when expecting one of the following:
. , @ ; for <an identifier>
<a double-quoted delimited-identifier> group having intersect
minus order partition start subpartition union where connect
SQL> begin
2 if ( 0 in (select count(*) from dual) ) then
3 dbms_output.put_line('ok');
4 end if;
5 end;
6 /
if ( 0 in (select count(*) from dual) ) then
ERRORE alla riga 2:
ORA-06550: line 2, column 12:
PLS-00405: subquery not allowed in this context
ORA-06550: line 2, column 2:
PL/SQL: Statement ignoredBye Alessandro -
How can I select columns from a table EMP, using Select statement?.
Hi Friends,
How can I select columns from a table EMP?.
I want to select columns of EMP table, using select statement.
Please reply me urgently.
ShahzadSomething like this:
scott@DBA> select empno,ename,job from emp;
EMPNO ENAME JOB
7369 SMITH CLERK
7499 ALLEN SALESMAN
7521 WARD SALESMAN
7566 JONES MANAGER
7654 MARTIN SALESMAN
7698 BLAKE MANAGER
7782 CLARK MANAGER
7788 SCOTT ANALYST
7839 KING PRESIDENT
7844 TURNER SALESMAN
7876 ADAMS CLERK
7900 JAMES CLERK
7902 FORD ANALYST
7934 MILLER CLERK
14 rows selected.Check the documentation:
http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10002.htm#sthref9697
Message was edited by:
Delfino Nunez -
How to fetch negative sign data using select statement
hi gurus,,
i hv to fetch data which is negative in nature using select statement i m using ppdit table and wrbtr field.(it contains both negative and positive data)....wat sud i add with select statement...plz help me..
thnx in advance
Message was edited by:HI,
I think you can use LT or < 0.0 in the WHERE clause to get all the -ve values. Once you get them treat them as negative.
Regards,
Sesh -
FETCHING VALUES IN MULTI RECORD BLOCK FROM ANOTHER TABLE USING SELECT STATEMENT.
Hi,
I have one multi record block in which i want to fetch values
(more then one record) from another table using select statement
IN KEY NEXT ITEM.I am getting following error.
ORA-01422: exact fetch returns more than requested number of rows
Thanks in advance.In your case I see no reason to use non-database block and to try to populate it from a trigger with a query, instead of using the default forms functionality where you can associate the block and the fields with table, create where clause using bind variables and simply use execute_query() build-in to populate the block. The power of the forms is to use their build-in functionality to interact with the database.
Also, you can base your block on a query, not on a table and you dynamically change this query using set_block_property() build-in. You can use any dynamic queries (based on different data sources) and you simply need to control the column's data type, the number of the columns and their aliases. Something like creating inline views as a block data source.
However, you can replace the explicit cursor with implicit one like
go_block('non_db_block_name');
first_record();
FOR v_tab IN (SELECT *
FROM tab
WHERE col_name = :variable)
LOOP
:non_db_block_name.field1 := v_tab.col1;
:non_db_block_name.field2 := v_tab.col2;
next_record();
END LOOP; -
Can i use select statements in LDB
Hai All,
Can i use select statements and internal table in a LDB program.
my requirement is that if i enter company code , fiscal year and reporting periods.
generally fiscal year will be jan to dec.but in my requirement the fiscal year is apr of previous year to march of currentyear.
so as i require the last years data can iuse select statement in that ldb program or is there any solution for this.
Thanks in Advance
kiranHi Kiran,
To retrive records from ldb you have to use the
GET <node> statement. This will invoke the selection screen of the node. An alternate solution is to use the function module LDB_PROCESS.
Please see the following link for help and example
http://help.sap.com/saphelp_nw04/helpdata/en/64/237f8cd43711d1950b0000e8353423/content.htm
Thanks
Vinod -
How to avoid data repetation when using select statements with innerjoin
how to avoid data repetation when using select statements with innerjoin.
thanks in advance,
satheeshyou can use a query like this...
SELECT DISTINCT
frg~prc_group1 "Product Group 1
frg~prc_group2 "Product Group 2
frg~prc_group3 "Product Group 3
frg~prc_group4 "Product Group 4
frg~prc_group5 "Product Group 5
prc~product_id "Product ID
txt~short_text "Product Description
UP TO 10 ROWS
INTO TABLE l_i_data
FROM
Joining CRMM_PR_SALESG and
COMM_PR_FRG_ROD
crmm_pr_salesg AS frg
INNER JOIN comm_pr_frg_rod AS prd
ON frgfrg_guid = prdfragment_guid
Joining COMM_PRODUCT and
COMM_PR_FRG_ROD
INNER JOIN comm_product AS prc
ON prdproduct_guid = prcproduct_guid
Joining COMM_PRSHTEXT and
COMM_PR_FRG_ROD
INNER JOIN comm_prshtext AS txt
ON prdproduct_guid = txtproduct_guid
WHERE frg~prc_group1 IN r_zprc_group1
AND frg~prc_group2 IN r_zprc_group2
AND frg~prc_group3 IN r_zprc_group3
AND frg~prc_group4 IN r_zprc_group4
AND frg~prc_group5 IN r_zprc_group5.
reward it it helps
Edited by: Apan Kumar Motilal on Jun 24, 2008 1:57 PM -
Hi,
How can I use select stat. rather than join to join to tables so that I have all the fields from both tables appearing in my output.Hi,
There are two ways to handle the problem.
1. For all entries
Types: begin of str1_tab,
lgnum type lgnum,
ivnum type LVS_IVNUM,
ivpos type LVS_IVPOS,
lgtyp type lgtyp,
lgpla type lgpla,
idatu type LVS_IDATU,
uname type LINK_UNAME,
end of str1_tab.
Data: it_tab1 type table of str1_tab,
wa_tab1 like line of it_tab1.
DATA: it_tab3 TYPE TABLE OF str1_tab,
wa_tab3 LIKE LINE OF it_tab3.
select lgnum ivnum lgtyp uname FROM link INTO CORRESPONDING FIELDS OF
TABLE it_tab1 where lgnum = pa_lgnum AND ivnum IN s_ivnum.
<b>if sy-subrc eq 0.</b>
select lgnum ivnum lgpla idatu from linp into corresponding
fields of table it_tab3 for all entries in it_tab1 <b>where lgnum = itab1-lgnum and ivnum = itab1-ivnum.</b><b>endif.</b>
LOOP AT it_tab3 INTO wa_tab3.
<b>clear wa_tab1.</b>
READ TABLE it_tab1 INTO wa_tab1 WITH
KEY lgnum = wa_tab3-lgnum
ivnum = wa_tab3-ivnum.
IF sy-subrc = 0.
move-corresponding it_tab1 to it_tab3.
<b>modify it_tab3 from wa3 transporting lgtyp uname where lgnum = wa_tab3-lgnum
and ivnum = wa_tab3-ivnum.</b>ENDIF.
clear it_tab3.
endloop.
2. Use inner join
Types: begin of str1_tab,
lgnum type lgnum,
ivnum type LVS_IVNUM,
ivpos type LVS_IVPOS,
lgtyp type lgtyp,
lgpla type lgpla,
idatu type LVS_IDATU,
uname type LINK_UNAME,
end of str1_tab.
Data: it_tab1 type table of str1_tab,
wa_tab1 like line of it_tab1.
select linklgnum linkivnum linklgtyp linkuname linplgpla linpidatu FROM link inner join linp on linklgnum = linplgnum
and linkivnum = linkivnum
into TABLE it_tab1 where lgnum = pa_lgnum AND ivnum IN s_ivnum.
Now itab1 will contain all the values -
How to insert variable value using select statement - Oracle function
Hi,
I have a function which inserts record on basis of some condition
INSERT INTO Case
Case_ID,
Case_Status,
Closure_Code,
Closure_Date
SELECT newCaseID,
caseStatus,
Closure_Code,
Closure_Date,
FROM Case
WHERE Case_ID = caseID
Now i want new casestatus value in place of select statement caseStatus value. I have a variable m_caseStatus and i want to use the value of this variable in above select statement.
how can i use this.
thanksHi,
I have a function which inserts record on basis of some condition
INSERT INTO Case
Case_ID,
Case_Status,
Closure_Code,
Closure_Date
SELECT newCaseID,
caseStatus,
Closure_Code,
Closure_Date,
FROM Case
WHERE Case_ID = caseID
Now i want new casestatus value in place of select statement caseStatus value. I have a variable m_caseStatus and i want to use the value of this variable in above select statement.
how can i use this. Do not select Case_Status from inner select, so null will be inserted then after inserting it update the case status with m_caseStatus.
Regards. -
DYNAMIC QUERY FOR INSERT USING SELECT
Hi All,
I am facing an issue...I am un bale to do an dynamic query. i have explained my code and the sample create, insert statements. I shud insert values in a table using a select statement dynamically..
create table listing (tel_no varchar2(16), list_key varchar2(30));
create table dummy_extract ( extract_name varchar2(10),extract_query varchar2(400),extract_date date );
create table dummy_query (tel_no varchar2(16), list_key varchar2(30));
insert into listing (tel_no ,header_key) values ('123456','123.23');
insert into dummy_extract (extract_name,extract_query,extract_date) values ('SP','SELECT TEL_NO, LIST_KEY FROM LISTING','10-DEC-2010');
SET SERVEROUTPUT ON
declare
CURSOR CUR_QUERY IS
SELECT * FROM DUMMY_EXTRACT ;
V_STMT VARCHAR2(4000);
BEGIN
FOR I IN CUR_QUERY LOOP
V_STMT := 'INSERT INTO DUMMY_QUERY VALUES ' ||(I.EXTRACT_QUERY ) ;
EXECUTE IMMEDIATE V_STMT using i.extract_query;
DBMS_OUTPUT.PUT_LINE (V_STMT);
END LOOP;
END ;Hi Blue shadow and Saubik,
I tried my query.It shows missing expression...Could you tell me the reason...
SET SERVEROUTPUT ON
declare
CURSOR CUR_QUERY IS
SELECT * FROM DUMMY_EXTRACT ;
V_STMT VARCHAR2(4000);
BEGIN
FOR I IN CUR_QUERY LOOP
--V_STMT := 'INSERT INTO'|| DUMMY_QUERY ||'VALUES ' ||(I.EXTRACT_QUERY ) ;
EXECUTE IMMEDIATE 'INSERT INTO DUMMY_QUERY VALUES ' ||(I.EXTRACT_QUERY ) ;
DBMS_OUTPUT.PUT_LINE (V_STMT);
END LOOP;
END ;
Error report:
ORA-00936: missing expression
ORA-06512: at line 14
00936. 00000 - "missing expression"
*Cause:
*Action: -
Re-use SELECT statement in several procedures (other than copy-and-paste)
Our site uses a procedure of the following procedure construct to generate Excel spreadsheets:
TYPE retCur is REF CURSOR;
PROCEDURE get_data_for_excel (
p_filter1 VARCHAR2
,p_filter2 VARCHAR2
,c_OutCursor out retCur
IS
retCursor retcur
BEGIN
BEGIN
OPEN c_OutCursor FOR
SELECT XMLELEMENT("TR", XMLFOREST(
"col1" AS "TD"
,"col2" AS "TD"
,"col3" AS "TD"
)).getstringval()DATA FROM (SELECT * FROM
SELECT col1, col2, col3
FROM sometable
WHERE somecolumn = p_filter1
AND someothercolumn = p_filter2
) x);
END;
END get_data_for_excel
My question is, the subselect:
SELECT col1, col2, col3
FROM sometable
is used in another procedure. Is there a way to reuse the select from the other procedure into this procedure so we don't copy-and-paste each time the other procedure is changed?
Thanks a lot.This is a design decision you need to make BEFORE it goes into production.
Right now you have
procedure get_data_for_excel (
p_filter1 VARCHAR2
,p_filter2 VARCHAR2
,c_OutCursor out retCur );
What, I think jihuyao is trying to say is: convert it to a pipelined function.
I agree with jihuyao as I have ran into to this problem before.
create type d4e_t as object ( DATA xmltype);
create type d4e_table is table of d4e_t;
create or replace function get_data_for_excel (
p_filter1 VARCHAR2
,p_filter2 VARCHAR2 )
return d4e_table pipelined;
as
begin
for curr in ( --start of SELECT statement
SELECT XMLELEMENT("TR", XMLFOREST(
"col1" AS "TD"
,"col2" AS "TD"
,"col3" AS "TD"
)).getstringval()DATA FROM (SELECT * FROM
SELECT col1, col2, col3
FROM sometable
WHERE somecolumn = p_filter1
AND someothercolumn = p_filter2
) x) )
LOOP
pipe row( d4e_t( curr.data ) );
end loop;
return;
end;
From there, you use it elsewhere as if it were a table.
insert into t
select X.data from table( get_data_for_excel( l_var1, l_var2 ) ) X;
MK
Maybe you are looking for
-
No variable audio output for Cisco CHS 435HDC set top box.
Background: Until the other day I had my stb connectected to a TV, using TV sound, with an HDMI cable. The P265v2 remote volume control changed the TV volume. No problems. My new TV & home theater system was recently installed. We don't use the T
-
AS 2.0 help with transitions
i'm wondering what the best method is to apply the same transtion to multiple images in a photo based site. i've created a fade in as my transition (see attached code) and would like to apply the same effect to all images in the site. thanks in advan
-
anyone able to decipher this,....? panic(cpu 0): Uncorrectable machine check: pc = 0000000011D58C80, msr = 0000000000141000, dsisr = 40000000, dar = 0000000025190004 AsyncSrc = 0000000000000000, CoreFIR = 0000000000000000 L2FIR = 0000000000000000, Bu
-
Installing Windows XP on new MacBook
What do I need to know. Can I use the same version I puchased for my PC. How do I install it? I am a new Mac user. Any tips, pointers or otherwise would be apprecated. Also I need to puchase Office and am a student. Where should I purchase it? Thanks
-
Essbase services shutting down automatically
Please all the gurus help me with this. The essbase services are shutting down automatically.