Dynamic PL/SQL block vs dynamic SQL SELECT
Hi there,
I have a question regarding the optimal way to code a dynamic SELECT INTO statement. Below are the 2 posiibilities I know of:
_1. Dynamically executing the SELECT statement and making use of the INTO clause of the EXECUTE IMMEDIATE statement_
CREATE OR REPLACE FUNCTION get_num_of_employees (p_loc VARCHAR2, p_job VARCHAR2)
RETURN NUMBER
IS
v_query_str VARCHAR2(1000);
v_num_of_employees NUMBER;
BEGIN
v_query_str := 'SELECT COUNT(*) FROM emp_'
|| p_loc
|| ' WHERE job = :bind_job';
EXECUTE IMMEDIATE v_query_str
INTO v_num_of_employees
USING p_job;
RETURN v_num_of_employees;
END;
_2. Encapsulating the SELECT INTO statement in a block and dynamically exectuting the block_
CREATE OR REPLACE FUNCTION get_num_of_employees (p_loc VARCHAR2, p_job VARCHAR2)
RETURN NUMBER
IS
v_query_str VARCHAR2(1000);
v_num_of_employees NUMBER;
BEGIN
v_query_str := 'begin
SELECT COUNT(*) INTO :into_bind FROM emp_'
|| p_loc
|| ' WHERE job = :bind_job;
end;';
EXECUTE IMMEDIATE v_query_str
USING out v_num_of_employees, p_job;
RETURN v_num_of_employees;
END;
I was just wondering which way would be preferred? I know the second method uses a bind variable for the INTO clause, but does the first one also use bind varialbes (no semi-colon)? Any differences in terms of efficiency or speed?
Thanks alot
Edited by: BYS2 on Oct 19, 2011 1:23 AM
sybrand_b wrote:
No difference in terms of performance or speed
Both variants will wreck the primary purpose of PL/SQL: to avoid parsing.
When I would see a 'developer' do this, I would fire him on the spot.
Why abuse PL/SQL in such a fashion? Both statements don't require parsing, as there is nothing dynamic in them and indicate a complete lack of understanding of Oracle, or a desire to deliver completely unscalable applications, resulting in end-users desiring to lynch you, and rightly so.
Remove the dynamic SQL or find another job.
Sybrand Bakker
Senior Oracle DBANot dynamic? What if p_loc and p_job were generated dynamically based on user-input? or what if there were potentially thousands of tables that p_loc could refer to? Should I make a CASE statement with a thousand cases?
In addition, the first example was actually taken directly from the official Oracle Database Application Developer's Guide (version 10.2). http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_dynamic_sql.htm#i1006429 - look under 'Sample Single-Row Query Using Native Dynamic SQL' heading. Therefore, if you have any issues with this alleged 'improper' usage of dynamic SQL, perhaps you should go talk to Oracle directly.
While I appreciate your response, I don't think it has occurred that you that not everyone is a 'developer'. In fact, I have only very recently (several days ago) taught myself how to use Oracle SQL, PL/SQL and XMLDB by reading several of the official Oracle language and developer's guides. It is more a passing interest to me as I am working on some medical research which may require the use of a database. I am actually in medical school at the moment but have an undergraduate degree in Electrical and Computer engineering so I am generally well-versed in programming.
Perhaps the next time, you post your rubbish, rude and unhelpful comments, you should stop and think that people come to this forum because they need help and not because they want to be told to 'find another job'. In fact, I am quite certain that I could make you look absolutely stupid in any topic of electrical engineering or medicine.
Please do us all a favour and stop polluting this forum with your vapid posts. While I understand that your behavior is likely a compensatory mechanism to cope with your inferiority complex, know that help IS available if you need it.
Edited by: BYS2 on Oct 19, 2011 2:13 AM
Similar Messages
-
Dynamic parameter selection from infoview not storing the sql password
We are having the problem of dynamic parameter selection from infoview not storing the sql password as it does for the actual report. We are using Crystal Reports XI Release 2 version 11.5.3.438 (Not sure of SP level, asked in separate thread).
To be more specific.
We have created a report that dynamically populates the parameters of the report by pulling the records from the Informix sql database and allowing selection from there.
In the Central Management Console for the report object we have set as follows:
Process - Database:
Use original database logon information from the report - the sql username and pw etc
Use same database logon as when report is run
Process - Parameters
In selecting a default selection there is the option to put in the sql password, however, this does not stick and clears after update.
As such the end result is that every time this report is run from infoview and a user chooses a parameter (there are 5), crystal goes through some timeout for about a minute or so and then requests the sql password, if a user then selects the next parameter, the same timeout and password dialog appears.
We need the crystal report to handle to the sql password for fetching the parameters as well as for the database section of running the report, however, the parameters insists on the end user always putting the password in.
This is 100% replicatable on our system.
Any way that we can fix this?
Will an update fix this issue? If so could you please advise which one?
ThanksHi,
I am having the exact same problem. Any help?
And what does "Use same database logon as when report is run" mean? For me that would be that no prompt is needed for getting values in a dynamic parameter...
Regards
Magnus -
Until runtime I don't know the table name and column-name on which I have to do a select.
Here is my SQL:
SELECT single <b>w_sum_col_name </b> FROM (w_tbl_name)
INTO ZOH_AUDIT-ZOH_NET1
WHERE REQUID = ZOH_AUDIT-REQUID.
My SQL fails when I have SUM(any_column) in the string w_sum_col_name. However it works if its a just a column name of the table. Failure is when the w_sum_col_name string has an aggregate function.
Error is ..SAPSQL_ILLEGAL_AGGREGATE" CX_SY_DYNAMIC_OSQL_SYNTAX
Any alternatives for my requirement is appreciated.Try this code.
REPORT zreport NO STANDARD PAGE HEADING MESSAGE-ID zfi
LINE-COUNT 65
LINE-SIZE 120.
PARAMETERS: p_matnr LIKE mara-matnr.
DATA: mytable LIKE dd02l-tabname,
fields(50) TYPE c OCCURS 0 WITH HEADER LINE,
labst LIKE mard-labst.
TABLES: mard.
DEFINE select_statement.
select (&1) into &2
from (&3)
where matnr = p_matnr.
endselect.
END-OF-DEFINITION.
fields = 'SUM( LABST )'.
APPEND fields.
mytable = 'MARD'.
select_statement fields[] labst 'MARD'.
WRITE:/ labst. -
Blocking Session - blocked SQL - SELECT SYSDATE FROM SYS.DUAL
Oracle 10.0.0.4g
When database execute some big and long queries/operations my system is slow and some users wait, can’t work (they work with some Oracle forms applications ) because I often have blocking session.
I found up that this blocking sessions block only this query of another user:
SELECT SYSDATE FROM SYS.DUAL
Or:
+10-АВГ-2009 08:51:10 User X1 ( SID= 222 ) with the statement: SELECT ... is blocking the SQL statement on Y1 ( SID=333 ) blocked SQL -> SELECT SYSDATE FROM SYS.DUAL+
When I kill one of the blocking session another session take his place and do the same:
+10-АВГ-2009 08:53:10 User X2 ( SID= 444 ) with the statement: SELECT ... is blocking the SQL statement on Y2 ( SID=555 ) blocked SQL -> SELECT SYSDATE FROM SYS.DUAL+
When long queries finished everything is OK.
Please Help Me!!!I create ASH report:_
Top User Events
Avg Active
Event Event Class % Activity Sessions
enq: TM - contention Application 55.87 0.96
db file sequential read User I/O 18.87 0.32
CPU + Wait for CPU CPU 16.33 0.28
db file scattered read User I/O 3.02 0.05
Top Event P1/P2/P3 Values
Event % Event P1 Value, P2 Value, P3 Value % Activity
Parameter 1 Parameter 2 Parameter 3
enq: TM - contention 55.87 "xxxxxxxxxxxxxxxxxxxx" 38.35
name|mode object # table/partition
"1111111111","xxxxxxx","0" 17.44
db file sequential read 19.21 "xxxxxxxxxxxxxxx’’ 0.00
file# block# blocks
db file scattered read 3.03 "xxxxxxxxxxxxxxxxxxxxxx’’ 0.01
file# block# blocks
Top SQL Statements …………..
SQL ID Planhash % Activity Event % Event
fnxxxxxxxxx N/A 25.09 enq: TM - contention 23.47
** SQL Text Not Available **
N/A 25.09 db file sequential read 1.19
** SQL Text Not Available **
byxxxxxxxxxxxxx 1111111 10.11 enq: TM - contention 7.43
SELECT SYSDATE FROM SYS.DUAL
db file sequential read 2.10
fnxxxxxxxxx 11111111111 2.57 enq: TM - contention 2.16
** SQL Text Not Available **
Top DB Objects
Object ID % Activity Event % Event
Object Name (Type) Tablespace
11111 10.33 enq: TM - contention 10.30
XXXXXXXXXXXXXXXXXXXXXXXX (INDEX) CC
99999 10.18 enq: TM - contention 10.16
XXXXXXXXXXXXXXXXXXXXXXXXX (INDEX) IND
933333 6.67 enq: TM - contention 6.55
FFFFFFFFFFFFFFFF (TABLE) T3
114545 3.88 enq: TM - contention 3.85
RRRRRRRRRRRRRRRRRRRRRR (INDEX) JJJ
1136664 2.96 enq: TM - contention 2.93
FFFFFFFFFFFFFFFFFFFFFFFFF (INDEX) G
How to found sql text that is not available ** SQL Text Not Available **?
What to do whit this Top DB Objects that have enq: TM - contention event?
And how to solve this problem? -
How many columns a sql selects
I need to find out how many columns are in a sql statement like below:
sql = "select id, decode(description,'','No decription', description), comment from my_table";
The sql string is build dynamically so I don't know it when I write the code. I need to know before I do
call rs.next(), because I need to set up the table header so I need to know how many columns the sql is selecting.
Thanks inadvance.
BotaoYou can use the interface ResultSetMetaData,below are some methods of it.
int getColumnCount()
Returns the number of columns in this ResultSet object.
String getColumnName(int column)
Get the designated column's name.
int getColumnType(int column)
Retrieves the designated column's SQL type.
for more infomation ,you can refer to JDBC Online Document. -
Javascript and sql select statement
I am working in html db in the 10 g environment. I'm trying to create an "auto suggestion function" that predicts values as the user enters characters into a text field. I've gotten it to work by hard coding the values in the function, ie: states. btw: there are several external javascript files at work here.
What I want is to create a dynamic link to the database to gather, say, all names of providers at the time the page is built to use in the auto suggest format. I want to put this into a javascript routine and I'm having problems finding out how to mix the sql select statement into the javascript function.
For the states example, I'm using:
function StateSuggestions() {
this.states = [
"Alabama", "Alaska", "Arizona", "Arkansas",
"California", "Colorado", "Connecticut",..."Wyoming" ];
Can I substitute the hard coded data (states) with a sql select statement such
as:
select name from <dbtable> ???
How does this need to be "wrapped" or containerized?
Thank you. You have a great product in html db and your site is very useful. I appreciate everything you have done to assist us. Again, thank you.Hi,
You can use TRUNC with 2 arguments to get the first DATE in a month, year, quarter, week, hour, minute, ISO year, ...
SELECT TRUNC ( ADD_MONTHS ( SYSDATE
, 12
, 'MONTH'
) AS first_of_month
FROM dual
;The DATE returned will be in the same month, year, quearter, ... as the first argument.
\We convered the last day of the month in [your previous question|http://forums.oracle.com/forums/message.jspa?messageID=3942939#3942939].
At that time, I warded about using LAST_DAY as a cutoff point; TRUNC is a much better way.
For example, to find all appointment_dates in the current month next year:
SELECT *
FROM appointments
WHERE appointment_date >= TRUNC (ADD_MONTHS (SYSDATE, 12), 'MONTH')
AND appointment_date < TRUNC (ADD_MONTHS (SYSDATE, 13), 'MONTH')Note that
the first part of the WHERE clause calls for dates on or equal to the beginning of the 12th month in the future, but
the second part of the WHERE clause calls for dates before, not equal to , the beginning of the 13th month in the future. -
Oracle SQL Select query takes long time than expected.
Hi,
I am facing a problem in SQL select query statement. There is a long time taken in select query from the Database.
The query is as follows.
select /*+rule */ f1.id,f1.fdn,p1.attr_name,p1.attr_value from fdnmappingtable f1,parametertable p1 where p1.id = f1.id and ((f1.object_type ='ne_sub_type.780' )) and ( (f1.id in(select id from fdnmappingtable where fdn like '0=#1#/14=#S0058-3#/17=#S0058-3#/18=#1#/780=#5#%')))order by f1.id asc
This query is taking more than 4 seconds to get the results in a system where the DB is running for more than 1 month.
The same query is taking very few milliseconds (50-100ms) in a system where the DB is freshly installed and the data in the tables are same in both the systems.
Kindly advice what is going wrong??
Regards,
PurushothamSQL> @/alcatel/omc1/data/query.sql
2 ;
9 rows selected.
Execution Plan
Plan hash value: 3745571015
| Id | Operation | Name |
| 0 | SELECT STATEMENT | |
| 1 | SORT ORDER BY | |
| 2 | NESTED LOOPS | |
| 3 | NESTED LOOPS | |
| 4 | TABLE ACCESS FULL | PARAMETERTABLE |
|* 5 | TABLE ACCESS BY INDEX ROWID| FDNMAPPINGTABLE |
|* 6 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
|* 7 | TABLE ACCESS BY INDEX ROWID | FDNMAPPINGTABLE |
|* 8 | INDEX UNIQUE SCAN | PRIMARY_KY_FDNMAPPINGTABLE |
Predicate Information (identified by operation id):
5 - filter("F1"."OBJECT_TYPE"='ne_sub_type.780')
6 - access("P1"."ID"="F1"."ID")
7 - filter("FDN" LIKE '0=#1#/14=#S0058-3#/17=#S0058-3#/18=#1#/780=#5#
8 - access("F1"."ID"="ID")
Note
- rule based optimizer used (consider using cbo)
Statistics
0 recursive calls
0 db block gets
0 consistent gets
0 physical reads
0 redo size
0 bytes sent via SQL*Net to client
0 bytes received via SQL*Net from client
0 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
9 rows processed
SQL> -
Hi All,
Please help me to resolve this Issue.
Internal table - IT which has table name like
KOTH600
KOTH601
KOTH602
KOTH603 , All these table has field KNUMH.
Loop at IT into WA. ( which has table name in it )
select * from (WA-TABNAME) into (New_WA)
where KNUMH = '100010'.
write:/ New_WA - NAME.
Endloop.
Here issue is table name is dynamic and depending upon this New_WA will change. How can I give both table name and work-area dynamic. ( I do not wish to define 4 new work-area, one for each to handle this situation as number of tables will increase going further ).
Thanks in advance,
Regards,
Mayank Rajguru.In this example you have what you are looking for. Create dinamyc tables.
REPORT Z_DUMMY_ATG NO STANDARD PAGE HEADING MESSAGE-ID SAPLWOSA.
*=======================================================================
Variables*
*=======================================================================
DATA DESCR_STRUCT_REF TYPE REF TO CL_ABAP_STRUCTDESCR.
DATA WA_FCAT TYPE LVC_S_FCAT.
DATA IT_FIELDCATALOG TYPE LVC_T_FCAT.
DATA DATAREF TYPE REF TO DATA.
DATA: ONE LIKE PCFILE-DRIVE,
TWO LIKE PCFILE-PATH,
LONG TYPE I,
FLAG TYPE C,
FILEPATH(128) TYPE C,
FILE_TAB TYPE STRING,
TABNAME LIKE DD02L-TABNAME.
*=======================================================================
Field-Symbols.*
*=======================================================================
FIELD-SYMBOLS:
<ROW> TYPE ANY TABLE,
<TABLE> TYPE STANDARD TABLE,
<COMPONENT> TYPE ABAP_COMPDESCR,
<FS> TYPE ANY.
*=======================================================================
Selection screen*
*=======================================================================
SELECTION-SCREEN BEGIN OF BLOCK DATA WITH FRAME TITLE TEXT-T01.
PARAMETERS:
TABNAM(128) TYPE C,
FUNCTION(1) TYPE C OBLIGATORY,
LISTNAME LIKE RLGRAP-FILENAME.
SELECTION-SCREEN END OF BLOCK DATA.
*=======================================================================
At Selection screen*
*=======================================================================
AT SELECTION-SCREEN ON VALUE-REQUEST FOR LISTNAME.
PERFORM GET_FILENAME CHANGING LISTNAME.
*=======================================================================
Start-of-selection*
*=======================================================================
START-OF-SELECTION.
CLEAR FLAG.
PERFORM LOAD_DATA USING TABNAM.
PERFORM VERIFY_TABLE USING TABNAM CHANGING FLAG.
IF FLAG NE 'X'.
IF FUNCTION EQ 'D'.
PERFORM CREATE_TABLE USING TABNAM.
PERFORM DOWNLOAD_TABLE USING TABNAM.
ELSE.
PERFORM CREATE_TABLE USING TABNAM.
PERFORM UPLOAD_TABLE USING TABNAM.
ENDIF.
ELSE.
MESSAGE S000 WITH 'The proposed table doesn''t exist.'.
ENDIF.
FORM GET_FILENAME **
Name of the directory.*
FORM GET_FILENAME CHANGING LISTNAME.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
DEF_FILENAME = LISTNAME
DEF_PATH = 'C:\downloads\list'
MASK = ',.,.. '
MODE = 'S'
TITLE = 'Save as'
IMPORTING
FILENAME = LISTNAME
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
ENDFORM.
FORM LOAD_DATA **
Specifies the path and table name*
FORM LOAD_DATA USING MY_TAB.
DATA: W_FILE LIKE PCFILE-PATH.
W_FILE = LISTNAME.
CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
EXPORTING
COMPLETE_FILENAME = W_FILE
IMPORTING
DRIVE = ONE
PATH = TWO
EXCEPTIONS
INVALID_DRIVE = 1
INVALID_EXTENSION = 2
INVALID_NAME = 3
INVALID_PATH = 4
OTHERS = 5.
CONCATENATE ONE ':' TWO INTO FILEPATH.
CONCATENATE FILEPATH MY_TAB '.txt' INTO FILE_TAB.
ENDFORM.
FORM DOWNLOAD_TABLE **
Downloads the table data.*
FORM DOWNLOAD_TABLE USING MY_TAB.
*SELECT **
INTO TABLE <ROW>
FROM (MY_TAB).
ASSIGN <ROW> TO <TABLE>.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = FILE_TAB
FILETYPE = 'ASC'
TABLES
DATA_TAB = <TABLE>
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6.
IF SY-SUBRC EQ 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
TITEL = 'Successful Download'
TXT1 = 'All the data from the table'
TXT2 = 'was correctly downloaded.'.
ELSE.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
TITEL = 'Download Error!'
TXT1 = 'The data of the table'
TXT2 = 'couldn''t be downloaded.'.
ENDIF.
ENDFORM.
FORM UPLOAD_TABLE **
Table Upload.*
FORM UPLOAD_TABLE USING MY_TAB.
ASSIGN <ROW> TO <TABLE>.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = FILE_TAB
FILETYPE = 'ASC'
IMPORTING
FILELENGTH = LONG
TABLES
DATA_TAB = <TABLE>
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7.
MODIFY (MY_TAB) FROM TABLE <TABLE>.
IF SY-SUBRC EQ 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
TITEL = 'Successful Upload'
TXT1 = 'All the data from the table'
TXT2 = 'was correctly uploaded.'.
ELSE.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
TITEL = 'Upload Error!'
TXT1 = 'The data of the table'
TXT2 = 'couldn''t be uploaded.'.
ENDIF.
ENDFORM.
FORM CREATE_TABLE **
Creates a dynamic internal table.*
FORM CREATE_TABLE USING MY_TAB.
CREATE DATA DATAREF TYPE (MY_TAB).
ASSIGN DATAREF-> TO <FS>.*
DESCR_STRUCT_REF ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( <FS> ).
LOOP AT DESCR_STRUCT_REF->COMPONENTS ASSIGNING <COMPONENT>.
WA_FCAT-FIELDNAME = <COMPONENT>-NAME.
WA_FCAT-REF_TABLE = MY_TAB.
WA_FCAT-REF_FIELD = <COMPONENT>-NAME.
APPEND WA_FCAT TO IT_FIELDCATALOG.
ENDLOOP.
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_FIELDCATALOG
IMPORTING
EP_TABLE = DATAREF
EXCEPTIONS
GENERATE_SUBPOOL_DIR_FULL = 1
OTHERS = 2.
ASSIGN DATAREF-> TO <ROW>.*
ENDFORM.
*& Form VERIFY_TABLE
The table must exist!*
FORM VERIFY_TABLE USING TABNAM CHANGING FLAG.
SELECT SINGLE TABNAME
INTO (TABNAME)
FROM DD02L
WHERE TABNAME EQ TABNAM.
IF SY-SUBRC NE 0.
FLAG = 'X'.
ENDIF.
ENDFORM. -
Dynamically calling selection screens with obligatory
TABLES :
******selection-screen: begin of block bal with frame title txt3.
******parameters: RB1 radiobutton group rd1 user-command abc default 'X'.
******parameters: RB2 radiobutton group rd1.
******selection-screen: end of block bal.
******selection-screen: begin of block B1 with frame title txt1.
******SELECT-OPTIONS : s_cust FOR KNA1-kunnr OBLIGATORY MODIF ID r1.
******SELECT-OPTIONS : s_plant FOR plko-werks OBLIGATORY MODIF ID r1 .
******selection-screen: end of block val.
******selection-screen: begin of block upd with frame title txt2.
******SELECT-OPTIONS: s_vend FOR lfa1-lifnr OBLIGATORY modif id r2.
******SELECT-OPTIONS: s_plan FOR plko-werks OBLIGATORY modif id r2.
******selection-screen: end of block upd.
Here i need to call these two selection screens dynamically depends on radio buttion selection.
But
Problem is a arising when when both are obligatory in selection screen ( with out obligatory , it is working fine)
I need to call screens dynamically, ecen though we have obligatory
Let me know procedure , the possibility of same funcationality in tabstips & selection screen.
MadhuHi Madhu,
You have to write code in AT SELECTION-SCREEN OUTPUT event.
First of all remove obligatory from select-options declaration. Do it dynamically in AT SELECTION-SCREEN OUTPUT event.
You enable or disable the block depending upon the rediobutton selected. Then in the venet AT SELECTION-SCREEN ON field, you can check whethere user has entered data into that field or not depending upon the radiobutton selected.
TABLES : kna1,
plko,
lfa1.
SELECTION-SCREEN: BEGIN OF BLOCK bal WITH FRAME TITLE txt3.
PARAMETERS: rb1 RADIOBUTTON GROUP rd1 USER-COMMAND abc DEFAULT 'X'.
PARAMETERS: rb2 RADIOBUTTON GROUP rd1.
SELECTION-SCREEN: END OF BLOCK bal.
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE txt1.
SELECT-OPTIONS : s_cust FOR kna1-kunnr MODIF ID r1.
SELECT-OPTIONS : s_plant FOR plko-werks MODIF ID r1 .
SELECTION-SCREEN: END OF BLOCK b1.
SELECTION-SCREEN: BEGIN OF BLOCK upd WITH FRAME TITLE txt2.
SELECT-OPTIONS: s_vend FOR lfa1-lifnr MODIF ID r2.
SELECT-OPTIONS: s_plan FOR plko-werks MODIF ID r2.
SELECTION-SCREEN: END OF BLOCK upd.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF rb1 EQ 'X'.
IF ( screen-name EQ 'S_CUST-LOW'
OR screen-name EQ 'S_CUST-HIGH'
OR screen-name EQ 'S_PLANT-LOW'
OR screen-name EQ 'S_PLANT-HIGH') .
screen-active = '1' .
ENDIF.
IF ( screen-name EQ 'S_VEND-LOW'
OR screen-name EQ 'S_VEND-HIGH'
OR screen-name EQ 'S_PLAN-LOW'
OR screen-name EQ 'S_PLAN-HIGH') .
screen-active = '0' .
ENDIF.
ELSEIF rb2 EQ 'X'.
IF ( screen-name EQ 'S_VEND-LOW'
OR screen-name EQ 'S_VEND-HIGH'
OR screen-name EQ 'S_PLAN-LOW'
OR screen-name EQ 'S_PLAN-HIGH') .
screen-active = '1' .
ENDIF.
IF ( screen-name EQ 'S_CUST-LOW'
OR screen-name EQ 'S_CUST-HIGH'
OR screen-name EQ 'S_PLANT-LOW'
OR screen-name EQ 'S_PLANT-HIGH') .
screen-active = '0' .
ENDIF.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
Regards,
Anil Salekar -
hi friends,
i've a view called "risk_efforts" with fields user_id,user_name,wknd_dt,week_day,prod_efforts,unprod_efforts.
Name Type
ROW_ID NUMBER
USER_ID VARCHAR2(14)
USER_NAME VARCHAR2(50)
WKND_DT VARCHAR2(8)
WEEK_DAY VARCHAR2(250)
PROD_EFFORTS NUMBER
UNPROD_EFFORTS NUMBER
data is like this:
when there is some data in prod_efforts, unprod_efforts will be null
when there is some data in unprod_efforts, prod_efforts will be null
for example:
USER_ID USER_NAME WKND_DT WEEK_DAY PROD_EFFORTS UNPROD_EFFORTS
G666999 GTest 20100403 TUE null 3
G666999 GTest 20100403 TUE 14 null
now i want to combine these 2 rows into 1 row i.e o/p should be like this
USER_ID USER_NAME WKND_DT WEEK_DAY PROD_EFFORTS UNPROD_EFFORTS
G666999 GTest 20100403 TUE 14 3
i've tried all combinations but couldn't get the query. Please help me with the exact SQL select query.
thanks,
GirishWelcome to the forum.
First read this:
Urgency in online postings
Secondly, it's always helpful to provide the following:
1. Oracle version (SELECT * FROM V$VERSION)
2. Sample data in the form of CREATE / INSERT statements.
3. Expected output
4. Explanation of expected output (A.K.A. "business logic")
5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.
You have provided #3 and #4. However with no usable form of sample data forum members will often not respond as quickly as they could if you provided #2.
I'm just wagering a guess here but what about this:SELECT ROW_ID
, USER_ID
, WKND_DT
, WEEK_DAY
, MAX(PROD_EFFORTS) AS PROD_EFFORTS
, MAX(UNPROD_EFFORTS) AS UNPROD_EFFORTS
FROM RISK_EFFORTS
GROUP BY ROW_ID
, USER_ID
, WKND_DT
, WEEK_DAY -
Need help for SQL SELECT query to fetch XML records from Oracle tables having CLOB field
Hello,
I have a scenario wherein i need to fetch records from several oracle tables having CLOB fields(which is holding XML) and then merge them logically to form a hierarchy XML. All these tables are related with PK-FK relationship. This XML hierarchy is having 'OP' as top-most root node and ‘DE’ as it’s bottom-most node with One-To-Many relationship. Hence, Each OP can have multiple GM, Each GM can have multiple DM and so on.
Table structures are mentioned below:
OP:
Name Null Type
OP_NBR NOT NULL NUMBER(4) (Primary Key)
OP_DESC VARCHAR2(50)
OP_PAYLOD_XML CLOB
GM:
Name Null Type
GM_NBR NOT NULL NUMBER(4) (Primary Key)
GM_DESC VARCHAR2(40)
OP_NBR NOT NULL NUMBER(4) (Foreign Key)
GM_PAYLOD_XML CLOB
DM:
Name Null Type
DM_NBR NOT NULL NUMBER(4) (Primary Key)
DM_DESC VARCHAR2(40)
GM_NBR NOT NULL NUMBER(4) (Foreign Key)
DM_PAYLOD_XML CLOB
DE:
Name Null Type
DE_NBR NOT NULL NUMBER(4) (Primary Key)
DE_DESC NOT NULL VARCHAR2(40)
DM_NBR NOT NULL NUMBER(4) (Foreign Key)
DE_PAYLOD_XML CLOB
+++++++++++++++++++++++++++++++++++++++++++++++++++++
SELECT
j.op_nbr||'||'||j.op_desc||'||'||j.op_paylod_xml AS op_paylod_xml,
i.gm_nbr||'||'||i.gm_desc||'||'||i.gm_paylod_xml AS gm_paylod_xml,
h.dm_nbr||'||'||h.dm_desc||'||'||h.dm_paylod_xml AS dm_paylod_xml,
g.de_nbr||'||'||g.de_desc||'||'||g.de_paylod_xml AS de_paylod_xml,
FROM
DE g, DM h, GM i, OP j
WHERE
h.dm_nbr = g.dm_nbr(+) and
i.gm_nbr = h.gm_nbr(+) and
j.op_nbr = i.op_nbr(+)
+++++++++++++++++++++++++++++++++++++++++++++++++++++
I am using above SQL select statement for fetching the XML records and this gives me all related xmls for each entity in a single record(OP, GM, DM. DE). Output of this SQL query is as below:
Current O/P:
<resultSet>
<Record1>
<OP_PAYLOD_XML1>
<GM_PAYLOD_XML1>
<DM_PAYLOD_XML1>
<DE_PAYLOD_XML1>
</Record1>
<Record2>
<OP_PAYLOD_XML2>
<GM_PAYLOD_XML2>
<DM_PAYLOD_XML2>
<DE_PAYLOD_XML2>
</Record2>
<RecordN>
<OP_PAYLOD_XMLN>
<GM_PAYLOD_XMLN>
<DM_PAYLOD_XMLN>
<DE_PAYLOD_XMLN>
</RecordN>
</resultSet>
Now i want to change my SQL query so that i get following output structure:
<resultSet>
<Record>
<OP_PAYLOD_XML1>
<GM_PAYLOD_XML1>
<GM_PAYLOD_XML2> .......
<GM_PAYLOD_XMLN>
<DM_PAYLOD_XML1>
<DM_PAYLOD_XML2> .......
<DM_PAYLOD_XMLN>
<DE_PAYLOD_XML1>
<DE_PAYLOD_XML2> .......
<DE_PAYLOD_XMLN>
</Record>
<Record>
<OP_PAYLOD_XML2>
<GM_PAYLOD_XML1'>
<GM_PAYLOD_XML2'> .......
<GM_PAYLOD_XMLN'>
<DM_PAYLOD_XML1'>
<DM_PAYLOD_XML2'> .......
<DM_PAYLOD_XMLN'>
<DE_PAYLOD_XML1'>
<DE_PAYLOD_XML2'> .......
<DE_PAYLOD_XMLN'>
</Record>
<resultSet>
Appreciate your help in this regard!Hi,
A few questions :
How's your first query supposed to give you an XML output like you show ?
Is there something you're not telling us?
What's the content of, for example, <OP_PAYLOD_XML1> ?
I don't think it's a good idea to embed the node level in the tag name, it would make much sense to expose that as an attribute.
What's the db version BTW? -
How to capture all the rows returned from a sql select query in CPO
Hi,
I am executing an sql select query which returns multiple rows. I need to capture the values of each row to specific variables. How do I proceed.
Thanks,
SwatiThe select activities ("Select from Oracle," Select from SQL Server," etc.) against database already return tables. Use one of the database adapters to do your select, and it will already be in a table form. Just put your query in the select and identify the columns in your result table. The online help or the database adapter guides in the product documentation can help.
-
Reg: SQL select Query in BPEL process flow
<p>
Hi,
I am suppose to execute a SQL select query (in BPEL Process flow) as mention below in JDeveloper using Database adapter.
</p>
<p>
SELECT LENGTH, WIDTH, HEIGHT, WEIGHT,
</p>
<p>
LENGTH*WIDTH* HEIGHT AS ITEM_CUBE
</p>
<p>
FROM CUBE
</p>
<p>
WHERE ITEM= <xyz>
</p>
<p>
AND OBJECT= (SELECT CASE_NAME FROM CUBE_SUPPLIER WHERE ITEM=<xyz> AND SUPP_IND = ‘Y')
<strong>Now my question is:
1.</strong> What does this "*" refer to in the query and how can I retrieve the value of LENGTH*WIDTH* HEIGHT from the query where LENGTH,WIDTH and HEIGHT are the individual field in the table.
2.What does this " AS" refer to? If " ITEM_CUBE " is the alies for the table name "ITEM" to retrieve the value, then query shoud be evaluated as
</p>
<p>
SELECT LENGTH, WIDTH, HEIGHT, WEIGHT,
</p>
<p>
LENGTH*WIDTH* HEIGHT AS ITEM_CUBE
</p>
<p>
FROM CUBE
</p>
<p>
WHERE <strong>ITEM_CUBE.ITEM</strong>= <xyz>
</p>
<p>
AND <strong>ITEM_CUBE.OBJECT</strong>= (SELECT CASE_NAME FROM CUBE_SUPPLIER WHERE ITEM=<xyz> AND SUPP_IND = ‘Y')
Is my assumption correct?
Please suggest asap.
Thanks...
</p>
<p>
</p>Hi
Thank for your reply!
I have a nested select query which performs on two different table as shown below:
<p>
SELECT LENGTH, WIDTH, HEIGHT, WEIGHT,
</p>
<p>
LENGTH*WIDTH* HEIGHT AS ITEM_CUBE
</p>
<p>
FROM CUBE
</p>
<p>
WHERE ITEM= <abc>
</p>
<p>
AND OBJECT= (SELECT NAME FROM SUPPLIER WHERE ITEM=<Item> AND SUPP_IND = ‘Y')
I am using DB adapter of Oracle JDeveloper in BPEL process flow, where I can able to select only one master table in DB adapter say SUPPLIER and its attributes at a time.But as per my requirment I need to select both the table (CUBE and SUPPLIER) in a single adapter to execute my query.
It can be achievable by using two DB adapter , One to execute the nested query and another to execute the main qyery considering value of nested query as a parameter.But I want to achieve it by using a single one.
Am I correct with my concept?
Please suggest how to get it ?
</p>
Edited by: user10259700 on Oct 23, 2008 12:17 AM -
Parsing an OPEN SQL select statement
Hi all,
I want to parse an open SQL select statement to get the list of tables and the corresponding fields in the select statement.
Is there some ABAP-internal syntax from the SAP Database Interface that does this? or is the only option to do this is to manually break the statement?
Thanks.
GirishHi,
I doubt if there is something like that available to use. It think you will have to write a parser for yourself.
Regards -
I have 2 tables
Table Parent_child_table:
ID | Parent_id | Name
1 | NULL | Kitchen
2 | 1 | Freezer
3 | NULL | Garden
4 | 3 | Grass
Table Products:
ID | parent_child_table_ID | Price | Comment
1 | 2 | 111 | aaaa
2 | 4 | 12 | vv
I want to select Name from parent table where selected child ID are in PRODUCT table.....
The result would like:
|NAME|
|Kitchen
|Garden
Can someone help with this SQL SELECT ?Raivis wrote:
I have 2 tables
Table Parent_child_table:
ID | Parent_id | Name
1 | NULL | Kitchen
2 | 1 | Freezer
3 | NULL | Garden
4 | 3 | Grass
Table Products:
ID | parent_child_table_ID | Price | Comment
1 | 2 | 111 | aaaa
2 | 4 | 12 | vv
I want to select Name from parent table where selected child ID are in PRODUCT table.....
The result would like:
|NAME|
|Kitchen
|Garden
Can someone help with this SQL SELECT ?A guess
select
p.name
from Parent_child_table p
where p.parent_id is null
and exists
select
null
from Parent_child_table p1, products p2
where p1.id = p2. parent_child_table_id
and p1.parent_id = p.id
)The reason it's a guess is because you've really done nothing to outline WHY you should get the results you say you would like. The more time you spend creating a clear question, the less time you'll have to spend weeding through useless answers.
Cheers, -
Dynamic bandwidth selection for PPPoE over Ethernet/VLAN
Hello all, hope you are doing great.
I'm planning to deploy PPPoE Server (Cisco Router 7609) for a ISP. This ISP will provide Internet connection for customer over Ethernet.
I have to provide a solution to assign bandwidth to each customer by RADIUS and I find some clues that Dynamic Bandwidth Selection (DBS) should be the answer. Unfortunately, DBS only support PPPoA or PPPoE over ATM.
If you have any experience with equivalent function, please help me. Thank you very much.
Regards,
Hiep Nguyen.Hiep,
I think I have figured this out. Here is the test config on my PPPoE server:
int lo1
ip address 172.25.25.25 255.255.255.255
ip radius source-interface Loopback1
aaa new-model
radius-server host 172.16.1.55 auth-port 1812 acct-port 1813 key cisco$$$
aaa group server radius RADIUS-ACT
server 172.16.1.55 auth-port 1812 acct-port 1813
aaa authentication login default group RADIUS-ACT local
aaa authorization exec default group RADIUS-ACT local
aaa accounting exec default start-stop group RADIUS-ACT
aaa accounting delay-start
aaa authentication ppp default if-needed group RADIUS-ACT local
aaa authorization network default group RADIUS-ACT local
aaa accounting network default start-stop group RADIUS-ACT
aaa accounting update periodic 5
bba-group pppoe global
virtual-template 1
interface fa0/1
pppoe enable group global
ip address 172.30.0.1 255.255.0.0
no shut
interface Virtual-Template1
mtu 1492
ip unnumbered FastEthernet0/1
peer default ip address pool GLOBALPOOL
ppp authentication chap
ip local pool GLOBALPOOL 172.30.0.2 172.30.127.255
policy-map POLICE-128K
class class-default
police 128000
policy-map POLICE-512K
class class-default
police 512000
Here are the attributes on the radius server, for a group the PPPoE customer belonged to:
Service-Type = Framed
Framed-Protocol = PPP
cisco-avpair="ip:sub-policy-In=POLICE-128K"
cisco-avpair+="ip:sub-policy-Out=POLICE-512K"
Here is the show policy-map on the virtual-access interface the client connected on:
sho policy-map int virtual-a 3
Virtual-Access3
Service-policy input: POLICE-128K
Class-map: class-default (match-any)
1000 packets, 1402000 bytes
5 minute offered rate 0 bps, drop rate 0 bps
Match: any
police:
cir 128000 bps, bc 4000 bytes
conformed 799 packets, 1120198 bytes; actions:
transmit
exceeded 201 packets, 281802 bytes; actions:
drop
conformed 0 bps, exceed 0 bps
Service-policy output: POLICE-512K
Class-map: class-default (match-any)
911 packets, 1137746 bytes
5 minute offered rate 0 bps, drop rate 0 bps
Match: any
police:
cir 512000 bps, bc 16000 bytes
conformed 799 packets, 1136178 bytes; actions:
transmit
exceeded 0 packets, 0 bytes; actions:
drop
conformed 0 bps, exceed 0 bps
I was able to generate enough traffic with ping to meet the exceed action in and have it drop packets.
Maybe you are looking for
-
Using Firefox, I used to be able to open a document on a website, such as a bank statement, and view it without downloading. Now, I must download and save a document before I can view it. How can I change settings so that I can open documents witho
-
HP 8500 all In One premier printer 909
I have a Hp officejet all in one premier 909 wireless printer. I try touse my Ipad but it can;t find the printer. The manu to connectal states that the printer is applicable. Help please
-
Data disappearing after updating software
ever since i updated my nokia n8 to belle its been eating on my data. now i hev to disconnect mobile data when i am browsing. any advice guys???
-
Savin' and recalling multiple channel Strips ?
is there a way to save and recall multiple channel strips ? what i'm trying to do is for example : to set up Ultrabeat Multi which would include several Aux's and busses with indivitual bus effect etc and recall it in a New song exactly as i saved it
-
HT4926 Move Final Cut Pro X project in CURRENT version
Simply put, from existing documentation "If the Project Library is not already open, click the Project Library button at the bottom-left corner of the Final Cut Pro main window." There is no Project library or the referenced icon. Thx.