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
Similar Messages
-
Since the last firefox upgrade my copy/paste and adobe doc viewer functionality is gone.
== This happened ==
Every time Firefox opened
== last upgradeThat is a bug in Firefox.
You can set the Boolean pref <b>dom.event.clipboardevents.enabled</b> to <i>false</i> on the <b>about:config</b> page or alternatively hold down Ctrl+C keys until the translate selection disappears that text in the left input text area start flashing.
*[[/questions/940871]]
*Bug 807599 - Can't copy and paste from Google Translate since Firefox 16.0.2 -
Selecting objects or ares of the screen, copy, and paste are missing
Hi,
Why such a standard and important functionality like selecting objects or areas of the screen, then copy and paste them are missing in the product?
AHi,
You can't select objects in Ideas, you can copy/paste the whole layer's contents by duplicating it, there is an icon in the layers panel, next to flip and merge down icons.
Emi -
I'm accustomed to copying pictures that I placed on a third-party host (Photobucket or Multiply) and pasting them into the body of a Yahoo Mail message. I can't do that on Firefox. When I click "Paste," nothing happens.
https://support.mozilla.com/en-US/kb/Clipboard+not+working
-
Have a MacBook Pro. Been using hot mail/Safari. Suddenly can't copy and paste an e mail. Can't make an att> without getting an error message.."0 bytes empty" Got ahold of hot mail was told yes there is a problem between Mac and hot mail Safari and for $59.00 they can fix it. Forgot to ask if the same would apply if I were a pc user. Anbody shed some light on this? Anyone recomend a better em ail service other than g mail?
HELP! Is there anyone out there who knows how I can fix this????
Thanks! -
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 -
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 to use SELECT statement to extract KNA1-NAME1 and KNB1-ZSABE
In building table I_KNA1 in form f_extract_data, an additional select statement is needed to select and append datafrom (KNA1 and KNB1) to existing I_KNA1
In form f_extract_data table i_kna1 is populated with data from zd_kna101.(where ZD_KNA101 is a view of KNA1, KNB1 and KNBK. It's a joint of these three tables.) This will take care of all customers with KNBK-BANKL and KNBK-BANLN populated. But this does not include new customers created in SAP CRM (no KNBK records). Therefore a separate SELECT statement is needed to extract KNA1-NAME1 and KNB1-ZSABE for customers created in SAP CRM(the customers who do do not have BANKL and BANKN). These selected records are then need to be appended to I_KNA1. It's possible that new selection statement might extract records that are already in existing I_KNA1 table. IF this is the case, right after the append, sort I_KNA1 and remove duplicate records.
form f_extract_data.
select kunnr " Customer Number
name1 " Name
zsabe " Business Unit
bankl " Legacy Bank Key
bankn " Legacy Bank Account
from zd_kna101 " View of KNA1, KNB1, and KNBK
into table i_kna1
for all entries in i_doc_by_ref
where kunnr = i_doc_by_ref-kunnr
and zsabe in s_zsabe.
if sy-subrc <> 0.
message a116 with 'customer'. " Customer Table is empty. HALT!!!
else.
sort i_kna1 by kunnr.
endif.
will I have to use the join statement(for KNA1-NAME1 and KNB1-ZSABE using the key as KUNNR) here or give two seperate select statements for extracting data from KNA1 and KNB1 using the key as KUNNR.
THANKS FOR THE HELP.I would suggest using the join on KUNNR. Maybe something like this.
data: begin of itab occurs 0,
kunnr type kna1-kunnr,
name1 type kna1-name1,
ZSABE type knb1-ZSABE,
end of itab.
select kna1~kunnr kna1~name1 knb1~zsabe
into table itab
from kna1
inner join knb1
on kna1~kunnr = knb1~kunnr
where ........
Regards,
Rich Heilman -
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)
/ -
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
SudhirTry 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 -
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 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);
Maybe you are looking for
-
Improper Install of Hyper-V 2012 R2 Integration Services on 2008 R2 VMs
I have two VMs that have one or more missing/broken services after upgrading to Integration Services 6.3.9600.16384. On one VM the Hyper-V Remote Desktop Virtualization Service is missing and the Hyper-V Data Exchange Service won't start. The other
-
Issue with Sender Side JDBC processing
Hello, I am facing some problem with Sender Side JDBC Processing. I am polling the DB MY SQL Server 2000 and using some SELECT statement i picked up some data and updated the DB with an UPDATE statement. At the receiver side i am using RFC adapter wh
-
Web based mail program like hotmail or yahoo
Hi All, How do I create a web based mail program like yahoo or hotmail using Java Mail API? If any one knows please let me know. my email id: [email protected] Thanks and Regards, Sarat
-
Why can't I successfully download InDesign (CC)
When I download InDesign from my Creative Cloud account, the download fails and the error message tells me that the download was unable to extract to the temp file. I am running a 32 bit version of Windows 7. How do I fix that?
-
HT1386 My iTunes will not synch music downloaded from CDs from my laptop to my Iphone
My iTunes will not synch music downloaded from CDs from my laptop to my Iphone. Help!