Cursor - Suggestions for Dynamic select statements
Hey,
Am trying to define a cursor like this -
cursor c1 is
select table_name from dba_tables INTERSECT select table_name from dba_tables@SOME_DBLINKMy need is to pass this dblink as IN parameter to the procedure and use it in the select statement for cursor. How can I do this?
Any suggestion is highly appreciated. Thanks!
Well that was meant to be my point. If you had two, you wouldn't (I hope) call the second one "c2" - you would be forced to think about what it represented, and name it "c_order_history" or something. Sticking "1" on the end does not make an extensible naming convention for cursors any more than it does for variables, procedures, tables or anything else, and so the "1" in "c1" is redundant because there will never be a c2.
Similar Messages
-
Need to wite pl sql procedure for dynamic select statement
Need pl sql procedure for a Dynamic select statement which will drop tables older than 45 days
select 'Drop table'||' ' ||STG_TBL_NAME||'_DTL_STG;' from IG_SESSION_LOG where substr(DTTM_STAMP, 1, 9) < current_date - 45 and INTF_STATUS=0 order by DTTM_STAMP desc;I used this to subtract any data older than 2 years, adjustments can be made so that it fits for forty five days, you can see how I changed it from the originaln dd-mon-yyyy to a "monyy", this way it doesn't become confused with the Static data in the in Oracle, and call back to the previous year when unnecessary:
TO_NUMBER(TO_CHAR(A.MV_DATE,'YYMM')) >= TO_NUMBER(TO_CHAR(SYSDATE - 365, 'YYMM')) -
Inner Join for Dynamic Select statement
Hi All,
Can some one please help me in rewriting the below select statement where i have to remove the existing table1 by putting a dynamic table name which has the same table structure.
select a~zfield1
a~zfield2
from ztab1 as a
inner join ztab2 as b
on b~ztab1-zfield3 = a~ztab2-zfield3
where a~zfield4 = 'A'.
I am looking something as below. But encountering an error when using the below statement
select a~zfield1
a~zfield2
from (v_ztab1) as a
inner join ztab2 as b
on b~ztab1-zfield3 = a~ztab2-zfield3
where a~zfield4 = 'A'.
No Separate selects please. Please help me in rewriting the same select statement itself.
Regards,
PSKhi,
What error you are getting ?
Also INTO is missing from the statement.
SELECT pcarrid pconnid ffldate bbookid
INTO TABLE itab
FROM ( spfli AS p
INNER JOIN sflight AS f ON pcarrid = fcarrid AND
pconnid = fconnid )
WHERE p~cityfrom = 'FRANKFURT' AND
p~cityto = 'NEW YORK' .
thanks -
How can I open a cursor for dynamic sql statement
Hi,
I'm facing issues opening a cursor for dynamic sql statement : PLS-00455: cursor 'RESULT1' cannot be used in dynamic SQL OPEN statement.
CREATE OR REPLACE FUNCTION DEMO
(MN_I in VARCHAR)
return AB_OWNER.ABC_Type.NonCurTyp is
RESULT1 AB_OWNER.ABC_Type.NonCurTyp;
sql_stmt VARCHAR2(4000);
BEGIN
sql_stmt := 'SELECT * FROM AB_OWNER.DUN WHERE JZ_I in ('||mn_i||') ORDER BY app.ACC_I';
OPEN RESULT1 FOR sql_stmt;
END IF;
return RESULT1;
END DEMO;
What changes should I make in the code so that it doesn't fail? I can't change the definition of RESULT1 cursor though.Gangadhar Reddy wrote:
I used SYS REFCURSOR and was able to implement successfully.How many times did you run this successful implementation that does not use bind variables?
Because this is what will happen when it runs a lot.
http://download.oracle.com/docs/cd/E11882_01/server.112/e17766/e2100.htm#sthref1874
http://forums.oracle.com/forums/search.jspa?q=%2BORA-04031%20%2Bbind&objID=c84&dateRange=all&rankBy=10001&start=30
And you will have to regularly restart the server, or possibly slightly less invasive, flush the shared pool.
Flushing Shared Pool regularly
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1516005546092
>
Ok, this is an easy one to diagnose.
You are not using bind variables. This is terrible. Flushing the shared pool is a bad
solution -- you are literally killing the performance on your box by not using them.
If I was to write a book on how to build non scalable applications in Oracle, this
would be the first and last chapter. This is a major cause of performance issues and a
major inhibitor of scalability in Oracle. The way the Oracle shared pool (a very
important shared memory data structure) operates is predicated on developers using bind
variables. If you want to make Oracle run slowly, even grind to a total halt just
refuse to use them.
>
But, please feel free to go ahead with this successful implementation.
I just hope anyone else who reads this doesn't make the same mistake. -
Hello Gurus,
We have a dynamic SELECT statement in our BW Update Rules where the the Selection Fields are populated at run-time and so are the look-up target and also the WHERE clause. The code basically looks like below:
SELECT (lt_select_flds)
FROM (lf_tab_name)
INTO CORRESPONDING FIELDS OF TABLE <lt_data_tab>
FOR ALL ENTRIES IN <lt_source_data>
WHERE (lf_where).
In this instance, we are selecting 5 fields from Customer Master Data and the WHERE condition for this instance of the run is as below:
WHERE: DIVISION = <lt_source_data>-DIVISION AND DISTR_CHAN = <lt_source_data>-DISTR_CHAN AND SALESORG = <lt_source_data>-SALESORG AND CUST_SALES = <lt_source_data>-SOLD_TO AND OBJVERS = 'A'
This code was working fine till yesterday when we encountered serious performance problems and the Basis team had to do some changes at the DB level [Oracle]. Ever since, when we execute our data load, we get the CX_SY_DYNAMIC_OSQL_SEMANTICS.
Is setting changes at the Oracle level cause issues with how the data is being read at the DB. If yes, can you suggest what can we do to this code to get is working correctly [in case Basis can't revert back their changes]?
Would appreciate any help we can get here.You don't understand - this error comes up when we run specific BEx queries. It was working yesterday, but today it is not. Our support package did not change from yesterday. We did not apply any OSSnotes.
We are however doing pre-prepare on our Prod system.
The temporary table is used to store SIDs for use in the join. the table exists in the dictionary, but not at an Oracle level. -
FAGLL03 : Submit syntax for dynamic selections
Hi Experts,
My z report contains following fields in selction screen.
1 . G/ L account
2. Comapny code
3. posting date
4. document type
5. layout
In my z report i used following syntax for passing selection screen values to standard program and getting data.
SUBMIT FAGL_ACCOUNT_ITEMS_GL
WITH SD_SAKNR IN S_SAKNR
WITH SD_BUKRS IN S_BUKRS
WITH X_OPSEL EQ ' '
WITH X_CLSEL EQ ' '
WITH X_AISEL EQ 'X'
WITH SO_BUDAT IN S_BUDAT
WITH PA_VARI EQ P_VAR
EXPORTING LIST TO MEMORY
AND RETURN.
The above syntax is not working for dynamic selection field ( document type ), entire document types data is fetching from standard program. I want to fetch document type data based on my z report selection values for document type field.
Expect for document type field , submit syntax is working.
kindly provide submit syntax for my above requirement .
Any suggestions from experts....
thanks & regards,
Hari priya
Edited by: Hari Priya on Aug 24, 2009 4:33 PMHi,
Try like this.
call function 'RS_REFRESH_FROM_SELECTOPTIONS'
exporting
curr_report = 'FAGL_ACCOUNT_ITEMS_GL'
tables
selection_table = i_sel[].
Fill your profit center values in i_sel
Submit FAGL_ACCOUNT_ITEMS_GL with selection-table i_sel and return
WITH FREE SELECTIONS TEXPR AND RETURN
Regards,
Shamma -
How to find for which select statement performance is more
hi gurus
can anyone suggest me
if we have 2 select statements than
how to find for which select statement performance is more
thanks®ards
kals.hi check this..
1 .the select statement in which the primary and secondary keys are used will gives the good performance .
2.if the select statement had select up to i row is good than the select single..
go to st05 and check the performance..
regards,
venkat -
Submit syntax for dynamic selections for T-code FAGLL03
Hi Experts,
My z report contains following fields in selction screen.
1 . G/ L account
2. Comapny code
3. posting date
4. Profit Center
5. layout
In my z report i used following syntax for passing selection screen values to standard program and getting data.
This is for T-code FAGLL03
SUBMIT FAGL_ACCOUNT_ITEMS_GL
WITH SD_SAKNR IN S_SAKNR
WITH SD_BUKRS IN S_BUKRS
WITH %%DYN001-LOW (Profit Center)
EXPORTING LIST TO MEMORY
AND RETURN.
The above syntax is not working for dynamic selection field ( Profit Center), entire Profit center data is fetching from standard program. I want to fetch profit center data based on my z report selection values .
Expect for profit center field , submit syntax is working.
kindly provide submit syntax for my above requirement .
Any suggestions from experts....
Edited by: PLP REDDY on Nov 25, 2009 8:59 AMIndeed it won't work. Instead of passing parameters one by one use
[SUIBMIT... WITH SELECTION-TABLE rspar|http://help.sap.com/abapdocu_70/en/ABAPSUBMIT_SELSCREEN_PARAMETERS.htm#!ABAP_ADDITION_3@3@]
Here you add one line per parameter (field KIND = 'P' ) and multiple lines per select options (field KIND = 'S' ). For the latter you need also provide SIGN and OPTIONS, i.e SIGN = 'I' , OPTIONS = 'EQ'
The lin I gave you will explain it more.
Regards
Marcin -
CX_SY_DYNAMIC_OSQL_SEMANTICS error with dynamic SELECT statement
Hello Gurus,
We have a dynamic SELECT statement in our BW Update Rules where the the Selection Fields are populated at run-time and so are the look-up target and also the WHERE clause. The code basically looks like below:
SELECT (lt_select_flds)
FROM (lf_tab_name)
INTO CORRESPONDING FIELDS OF TABLE <lt_data_tab>
FOR ALL ENTRIES IN <lt_source_data>
WHERE (lf_where).
In this instance, we are selecting 5 fields from Customer Master Data and the WHERE condition for this instance of the run is as below:
WHERE: DIVISION = <lt_source_data>-DIVISION AND DISTR_CHAN = <lt_source_data>-DISTR_CHAN AND SALESORG = <lt_source_data>-SALESORG AND CUST_SALES = <lt_source_data>-SOLD_TO AND OBJVERS = 'A'
This code was working fine till we were in BW 3.5 and is causing issues after we moved to BW 7.31 recently. Ever since, when we execute our data load, we get the CX_SY_DYNAMIC_OSQL_SEMANTICS. THE ERROR TEXT SAYS 'Unable to interpret '<LT_SOURCE_data>-DOC_NUMBER'.
Can you pleasesuggest what can we do to this code to get is working correctly ? What has changed in ABAP Objects that has been introduced from BI 7.0 that could be causing this issue?
Would appreciate any help we can get here.
Thanks
ArvindHi,
Please try this.
data: lv_where type string.
concatenate 'vbeln' 'in' 'r_vbeln' into lv_where separated by space.
select *from table into itab where (lv_where).
Also please check this sample code.
REPORT ZDYNAMIC_WHERE .
TABLES: VBAK.
DATA: CONDITION TYPE STRING.
DATA: BEGIN OF ITAB OCCURS 0,
VBELN LIKE VBAK-VBELN,
POSNR LIKE VBAP-POSNR,
END OF ITAB.
SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN.
CONCATENATE 'VBELN' 'IN' 'S_VBELN.'
INTO CONDITION SEPARATED BY SPACE.
SELECT VBELN POSNR FROM VBAP INTO TABLE ITAB
WHERE (CONDITION).
LOOP AT ITAB.
WRITE 'hello'.
ENDLOOP.
Regards,
Ferry Lianto -
How to create a cursor on a union select statement?
Hi,
Using Oracle 10g RAC +ASM ( RELEASE 1002000300)
What are is the proper way to create a cursor on a union select statement?
Is it possible?
code lines, Results in PLS-00201 error: sT := crsR.STATUS; sS := crsR.TIME;
Procedure listed below:
CREATE OR REPLACE PROCEDURE BUILD_SUMMARY IS
CURSOR csrO IS
SELECT
STATUS,
TIME
FROM (
SELECT
SUBSTR(DESCRIPTION,1,50) STATUS,
TO_CHAR(TIMESTAMP,'MM/DD/YY hh12:mi:ss') TIME
FROM GLOBALSALES.CUBE_STATUS
UNION ALL
SELECT
' TOTAL BUILD TIME',
TO_CHAR(TO_DATE('00:00:00','HH24:MI:SS') +(MAX(TIMESTAMP) - MIN(TIMESTAMP)), 'HH24:MI:SS')
FROM GLOBALSALES.CUBE_STATUS);
csrR csrO%ROWTYPE;
sT LONG :='';
sS LONG :='';
BEGIN
FOR csrR IN csrO
LOOP
sT := crsR.STATUS;
sS := crsR.TIME;
DBMS_OUTPUT.PUT_LINE(sT || ' ' || sS);
END LOOP;
END;
/csrR csrO%ROWTYPE;
Declares the csrR correct? Cursor Record of Cursor Object Type?That line declares one variable CSRR with your column structure described by the cursor (CSRO) type you declared above it. It means the CSRR variable has the columns you had in the SELECT statement in that cursor.
When you run a cursor as you did you don't need to declare the record variable. Try this:
CREATE OR REPLACE PROCEDURE build_summary IS
CURSOR csro IS
SELECT status, TIME
FROM (SELECT substr(description, 1, 50) status, to_char(TIMESTAMP, 'MM/DD/YY hh12:mi:ss') TIME
FROM globalsales.cube_status
UNION ALL
SELECT ' TOTAL BUILD TIME',
to_char(to_date('00:00:00', 'HH24:MI:SS') + (MAX(TIMESTAMP) - MIN(TIMESTAMP)),
'HH24:MI:SS')
FROM globalsales.cube_status);
--csrr csro%ROWTYPE;
st LONG := '';
ss LONG := '';
BEGIN
FOR csrr IN csro
LOOP
st := csrr.status;
ss := csrr.time;
dbms_output.put_line(st || ' ' || ss);
END LOOP;
END;Also why are you using LONG? It's a deprecated data type and Oracle recommends against using it. Either pick varchar2(4000) or CLOB.
DBMS_OUTPUT.PUT_LINE will implicitly convert that LONG data type anyway. -
How to add Document group in t code S_ALR_87012082 for dynamic selection.
Hi Gurus,
I Need to add Document group in t code S_ALR_87012082 for dynamic selection.
Currently here two groups are showing , Vender and Comp Code. i need to add Document group there. Kindly guide me in this.
Thanks in advance.Hi
Pls follow below report
*S_ALR_87012103 - List of Vendor Line Items *
In dynamic selections you can find Document number, there you can give the range
Reg
Vishnu -
DYnamic select statement in JDBC adapter?
Hi guys,
Is it possible so send dynamic select statement in jdbc adapter?
XIerAamir,
The poster did not specify whether this was sender or receiver channel, but it would only make sense that a "dynamic query" must be on the receiver communication channel since if it was on the sender channel, the channel would have to intelligently determine how to do dynamic queries.
Also, the poster asked if there was a way to "send a dynamic query" to the channel. This seems to imply that the channel is receiving information from somewhere to determine the query, which could only mean it is a receiver channel.
If you would like more information on the JDBC sender communication channel, please open a new thread. -
Selection variable for dynamic selection in QE51n
Hi All,
I have a scenario were we have a repetitive Manufacturing and we create one insp. lot of origin 13 and keep creating insp. points for days, so my user wants the insp. points to be displayed only for the past 3 days based of the Date Insp. point identifier which is one of dynamic selection criteria under insp. points, I see with other transaction I can do selection variable on dates for dynamic selection fields but I cannot do that in QE51n, I can do the same in QE51 but not in QE51n, can some tell me if there is a OSS or other way to get this working.
I appreciate your help.
Thanks,Hi Srikant,
I think you can meet the requirement in QE51N also.
In the screen for QE51N :Result Recording Work list", Follow this Path,,,,,,,,,
Edit--->Dynamic Selection.
The system will pop-up new small window for "Dynamic selection for insp. lot and operation" here I there is one folder is available named "Inspection point " which is having the selection criteria "Inspection point", double click on it and enter the desired values.
Regards,
Shyamal -
Autonumbers through dynamic SELECT statement
Trying to get an autonumber from an order table. The order_id I need from the table is only uniquely identified by the customer_id and the date/time. I've been advised that you cannot get an autonumber back from access without going via a select statement.
I've tried to do a dynamic select statement by getting the date (short i.e.DD/MM/YY) from the server using a JSP custom tag and then putting this value into a hidden form field on the previous web page.
However, when I load the next page the data gets input into the order table okay but the web page displayed is blank i.e. it doesn't display the order_id or the form to input credit card details. There are no error messages
Code below, any ideas?
<%@ page language="java" contentType="text/html"
import="ShoppingBasket,Product,java.util.*"
errorPage="errorpage.jsp"%>
<jsp:useBean id="basket" class="ShoppingBasket" scope="session"/>
<html>
<head>
<title>Your Order Has Been Received</title>
</head>
<body>
<%
String customer_id = request.getParameter("customer_id");
String total_value = request.getParameter("total_value");
String order_date = request.getParameter("order_date");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:Novbase","","");
java.sql.Statement Stmt = connection.createStatement();
String query = ("INSERT INTO Orders (customer_id, total_value) VALUES ("+customer_id+", "+total_value+")");
Stmt.executeUpdate(query);
java.sql.Statement Stmt2 = connection.createStatement();
java.sql.ResultSet RS = Stmt2.executeQuery("SELECT order_id FROM Orders WHERE customer_id = "+customer_id+" AND time_date LIKE '"+order_date+"%'" );
while(RS.next())
String order_id = RS.getString("order_id");
%>
your order id is <%=order_id %>. Please input your credit card details in the form below:
<form name="form1" method="post" action="shop-postorder4.jsp">
<table width="90%" border="0" cellspacing="1" cellpadding="5">
<tr>
<td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Credit
Card Type</font></td>
<td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<select name="card_type">
<option value="AMERICAN EXPRESS">American Express</option>
<option value="MASTER CARD">Master Card</option>
<option value="SWITCH">Switch</option>
<option value="VISA">Visa</option>
</select>
*</font></td>
</tr>
<tr>
<td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Credit
Card No.</font></td>
<td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<input type="text" name="card_number" size=18 maxlength="18">
*</font></td>
</tr>
<tr>
<td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Issue
No. <font size="1"><br>
(Switch card holders<br>
only)</font></font></td>
<td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<input type="text" name="issue_no" size="2" maxlength="2">
</font></td>
</tr>
<tr>
<td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Valid
From</font></td>
<td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<input type="text" name="valid_from" size="4" maxlength="4">
e.g. 0502</font></td>
</tr>
<tr>
<td width="5%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"></font></td>
<td width="25%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Validy
To</font></td>
<td width="70%"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<input type="text" name="valid_to" size="4" maxlength="4">
* e.g. 0105</font></td>
</tr>
</table>
<input type="submit" name="Submit" value="Submit">
<input type="hidden" name="order_id" value="<%=order_id %>">
</form>
<a href=" <%= response.encodeURL(shop-products.jsp") %">">
<img src="images\toshop.gif" border="0" alt="Return to the Shop"></a>
<%
RS.close();
Stmt.close();
Stmt2.close();
connection.close();
%>
</body>
</html>
</a>String query = ("INSERT INTO Orders (customer_id, total_value) VALUES ("+customer_id+", "+total_value+")");
the data gets input into the order table okay
java.sql.ResultSet RS = Stmt2.executeQuery("SELECT order_id FROM Orders WHERE customer_id = "+customer_id+" AND time_date LIKE '"+order_date+"%'" );It is a field name as <B>time_date </B>in Orders table? And should you insert some value ?
It seems your select return nothing.
When your RS.next() is false, so you get blank. Add some HTNL code or just <HR> after while {} block so your would see it. -
Cursor - dynamic select statement?
Hello!
I am passing a string into a function, and my string is a sql select statement. Is it possible to create a cursor using the string that is passed to the function?
Ex:
create or replace function "GETCOUNT"
(sqlstring in VARCHAR2)
return NUMBER
is
rec_count NUMBER; --I eventually want to return a count of the rows returned from my sqlstring
cursor c1 is sqlstring <--this is what I'd like to do...but how?
begin
... -- I haven't gotten to this point yet
end;
The error I get says 'Encountered the symbol "sqlstring" when expecting on of the following: ( select '
Thanks in advance!!Something like this ->
create or replace procedure gen_cur(str in varchar2,rc in out sys_refcursor)
is
str1 varchar2(500);
begin
str1 := 'select empno,ename,hiredate,sal
from emp
where '||str;
open rc for str1;
exception
when others then
dbms_output.put_line(sqlerrm);
end;
variable b refcursor
declare
src varchar2(300);
begin
src:= 'sal between 2000 and 7000';
gen_cur(src,:b);
exception
when others then
dbms_output.put_line(sqlerrm);
end;
print bRegards.
Satyaki De.
Maybe you are looking for
-
Hi, I am looking for a good audio player with the option to play MP3 and Flac files. I have tried FLAC player but its capability for organizing and editing files according to composers and musical works is very limited. Any help will be appreciated.
-
Cant log in to Macbook after Time Capsule Full Restore
Hi, I upgraded to Yosemite the other day and after doing so, I realized it locked me out of aperture, vmware fusion, and a few other programs which evidentially needed to be upgraded. I had a recent backup(pre-Yosemite) on my Time Capsule so I just c
-
What is NetAuthAgent.app
Should I allow firewall connection with NetAuthAgent.app? What is its function? Thank you
-
Validation for non-ASCII characters
Hi all, Requirement: I have to apply a validation on on fields like Name and Address in applicationdefination.xml. When a user types non-ASCII characters and navigates to next page then it should display the error message. Thus, I have to restrict my
-
USEREXIT FOR vf01 TRANSACTION IN INTER COMpany billing
Hi guys , Could you please suggest a closest userexit for Intercompany billing where the requirement is It should take iv billing type automatically before pgi is done.one sap note is applied which is allowing billing to take place with out pgi ,but