Put prepended "WITH" into Select statement possible?
Assume I have a SQL statement like:
with t1 as (select ......),
t2 as (select ......)
Select .... From t1, t2 Where ....;
Can I merge somehow the prepended "with" term into the actual select statement?
As far as I remember there is an equivalent statement syntax like:
Select .... from t1 as (select ....), t2 as (select ....) where ....;
but this does not work.
Peter
It will be like
Select ....
From ( select .. From ...) t1
,( select .. From ...) t2
WHERE ...
Regards
Arun
Similar Messages
-
Smart scan not working with Insert Select statements
We have observed that smart scan is not working with insert select statements but works when select statements are execute alone.
Can you please help us to explain this behavior?There is a specific exadata forum - you would do better to post the question there: Exadata
I can't give you a definitive answer, but it's possible that this is simply a known limitation similar to the way that "Create table as select" won't run the select statement the same way as the basic select if it involves a distributed query.
Regards
Jonathan Lewis -
How to put OR clause in SELECT statement
Hi
How to put OR clause in SELECT statement to return number_first/number_last to match records from another table's column.
<pre>
SELECT
a.id ,
flat_number ||' '|| a.number_first||' '||a.street_name||' '||a.suburb address1,
apt_no ||' '|| street_no||' '||b.street_name||' '||b.suburb address2
from
a ,
b
where b.street_name = a.street_name
AND b.SUBURB = a.SUBURB
AND b.STATE = a.STATE
</pre>
Thsi will return this as exact match.
ADDRESS 1
12 TAMAN TENANG A ORCHARD 3142
10 RAMA YISHUN 2095
ADDRESS2
12 TAMAN TENANG A ORCHARD 3142
10 RAMA YISHUN 2095
However this only matches number_first.
How can I get the query work that it will match both number_first and number_last (table b)in address 1 to match street_no in address2 ( table b).My oracle version is 10GR/2.Hi, I have a hard time understanding your request, and below is what I thought you want:
SELECT
a.id ,
flat_number ||' '|| (decode(b.street_no, a.number_first, a.number_first, a.number_last, a.number_last)||' '||a.street_name||' '||a.suburb address1,
apt_no ||' '|| street_no||' '||b.street_name||' '||b.suburb address2
from
a ,
b
where b.street_name = a.street_name
AND b.SUBURB = a.SUBURB
AND b.STATE = a.STATE
AND (B.street_no=a.number_first OR b.street_no=a.number_last);Not tested.
Also, since your B.street_no will be either a.number_first OR a.number_last, you could replace
(decode(b.street_no, a.number_first, a.number_first, a.number_last, a.number_last) with just b.street_no.
Edited by: PhoenixBai on Aug 26, 2010 11:33 AM -
Update with a select statement
hi experts,
I need some help again.. :)
I have an insert query here with a select statement.. Juz wondering how to do it in update?
insert into newsmail_recipient
(IP_RECIPIENTID,NF_LISTID,NF_STATUSID,D_CREATED,D_MODIFIED,C_NAME,C_EMAIL,USER_ID,NEWSMAIL_ID)
select newsmail_recipientid_seq.nextval
, liste
, 1
, sysdate
, sysdate
, null
, null
, ru.nf_userid
, null
from roleuser ru, unit u, userinfo ui
where u.ip_unitid = ru.nf_unitid
and u.ip_unitid = unit_id
and ui.ip_userid = ru.nf_userid
and ui.nf_statusid = 1
and n_internal = 0
and ui.ip_userid not in (select user_id
from newsmail_recipient
where user_id = ui.ip_userid
and nf_listid = liste
and nf_statusid = 1);let me know your thoughts.
Regards,
jpHi,
924864 wrote:
... I have an insert query here with a select statement.. Juz wondering how to do it in update?How to do what, exactly?
MERGE can UPDATE existing rows, and INSERT new rows at the same time. In a MERGE statement, you give a table or a sub-query in the USING clause, and define how rows from that result set match rows in your destination table. If rows match, then you can UPDATE the matching row with values from the sub-query.
Very often, MERGE is easier to use, and perhaps more efficient, than UPDATE just for changing existing rows. That is, while MERGE can do both INSERT and UPDATE, it doesn't have to . You can tell MERGE just to do one or the other if you wish.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
Since you're asking about a DML statement, such as UPDATE, the sample data will be the contents of the table(s) before the DML, and the results will be state of the changed table(s) when everything is finished.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
Quick help with a select statement...
Hello all,
I will try to lay this out as simply as possible. I have the following table in my code:
TYPES: BEGIN OF ty_table,
vbeln TYPE likp-vbeln,
lfdat TYPE likp-lfdat,
lfart TYPE likp-lfart,
wadat_ist TYPE likp-wadat_ist,
vstel TYPE likp-vstel,
route TYPE likp-route,
vsbed TYPE likp-vsbed,
inco1 TYPE likp-inco1,
inco2 TYPE likp-inco2,
kunnr TYPE likp-kunnr,
kunag TYPE likp-kunag,
brgew TYPE lips-brgew,
matnr TYPE lips-matnr,
arktx TYPE lips-arktx,
meins TYPE lips-meins,
lgmng TYPE lips-lgmng,
vgbel TYPE lips-vgbel,
name2 TYPE adrc-name2,
street TYPE adrc-street,
city1 TYPE adrc-city1,
region TYPE adrc-region,
post_code1 TYPE adrc-post_code1,
lifnr TYPE lfa1-lifnr,
name1 TYPE adrc-name1,
so_vbeln TYPE vbak-vbeln,
erdat TYPE vbak-erdat,
END OF ty_table.
DATA: it_table TYPE TABLE OF ty_table.
I then run through a select statement as follows:
* Get data from LIKP and LIPS.
SELECT a~vbeln a~lfdat a~lfart a~wadat_ist a~vstel a~route a~vsbed b~brgew a~inco1 a~inco2 a~kunnr a~kunag
b~matnr b~meins b~lgmng b~vgbel b~arktx INTO CORRESPONDING FIELDS OF TABLE it_table
FROM likp AS a
INNER JOIN lips AS b ON b~vbeln = a~vbeln
WHERE a~vstel IN so_vstel
AND a~wadat_ist IN so_wadat
AND b~mtart IN so_mtart.
That works fine. The next statement, in the report, is the following select. When this next select runs it clears all of the fields except for vbeln and erdat. I want c~vbeln to go into it_table-so_vbeln. Now it is going into it_table-vbeln.
* Get Sales order info from VBAK
SELECT c~vbeln c~erdat INTO CORRESPONDING FIELDS OF TABLE it_table
FROM lips AS a
INNER JOIN vbap AS b ON b~vbeln = a~vgbel
AND b~posnr = a~vgpos
INNER JOIN vbak AS c ON c~vbeln = b~vbeln
FOR ALL ENTRIES IN it_table
WHERE a~vgbel = it_table-vgbel.
I then tried to write the select statement by takign out "into corresponding fields" like the following but it gives my a syntax error on (it_table-so_vbeln , it_table-erdat).
* Get Sales order info from VBAK
SELECT c~vbeln c~erdat INTO (it_table-so_vbeln , it_table-erdat)
FROM lips AS a
INNER JOIN vbap AS b ON b~vbeln = a~vgbel
AND b~posnr = a~vgpos
INNER JOIN vbak AS c ON c~vbeln = b~vbeln
FOR ALL ENTRIES IN it_table
WHERE a~vgbel = it_table-vgbel.
Is there a way to write the second select (the select that is pulling data from VBAK) so that it will not clear the other entries in the table? Also, is there a way to combine the two selects into one join?
Regards,
DavisFollowing is the entire report, if that makes it easier:
*& Report Z_TRANS_EVAL
REPORT z_trans_eval.
TABLES: likp, lips, adrc, vbpa.
TYPE-POOLS: truxs.
TYPES: BEGIN OF ty_table,
vbeln TYPE likp-vbeln,
lfdat TYPE likp-lfdat,
lfart TYPE likp-lfart,
wadat_ist TYPE likp-wadat_ist,
vstel TYPE likp-vstel,
route TYPE likp-route,
vsbed TYPE likp-vsbed,
inco1 TYPE likp-inco1,
inco2 TYPE likp-inco2,
kunnr TYPE likp-kunnr,
kunag TYPE likp-kunag,
brgew TYPE lips-brgew,
matnr TYPE lips-matnr,
arktx TYPE lips-arktx,
meins TYPE lips-meins,
lgmng TYPE lips-lgmng,
vgbel TYPE lips-vgbel,
name2 TYPE adrc-name2,
street TYPE adrc-street,
city1 TYPE adrc-city1,
region TYPE adrc-region,
post_code1 TYPE adrc-post_code1,
lifnr TYPE lfa1-lifnr,
name1 TYPE adrc-name1,
so_vbeln TYPE vbak-vbeln,
erdat TYPE vbak-erdat,
END OF ty_table.
DATA: it_table TYPE TABLE OF ty_table,
wa_table LIKE LINE OF it_table,
it_table_csv TYPE truxs_t_text_data.
DATA : lv_tabix LIKE sy-tabix.
DATA temp_string TYPE string.
DATA w_adrnr TYPE vbpa-adrnr.
DATA: w_adrnr_sp TYPE vbpa-adrnr.
* Selction criteria
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-004.
SELECT-OPTIONS: so_vstel FOR likp-vstel,
so_wadat FOR likp-wadat_ist,
so_mtart FOR lips-mtart.
SELECTION-SCREEN END OF BLOCK b2.
* CSV output filename
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (16) text-002 FOR FIELD p_file.
PARAMETERS: p_file(30) TYPE c.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b3.
START-OF-SELECTION.
* Get data from LIKP and LIPS.
SELECT a~vbeln a~lfdat a~lfart a~wadat_ist a~vstel a~route a~vsbed b~brgew a~inco1 a~inco2 a~kunnr a~kunag
b~matnr b~meins b~lgmng b~vgbel b~arktx INTO CORRESPONDING FIELDS OF TABLE it_table
FROM likp AS a
INNER JOIN lips AS b ON b~vbeln = a~vbeln
WHERE a~vstel IN so_vstel
AND a~wadat_ist IN so_wadat
AND b~mtart IN so_mtart.
* Get Sales order info from VBAK
SELECT c~vbeln c~erdat INTO CORRESPONDING FIELDS OF TABLE it_table
FROM lips AS a
INNER JOIN vbap AS b ON b~vbeln = a~vgbel
AND b~posnr = a~vgpos
INNER JOIN vbak AS c ON c~vbeln = b~vbeln
FOR ALL ENTRIES IN it_table
WHERE a~vgbel = it_table-vgbel.
* Get internal address number for ship to party
LOOP AT it_table INTO wa_table.
lv_tabix = sy-tabix. "update counter.
SELECT SINGLE adrnr FROM vbpa INTO w_adrnr WHERE
vbeln = wa_table-vgbel
AND parvw = 'WE'.
SELECT SINGLE lifnr FROM vbpa INTO wa_table-lifnr WHERE
vbeln = wa_table-vbeln
AND parvw = 'SP'
AND posnr = '000000'.
SELECT SINGLE name1 FROM lfa1 INTO wa_table-name1 WHERE
lifnr = wa_table-lifnr.
* Get address data from VBPA
SELECT city1 region post_code1 INTO CORRESPONDING FIELDS OF wa_table
FROM adrc WHERE
addrnumber = w_adrnr.
ENDSELECT.
* Update the internal table
MODIFY it_table INDEX lv_tabix FROM wa_table.
ENDLOOP.
END-OF-SELECTION.
* Call correct display procedure(s).
IF p_file <> ''.
* Save a CSV file
PERFORM display_csv.
ELSE.
*Display in ALV
PERFORM display_alv.
ENDIF.
*& Form display_alv
* text
* --> p1 text
* <-- p2 text
FORM display_alv .
DATA: gr_alv TYPE REF TO cl_salv_table,
gr_func TYPE REF TO cl_salv_functions,
gr_columns TYPE REF TO cl_salv_columns_table,
gr_column TYPE REF TO cl_salv_column_table,
gr_error TYPE REF TO cx_salv_error.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = gr_alv
CHANGING
t_table = it_table.
CATCH cx_salv_msg INTO gr_error.
ENDTRY.
gr_func = gr_alv->get_functions( ).
gr_func->set_all( abap_true ).
gr_alv->display( ).
ENDFORM. " display_alv
*& Form display_csv
* text
* --> p1 text
* <-- p2 text
FORM display_csv .
DATA: w_filename TYPE string.
CONCATENATE p_file temp_string INTO w_filename.
CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
EXPORTING
i_field_seperator = ';'
TABLES
i_tab_sap_data = it_table
CHANGING
i_tab_converted_data = it_table_csv
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = w_filename
TABLES
data_tab = it_table_csv
EXCEPTIONS
OTHERS = 1.
PERFORM display_alv.
ENDFORM. " display_csv -
Pl/sql function body returning SQL query - if with in select statement
hello all,
I have a condition where when summary field is checked alone we have show that column for the users in the report. Is IF statement possible for this case ? I have given the code below.. is it possible to write something like below or is there any other way to do it ?
v_sql := 'select TBLCASES.INVESTIGATOR as INVESTIGATOR,';
v_sql := v_sql ||' TBLCASES.CASENUMBER as CASENUMBER,';
v_sql := v_sql ||' TBLCASES.OPENDATE as OPENDATE,';
v_sql := v_sql ||' TBLCASES.ESTCOMPLETE as TARGETDATE,';
v_sql := v_sql ||' TBLCASES.STATUS as STATUS,';
v_sql := v_sql ||' TBLCASES.CASECODE as CASECODE,';
v_sql := V_sql ||' TBLCASES.FAIR_HOTLINE as FAIRHotline,';
v_sql := v_sql ||' TBLCASES.NYSIG as NYSIGCase,';
v_sql := v_sql ||' TBLCASES.REGION as Region,';
IF :P44_INCLUDE_SUMMARY_FIELD is not null THEN
v_sql := v_sql||' TBLCASES.SUMMARY as SUMMARY,';
END IF ;
v_sql := v_sql ||' TBLCASES.PROGAREA as PROGArea ';
v_sql := v_sql ||' from TBLCASES where 1=1';
..\Hi Lucy,
You are adding and removing a column from a report so it may help to have the extra on the end of the query.
Do you get an error? If so paste it in...
BUT - this I would put a condition on the column where ':P44_INCLUDE_SUMMARY_FIELD is not null '
Under he report's "Column Attributes" Select the column edit icon and it has a "Condition" breadcrumb.
Select "Value of Item in Expression 1 is Not Null" and put P44_INCLUDE_SUMMARY_FIELD in Expression 1 text area.
And I make it more readable like this when I do dynamic SQL:
IF :P44_INCLUDE_SUMMARY_FIELD is not null THEN
v_INCLUDE_SUMMARY_FIELD := ' TBLCASES.SUMMARY as SUMMARY ';
END IF ;
v_sql := 'select TBLCASES.INVESTIGATOR as INVESTIGATOR,
TBLCASES.CASENUMBER as CASENUMBER,
TBLCASES.OPENDATE as OPENDATE,
TBLCASES.ESTCOMPLETE as TARGETDATE,
TBLCASES.STATUS as STATUS,
TBLCASES.CASECODE as CASECODE,
TBLCASES.FAIR_HOTLINE as FAIRHotline,
TBLCASES.NYSIG as NYSIGCase,
TBLCASES.REGION as Region,
TBLCASES.PROGAREA as PROGArea,'||
v_INCLUDE_SUMMARY_FIELD ||
'from TBLCASES where 1=1; ';
Hope it helps,
BC -
Short dump with a select statement
I have the following select statement (I have also inluded my data statement(s)) and I get a short dump. The error is as follows:
<b>What happened?
Error in ABAP application program.
The current ABAP program "ZPARTNER" had to be terminated because one of the
statements could not be executed.
This is probably due to an error in the ABAP program.
Following a SELECT statement, the data read could not be placed in AN
the output area.
A conversion may have been intended that is not supported by the
system, or the output area may be too small.
Error analysis
An exception occurred. This exception will be dealt with in more detail
below. The exception, assigned to the class 'CX_SY_OPEN_SQL_DB', was not
caught, which
led to a runtime error. The reason for this exception is:
The data read during a SELECT access could not be inserted into the
target field.
Either conversion is not supported for the target field's type or the
target field is too short to accept the value or the data are not in a
form that the target field can accept </b>
it_adrc TYPE TABLE OF adrc,
wa_adrc LIKE LINE OF it_adrc,
SELECT addrnumber name1 street city1 region post_code1 tel_number
FROM adrc INTO TABLE it_adrc
FOR ALL ENTRIES IN it_detail
WHERE addrnumber = it_detail-adrnr.
Regards,
DavisIf you only need the fields mentioned in the select query, then follow this:
TYPES: BEGIN OF ADRC_TYPE,
ADDRNUMBER LIKE ADRC-ADDRNUMBER,
NAME1 LIKE ADRC-NAME1,
STREET LIKE ADRC-STREET,
CITY LIKE ADRC-CITY,
REGION LIKE ADRC-REGION,
POST_CODE1 LIKE ADRC-POST_CODE1,
TEL_NUMBER LIKE ADRC-TEL_NUMBER,
END OF ADRC_TYPE,
ADRC_T_TYPE TYPE TABLE OF ADRC_TYPE.
DATA: IT_ADRC TYPE ADRC_T_TYPE WITH HEADER LINE.
IF NOT IT_DETAIL[] IS INITIAL.
SELECT addrnumber name1 street city1 region post_code1 tel_number
FROM adrc INTO TABLE it_adrc
FOR ALL ENTRIES IN it_detail
WHERE addrnumber = it_detail-adrnr.
ENDIF.
Thanks,
SKJ -
Help needed with a SELECT statement. How can I make it run faster?
Hi,
not sure if my brain is just too tired but I can't seem to crack this problem today.
Here is my scenario.
I have 2 tables
TABLE1 (searchId INTEGER, routeId INTEGER);
TABLE2 (routeId INTEGER, cityId INTEGER);
There are indexes on all 4 columns.
(routeId on TABLE1 is a primary key).
In the data I am using, a given search has more than 500 routes, each route has between 10 and 300 cities among more than 4000 possible different cities.
Now, what I want to create is the list of route couple, within a certain search, that do not have a single city in common.
That list should populate a table with the following structure
TABLE3 (searchId INTEGER, routeId1 INTEGER, routeId2 INTEGER)
Here is the fastest select statement I have found so far.
SELECT :searchId, t1.routeId, t2.routeId FROM table1 t1, table1 t2
WHERE t1.searchId=:searchId AND t2.searchId=:searchId
AND t1.routeId>t2.routeId
AND NOT EXISTS (
SELECT cityId FROM table2
WHERE routeId=t1.routeId
INTERSECT
SELECT cityId FROM table2
WHERE routeId=t2.routeId);
But it still seem really slow to me.
Any suggestion for an improved version is welcome.
Thanks,
Martin.
Title was edited by:
user453358I originaly posted this thread because I tought I was missing something "obvious" that would perform better that would make my SELECT statement perform better.
So I did not want to go as deep as using TKPROOF yet.
Here is the statistics I gets on my statement.
1 SELECT t1.searchId,t1.routeId, t2.routeId id2
2 FROM table1 t1, table1 t2
3 WHERE t1.searchid=t2.searchid
4 AND t1.searchId=91
5 AND t1.routeId>t2.routeId
6 AND NOT EXISTS (
7 SELECT cityId FROM table2
8 WHERE routeId=t1.routeId
9 INTERSECT
10 SELECT cityId FROM table2
11* WHERE routeId=t2.routeId)
SQL> /
43302 rows.
Tidsåtgång: 00:01:55.02
Körschema
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=9 Card=1 Bytes=14)
1 0 FILTER
2 1 TABLE ACCESS (BY INDEX ROWID) OF 'table1' (TABLE) (Cost=1 Card=1 Bytes=7)
3 2 NESTED LOOPS (Cost=3 Card=1 Bytes=14)
4 3 TABLE ACCESS (BY INDEX ROWID) OF 'table1' (TABLE) (Cost=2 Card=1 Bytes=7)
5 4 INDEX (RANGE SCAN) OF 'table1_IDX1' (INDEX) (Cost=1 Card=1)
6 3 INDEX (RANGE SCAN) OF 'table1_IDX1' (INDEX) (Cost=0 Card=1)
7 1 INTERSECTION
8 7 SORT (UNIQUE) (Cost=3 Card=108 Bytes=864)
9 8 TABLE ACCESS (BY INDEX ROWID) OF 'table2' (TABLE) (Cost=2 Card=108 Bytes=864)
10 9 INDEX (RANGE SCAN) OF 'table2_IDX1' (INDEX) (Cost=1 Card=108)
11 7 SORT (UNIQUE) (Cost=3 Card=108 Bytes=864)
12 11 TABLE ACCESS (BY INDEX ROWID) OF 'table2' (TABLE) (Cost=2 Card=108 Bytes=864)
13 12 INDEX (RANGE SCAN) OF 'table2_IDX1' (INDEX) (Cost=1 Card=108)
Statistik
1 recursive calls
0 db block gets
2872765 consistent gets
0 physical reads
812 redo size
964172 bytes sent via SQL*Net to client
32245 bytes received via SQL*Net from client
2888 SQL*Net roundtrips to/from client
860256 sorts (memory)
0 sorts (disk)
43302 rows processed Looks like a big number of consistent gets! Any idea how to improve on that?
Martin. -
Need to write with single select statement
NAME
SAL
GENDER
X 10000 M
X 9000 F
Y 8000 M
Y 7000 M
Z 6000 F
Z 5000 F
A 4000 M
A 4000 F
1) How to write a query that displays the name that exist in both male and female gender. using single select statement
I tried this one
SELECT NAME FROM EMPL WHERE NAME IN (SELECT NAME FROM EMPL WHERE GENDER='F') AND GENDER='M';
It worked fine
But when i converted to single select statement it didn't work . You can find the query below. can i rewrite in any possible ways(using single select statement).
Select name from table_name where gender='M' and gender='F'
thanks in advanceIf a Name does not exist with same gender
i.e
Name Gender
X M
X M
if above sceniorio not exist in ur data than following query will work
select name from table_name
group by name
having count(name) > 1 -
Passing parameter into select statement by using function in discoverer
I have created two functions in database named Period_in and Period_out and a global variable g_period_name
I have called Period_out function in VIEW(Select statement where condition).
I have registered Period_in function in discoverer admin then created calculation (called Period_in(:input parameter))in discoverer plus.
My expectation is user will enter period name and that will hit Period_in function and returns 1 and stores entered period name in g_period_name at runtime. then VIEW will executed and fetches data.
But i am getting no data found.
Problem is 2 functions running at the same time in select statement. Please help me to overcome this. Thanks in advance
FUNCTION period_in (p_period VARCHAR2)
RETURN NUMBER
AS
BEGIN
g_period_name := p_period;
RETURN 1;
END period_in;
FUNCTION period_out
RETURN VARCHAR2
AS
BEGIN
RETURN g_period_name;
END period_out;You can use this code:
WITH cte
AS ( SELECT EmpID ,
EmpName ,
[dbo].[udf_testFunction](EmpID) AS testfunctionvalue
FROM #Temp
SELECT EmpID ,
EmpName ,
testfunctionvalue ,
testfunctionvalue * EmpID ,
testfunctionvalue + 2
FROM cte
But using scalar functions in select clause can hurt the performance. Please see this link:
SQL Server Scalar User Defined Function Performance
T-SQL Articles
T-SQL e-book by TechNet Wiki Community
T-SQL blog -
TDE Issue with UPDATE/SELECT statement
We just implemented TDE on a table and now our import script is getting errors. The import script has not changed and has been running fine for over a year. The script failed right after applying TDE on the table.
Oracle 10g Release 2 on Solaris.
Here are the encrypted colums:
COLUMN_NAME ENCRYPTION_ALG SALT
PERSON_ID AES 192 bits key NO
PERSON_KEY AES 192 bits key NO
USERNAME AES 192 bits key NO
FIRST_NAME AES 192 bits key NO
MIDDLE_NAME AES 192 bits key NO
LAST_NAME AES 192 bits key NO
NICKNAME AES 192 bits key NO
EMAIL_ADDRESS AES 192 bits key NO
AKO_EMAIL AES 192 bits key NO
CREATION_DATE AES 192 bits key NO
Here is the UPDATE/SELECT statement that is failing:
UPDATE cslmo_framework.users a
SET ( person_id
, username
, first_name
, middle_name
, last_name
, suffix
, user_status_seq
= (
SELECT person_id
, username
, first_name
, middle_name
, last_name
, suffix
, user_status_seq
FROM cslmo.vw_import_employee i
WHERE i.person_key = a.person_key
WHERE EXISTS
SELECT 1
FROM cslmo.vw_import_employee i
WHERE i.person_key = a.person_key
AND ( NVL(a.person_id,0) <> NVL(i.person_id,0)
OR NVL(a.username,' ') <> NVL(i.username,' ')
OR NVL(a.first_name,' ') <> NVL(i.first_name,' ')
OR NVL(a.middle_name,' ') <> NVL(i.middle_name,' ')
OR NVL(a.last_name,' ') <> NVL(i.last_name,' ')
OR NVL(a.suffix,' ') <> NVL(i.suffix,' ')
OR NVL(a.user_status_seq,99) <> NVL(i.user_status_seq,99)
cslmo@awpswebj-dev> exec cslmo.pkg_acpers_import.p_users
Error importing USERS table.START p_users UPDATE
Error Message: ORA-01483: invalid length for DATE or NUMBER bind variableI rewrote the procedure using BULK COLLECT and a FORALL statement and that seems to work fine. Here is the new code:
declare
bulk_errors EXCEPTION ;
PRAGMA EXCEPTION_INIT(bulk_errors,-24381) ;
l_idx NUMBER ;
l_err_msg VARCHAR2(2000) ;
l_err_code NUMBER ;
l_update NUMBER := 0 ;
l_count NUMBER := 0 ;
TYPE person_key_tt
IS
TABLE OF cslmo_framework.users.person_key%TYPE
INDEX BY BINARY_INTEGER ;
arr_person_key person_key_tt ;
TYPE person_id_tt
IS
TABLE OF cslmo_framework.users.person_id%TYPE
INDEX BY BINARY_INTEGER ;
arr_person_id person_id_tt ;
TYPE username_tt
IS
TABLE OF cslmo_framework.users.username%TYPE
INDEX BY BINARY_INTEGER ;
arr_username username_tt ;
TYPE first_name_tt
IS
TABLE OF cslmo_framework.users.first_name%TYPE
INDEX BY BINARY_INTEGER ;
arr_first_name first_name_tt ;
TYPE middle_name_tt
IS
TABLE OF cslmo_framework.users.middle_name%TYPE
INDEX BY BINARY_INTEGER ;
arr_middle_name middle_name_tt ;
TYPE last_name_tt
IS
TABLE OF cslmo_framework.users.last_name%TYPE
INDEX BY BINARY_INTEGER ;
arr_last_name last_name_tt ;
TYPE suffix_tt
IS
TABLE OF cslmo_framework.users.suffix%TYPE
INDEX BY BINARY_INTEGER ;
arr_suffix suffix_tt ;
TYPE user_status_seq_tt
IS
TABLE OF cslmo_framework.users.user_status_seq%TYPE
INDEX BY BINARY_INTEGER ;
arr_user_status_seq user_status_seq_tt ;
CURSOR users_upd IS
SELECT i.person_key
,i.person_id
,i.username
,i.first_name
,i.middle_name
,i.last_name
,i.suffix
,i.user_status_seq
FROM cslmo.vw_import_employee i ,
cslmo_framework.users u
WHERE i.person_key = u.person_key ;
begin
OPEN users_upd ;
LOOP
FETCH users_upd
BULK
COLLECT
INTO arr_person_key
, arr_person_id
, arr_username
, arr_first_name
, arr_middle_name
, arr_last_name
, arr_suffix
, arr_user_status_seq
LIMIT 100 ;
FORALL idx IN 1 .. arr_person_key.COUNT
SAVE EXCEPTIONS
UPDATE cslmo_framework.users u
SET
person_id = arr_person_id(idx)
, username = arr_username(idx)
, first_name = arr_first_name(idx)
, middle_name = arr_middle_name(idx)
, last_name = arr_last_name(idx)
, suffix = arr_suffix(idx)
, user_status_seq = arr_user_status_seq(idx)
WHERE u.person_key = arr_person_key(idx)
AND
( NVL(u.person_id,0) != NVL(arr_person_id(idx),0)
OR
NVL(u.username,' ') != NVL(arr_username(idx),' ')
OR
NVL(u.first_name,' ') != NVL(arr_first_name(idx),' ')
OR
NVL(u.middle_name, ' ') != NVL(arr_middle_name(idx), ' ')
OR
NVL(u.last_name,' ') != NVL(arr_last_name(idx),' ')
OR
NVL(u.suffix,' ') != NVL(arr_suffix(idx),' ')
OR
NVL(u.user_status_seq,99) != NVL(arr_user_status_seq(idx),99)
l_count := arr_person_key.COUNT ;
l_update := l_update + l_count ;
EXIT WHEN users_upd%NOTFOUND ;
END LOOP ;
CLOSE users_upd ;
COMMIT ;
dbms_output.put_line('updated records: ' || l_update);
EXCEPTION
WHEN bulk_errors THEN
FOR i IN 1 .. sql%BULK_EXCEPTIONS.COUNT
LOOP
l_err_code := sql%BULK_EXCEPTIONS(i).error_code ;
l_err_msg := sqlerrm(-l_err_code) ;
l_idx := sql%BULK_EXCEPTIONS(i).error_index;
dbms_output.put_line('error code: ' || l_err_code);
dbms_output.put_line('error msg: ' || l_err_msg);
dbms_output.put_line('at index: ' || l_idx);
END LOOP ;
ROLLBACK;
RAISE;
end ;
cslmo@awpswebj-dev> @cslmo_users_update
updated records: 1274There are about 20 or so other procedure in the import script. I don't want to rewrite them.
Does anyone know why the UPDATE/SELECT is failing? I checked Metalink and could not find anything about this problem.This is now an Oracle bug, #9182070 on Metalink.
TDE (transparent data encryption) does not work when an update/select statement references a remote database. -
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 -
Can I query with a select statement in the from statement
I'm working with an application that creates a MASTERTABLE that keeps track of DATATABLEs as it creates them. These data tables are only allowed to be so big, so the data tables are time stamped. What I need to do is to be able to query the MASTERTABLE to find out what the latest datatable is and then query the specific datatable.
I've tried
select count(*) from (select max(timestamp) from mastertable)
and it always comes back with a count of 1.
Is this possible, or is there a better way?Well, I'm trying to understand... and if I understand, then you need something dynamic. I did create the following example, of course not exactly as yours (I don't have your data). Each employee has a table with his name, containing the sal history, and I want to query that table starting from actual sal :
SCOTT@db102 SQL> select ename from emp where sal= 3000;
ENAME
SCOTT
FORD
SCOTT@db102 SQL> select * from scott;
SAL_DATE SAL
01-JAN-85 2500
01-JAN-95 2750
01-JAN-05 3000
SCOTT@db102 SQL> set serveroutput on
SCOTT@db102 SQL> declare
2 v_rc sys_refcursor;
3 tname varchar2(30);
4 v_date date;
5 v_sal number;
6 begin
7 select max(ename) into tname
8 from emp
9 where sal = 3000;
10 open v_rc for 'select * from '||tname;
11 loop
12 fetch v_rc into v_date,v_sal;
13 exit when v_rc%notfound;
14 dbms_output.put_line(v_date||' '||v_sal);
15 end loop;
16* end;
SCOTT@db102 SQL> /
01-JAN-85 2500
01-JAN-95 2750
01-JAN-05 3000
PL/SQL procedure successfully completed.
SCOTT@db102 SQL> -
Need help with a SELECT statement
Dear forumers,
I'm a newbie in ABAP and I'm trying to figure out what the following line means (in bold letters):-
SELECT SINGLE STAT2 FROM PA0000 INTO PA0000-STAT2
WHERE PERNR = ITAB_DATA-STAFF_NO.
Does this mean that the single data from the STAT2 field is selected and then placed back into the same field (doesn't quite makes sense, right)?
Please help and many thanks in advance!SELECT SINGLE STAT2 FROM PA0000 INTO PA0000-STAT2
WHERE PERNR = ITAB_DATA-STAFF_NO.
Does this mean that the single data from the STAT2 field is selected and then placed back into the same field (doesn't quite makes sense, right)?
it sense very much right.
have you heared about table buffer concept?
here this concept exactly comes.
try with this below code:
TABLES:pa0000."tables must be decleare
SELECT SINGLE STAT2 FROM PA0000 INTO PA0000-STAT2.
write:PA0000-STAT2.
and since you are using select single than you should be use much key as much possible for getting accurate data.other wise system will pick first data which match your where condition.
Amit. -
How to insert ORACLE HINT into select statement....
Hi team,
Can you please suggest me how to add an Oracle hint to point the Program to BSAD~1.
Index BSAD1 has all three fields MANDT, BUKRS, AUGDT which are there in the where clause. But as per the execution plan index BSAD0 is being used which is the primary one.
Also the stats for this table are are current.
Thanks in Advance.
Puneet.Hi punnet, look at this example:
SELECT MAX( kkop~augbd )
INTO it_gen_docs-augbd
FROM ( fkkvkp AS vkp INNER JOIN dfkkop AS kkop
ON vkpvkont = kkopvkont ) INNER JOIN dfkkko AS kkko
ON kkopaugbl = kkkoopbel
WHERE vkp~exvko = ti_cuentas-exvko
AND kkop~bukrs = p_bukrs
AND kkop~blart IN r_blart
AND kkop~augst = '9'
AND kkko~blart IN r_blartd
%_HINTS ORACLE 'INDEX("DFKKOP" "DFKKOP~Z07")'.
DFKKOP is the table name and DFKKOP~Z07 is the index.
I hope this helps you.
Maybe you are looking for
-
Validation error message in JSF 1.2
I am testing my Web application inside Tomcat 6.0.2 and using JSF 1.2. I was surprised to see that validation error messages do not only display the custom error message, but also the id tag and a "Validation Error: " text. For instance, if an input
-
AOL stripping pdf from "multipart/alternative" text email
Hi! I am using MYOB AccountEdge and it has a function within the program to send out statements as pdf attachments to a text email. As of the beginning of this year, AOL is stripping off the pdf attachment, but the text email goes through. Last year,
-
Task details in BPM worklist on SOA 11g could not retrieved.Experts plz adv
Hi, This is regarding issues when I click on the Task details on the BPM worklist 11G. I am invoking a BPEL process using custom JSP and from the custom JSP form values are sent to BPEL and from BPEL i am invoking the Human workflow. Tech used: BPEL
-
HT1349 MS office critical update, now unable to boot up Mac book Pro.
First it was at login screen, but no passwors would unlock. Rebooted and it has not fullt booted back up.
-
How to organize Portlets?
We are using IBM RAD as the tool to develop JSF JSR168 Portlets. In our Project, there are around 70 Portlets we need to develop. Should we contain all these portlets in one Portlet Project, or split them into several ones. What is the normal way to