How to use dynamic query for this ??
hi , i am new to ABAP. i got a requirement to write dynamic query for the following code.
kindly address. two set of queries are same.but condition is different.
.IF p_psd EQ ' '.
*C--End of change DF 1232137- (Transport # :CIDK980530 )
*C--FETCH THE Deliverd Quantiity and Material Number
SELECT aufnr "ORDER number
wemng "Quantity of goods received for the order item
matnr "MATERIAL NUMBER
pwerk "PLANT
dauat "Order Type
FROM afpo
INTO TABLE t_afpo
WHERE aufnr IN s_order
AND wemng IN s_dqt
AND matnr IN s_matnr
AND pwerk IN s_plant
AND dauat = c_ro.
IF sy-subrc = 0.
SORT t_afpo BY aufnr matnr pwerk.
*C--FETCH THE OBJECT NUMBER
SELECT aufnr "ORDER number
objnr "Object number
FROM aufk
INTO TABLE t_aufk
FOR ALL ENTRIES IN t_afpo
WHERE aufnr = t_afpo-aufnr.
IF sy-subrc = 0.
SORT t_aufk BY aufnr objnr.
*C--FETCH THE Target Quantiity
SELECT aufnr "ORDER number
gamng "Total order quantity target quantity
FROM afko
INTO TABLE t_afko
FOR ALL ENTRIES IN t_afpo
WHERE aufnr = t_afpo-aufnr
AND gamng IN s_tqt.
IF sy-subrc = 0.
SORT t_afko BY aufnr .
ENDIF.
ENDIF.
ELSE.
MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
LEAVE LIST-PROCESSING.
ENDIF.
*C--Begin of change DF 1232137- (Transport # :CIDK980530 )
ENDIF.
IF p_psd EQ c_x.
SELECT aufnr "ORDER number
wemng "Quantity of goods received for the order item
matnr "MATERIAL NUMBER
pwerk "PLANT
dauat "Order Type
FROM afpo
INTO TABLE t_afpo
WHERE aufnr IN s_order
AND wemng > 0
AND matnr IN s_matnr
AND pwerk IN s_plant
AND dauat = c_ro.
if sy-subrc = 0.
*C--FETCH THE OBJECT NUMBER
IF NOT t_afpo[] IS INITIAL.
SORT t_afpo BY aufnr matnr pwerk.
SELECT aufnr "ORDER number
objnr "Object number
FROM aufk
INTO TABLE t_aufk
FOR ALL ENTRIES IN t_afpo
WHERE aufnr = t_afpo-aufnr.
IF sy-subrc = 0.
SORT t_afko BY aufnr gamng.
ELSE.
MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.
IF NOT t_afpo[] IS INITIAL.
*C--FETCH THE Target Quantiity
SELECT aufnr "ORDER number
gamng "Total order quantity target quantity
FROM afko
INTO TABLE t_afko
FOR ALL ENTRIES IN t_afpo
WHERE aufnr = t_afpo-aufnr
AND gamng <> t_afpo-wemng .
IF sy-subrc = 0.
SORT t_afko BY aufnr gamng.
ELSE.
MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.
ELSE.
MESSAGE text-e03 TYPE c_s. " No data for the selection criteria
LEAVE LIST-PROCESSING.
ENDIF.
Edited by: Thomas Zloch on Jan 5, 2011 1:30 PM please use code tags
Hi friend,
Try using MACRO and dynamic WHERE condition.
Group simialr Select statements under a Macro.
Build a dynamic where by checking conditions
Call macro passing dynamic where condition.
TABLES afpo.
DATA: str TYPE string.
*Macro definition
DEFINE operation.
select single *
from afpo into afpo
where (&1). " Dynamic condition
END-OF-DEFINITION.
*Build dynamic WHERE by checking some conditions
*If conditon
CONCATENATE 'AUFNR = ''000000700008''' 'AND POSNR = ''0001''' INTO str SEPARATED BY space.
*Else
CONCATENATE 'AUFNR = ''000000700008''' 'AND POSNR = ''0002''' INTO str SEPARATED BY space.
*Endif.
*Call Macro passing dynamic WHERE condition
operation str.
Similar Messages
-
How to use dynamic query for Result table
Hello Experts,
I want to use dynamic query and then display the result in the assignment block.
Using dynamic query BTQAct and BTQRAct and base on some search criteria i want tofilter and then append the result in the result table of that custom context node, and then it should display the result in the view in UI.
SO can you please provide me the samplle code on how to use the dynamic query and append in the result table.
Regards.Hi,
Please find below sample code:
data: query TYPE REF TO cl_crm_bol_dquery_service,
result TYPE REF TO if_bol_bo_col.
DATA: lt_params TYPE crmt_name_value_pair_tab,
lwa_params TYPE crmt_name_value_pair.
query = cl_crm_bol_dquery_service=>get_instance( 'BTQAct' ). " Get instance of dynamic query
Set general query parameter for maximum number of hits
lwa_params-name = 'MAX_HITS' .
lwa_params-value = '50'.
APPEND lwa_params TO lt_params.
query->set_query_parameters( it_parameters = lt_params ).
query->add_selection_param( iv_attr_name = 'OBJECT_ID'
iv_sign = 'I'
iv_option = 'EQ'
iv_low = <lv_objectid>
iv_high = '' ). " Set your search criteria. Repeat this code if you have multiple parameters
"You can find possible search options for a query object in GENIL_BOL_BROWSER
result ?= query->get_query_result( ). " Get result from your search query
me->typed_context-> <your result context node>->set_collection( result ).
Here you will have to create a context node in your view which would refer to query result object like for BTQAct its BTQRAct
Hope this helps.
e Regards,
Bhushan -
How to form a query for this requirment
Hi Friends,
I have a database table in which I store the employee data along with his phone number. Now this row of data can repeat for different phone number depending on if it is office phone or home phone or cell phone.
But in the output of query, I need name of empoyee and other three columns namely "Home Phone", "Office Phone" and "Cell Phone".
If employee has three rows for each kind of phone, then in the result of query all three columns for phone numbers should be filled, otherwise as many columns should be filled with data as different phone numbers employee has.
Can any one please post SQL query for this scenario ?
Thanks in AdavanceI cannot imagine, that second and third query are
under any circumstances faster as first one, but i
can imagine that they are slower You stated that query without the inline view can only be faster. Did you check on optimizer plans or use tkprof to verify your claim?
A quick check on those two selects
SELECT object_id, object_type, object_name
FROM user_objects;
SELECT object_id, object_type, object_name
FROM (SELECT object_id, object_type, object_name
FROM user_objects)
;didn't show any changes in the explain plan unter 10g1.
C. -
How to write select query for this
Hi,
I had a html form and in the for i had drop down box and it needs to select multiple values from the drop down box. When i select multiple values then i have to write the SQL select statement query .
When i try to write the select statement and trying to run i am getting error.
select * from Table
where emo_no = '1,2,3'
this is how i write query please suggest me how to write query for selecting multiple values from the drop down box.
Thanksselect * from Table
where emo_no in ( 1,2,3)
for integer values
select * from Table
where emo_no in ('1','2','3')
for characters
If we talk about large scale applications that may have millions of records, I would suggest this.
declare @t table (v int)
insert into t (v) values (1)
insert into t (v) valves (2)
insert into t (v) values (3)
select *
from table
inner join @t t on table.emo_no = t.v
Using "in" for a where clause is not so bad for filtering on a few values, but if you are filtering a lot of rows and a lot of values (emo_no) the performance degrades quickly for some reasons beyond the scope of this.
This is just one solution, I'll through this out as well, instead of an in memory (@t) table, doing a disk based temp table (#t) and creating an index on the column "v".
create table #t (v int)
insert into #t (v) values (1)
insert into #t (v) valves (2)
insert into #t (v) values (3)
create index ix_t on #t (v)
select *
from table
inner join #t t on table.emo_no = t.v
drop table #t
Pardon any syntax errors and careful using a drop statement.
Sometimes in memory tables work better than disk temp tables, it takes some testing and trial and error depending on your datasets to determine the best solution.
Probably too much info ;-)
Byron Mann
[email protected]
[email protected]
Software Architect
hosting.com | hostmysite.com
http://www.hostmysite.com/?utm_source=bb -
How to use execute query For a single record
Hi All,
I am working with oracle forms 10g, I have developed a custom form.
I the form user enter some data and click save in the menu and data get inserted into my table. Inside the insert statement i have hardcoded some values, Once data get inserted i cant able to see that values immediately in my text fields in my form.After requerying i can able to see the changes.
For example I have a text field called Status, and the field is display only field. At that time of insert i have hardcoded as "INCOMPLETE". Once the user enter the data in the form and click save the data get inserted in to my table but i cant able to see the status, after i requery my form i can able to see the status.
Here i do multi insert also.
This is my insert statement
BEGIN
First_Record;
LOOP
IF :BANK_GUARANTEE_BLK.CHECK_IN_OUT = 'Y'
THEN
XXBANK_GUARANTEE_HEADERS.XXBANK_GUARANTEE_INSERT;(this is my package, here i have written my insert statement)
--Execute_query;
END IF;
Exit when :System.Last_Record = 'TRUE';
Next_Record;
END LOOP;
END;
If user insert only one row and i gave Execute_query to refresh and bring the current data, but when i use execute_query Its brings up all the datas in the table.
Can any one tell me how to avoid this and how to use execute_query for a single record.
Thanks ®ards
SrikkanthSolved,
The solution is
set_block_property('LC_REQ_BLK',ONETIME_WHERE,'LC_PO_NUMBER='||:LC_REQ_BLK.LC_PO_NUMBER);
go_block('LC_REQ_BLK');
execute_query;
Works fine.
Regards
Sri -
How to prepare a query for this validation
I am supposed to implement the below validation using query:
retrieve emp_no from employee table where emp_desgn='MANAGER' and emp_status='OFFSHORE'
1. if the emp_no exists display emp_first_name,emp_last_name,emp_remarks.
2. if the emp_no doesn't exists then display emp_first_name, emp_last_name as blanks and emp_remarks as "EMPLOYEE not available in OFFSHORE'.
tablename: employee
can any one please give me the query with this condition. the validation should be implemented in queries and not using functions or procedures.i have tried with this
select emp_no,(
case emp_no
when null then emp_first_name
else 'SPACE'
end) empfirst_name,
(case emp_no
when null then emp_last_name
else 'SPACE '
end
) emplast_name,
(case emp_no
when null then emp_remarks
else 'EMPLOYEE NOT AVAILABLE IN OFFSHORE'
end
) empremarks
from employee
where emp_design='MANAGER' and emp_status='OFFSHORE'
here emp_no is PK so the emp_no in case statement will execute only if the where condition satisifies. but i am looking the results for the below data.
EMP_NO EMP_FIRST_NAME EMP_LAST_NAME EMP_DESIGN EMP_STATUS EMP_REMARKS
1 john Andrey SRDEVELOPER ONSITE DOING GOOD
2 Peter Andrey MANAGER ONSITE DOING GOOD
3 Samuel Andrey MANAGER OFFSHORE DOING GOOD
4 Joseph Andrey DELIVERYHEAD OFFSHORE DOING GOOD
5 Paul Andrey SRARCHITECT OFFSHORE DOING GOOD
i am expecting the results like for emp_no 3 it should display firsname, last name as blank spaces and remarks should be "EMPLOYEE Not availabe in OFFSHORE' but for all it should show the firstnname,lastname,remarks. -
How to write a query for this data??
In this table i have column dob which is DATE type,for example 12-jan-89 I want output like this
Year Day
12-jan-89 Thusrs_day
12-jan-90 Friday
upto
12-jan-14 sundaykrishnagopi wrote:
No not like that ,I want up to 2014 year
Ok, so lets say you have table like this
SQL> create table my_table(dob date);
Table created.
SQL> insert into my_table (dob) values( to_date('12-jan-1989', 'dd-mon-yyyy'));
1 row created.
SQL> commit;
Commit complete.
SQL> select * from my_table;
DOB
12-JAN-89
You can write a query like this
select dob + (level -1) dob
, to_char(dob + (level -1), 'fmDay') day_
from my_table
connect
by level <= (dob + interval '25' year) - dob + 1; -
How to use dynamic SQL in this case for best performance
I have the table with following columns
ID NUMBER,
DATA LONG,
TAG VARCHAR2(255)
Records in this table will be like following
1 this is an abstract ABSTRACT
1 this is author AUTHOR
1 100 PRICE
2 this is an abstract ABSTRACT
2 this is author AUTHOR
3 contract is this CONTRACT
Basically all the records with the same number constitute 1 record for another table. Tag in the above table indicates that what column it is and DATAwill have the actual data for that column. I need to populate the second table based an the above table but will not get the same number of TAGS all the time. I need to insert the values only for the columns provided in the TAG field. How will I accomplish this by dynamic sql. Do I create a loop and create two strings one with columns and one with values and then combine them and use execute immediate to insert into table? Is there an easier way to do this??
Please respond quickly.
Thanks
Bhawna
null> so which collection should i use to perform it..
so that performance is best......
Program to interfaces. That way, you can switch out implementations and test for yourself which performance is best in an actual production context. But first, write your program so that it works. Worry about refactoring for performance once your program is written and it works.
> plz send me the logic....
Give it a shot on your own first; we can help if you get stuck.
~ -
How to use dynamic values for service-ref
service-ref element allows for static configuration for endpoint reference as follows:
<copy>
<from>
<literal>
<sref:service-ref xmlns:sref="http://docs.oasis-open.org/wsbpel/2.0/serviceref">
<EndpointReference xmlns="http://docs.oasis-open.org/wsbpel/2.0/process/executable">
<Address>http://localhost:8080/mockservice</Address>
</EndpointReference>
</sref:service-ref>
</literal>
</from>
<to>$serviceref</to>
</copy>
I want to change the address value dynamically in service-ref element. How can I achieve it ?Hi,
Why don't you try:
1. Bpel references
You can select a BPEL reference property in your composite.xml and use it within your bpel process. This is explained here:
http://orasoa.blogspot.co.uk/2009/08/soa-11g-preferences.html
Then you can create a deployment configuration plan. Right-click on the composite file and generate a deployment configuration plan for your composite. This should create a search/replace construction for your preference.
2. DVM (Data Value Maps)
You can populate the address by using dvm lookup function. Create a DVM file with two columns, one to specify the Address/URL and populate the other column with the actual value. Use the address as your unique lookup criteria to retrieve the value. This value can be configured per environment.
Hope this helps.
Thanks
Sander -
Would I use Dynamic Actions for this?
As part of my hiring action, I would like to trigger an email to the Org's chief once the employee record is created. Is this done via Dynamic Actions? If so, can someone give me a step-by-step on how to set that up?
Thanks!Hi you can use code like this in table T588Z
Infotype
|0000 | | |06|101|P|P0000-MASSN='E9'| check Action Type
|0000 | | |06|102|P|P0000-MASSG='02'| check Reason for Action
|0000 | | |06|103|P|PSPAR-PERSG='4' | check Employee group
|0000 | | |06|104|W|PSPAR-PERSG='6' | check employee subgroup
|0000 | | |04|105|M|M0001 | call a feature
With this feature M0001 I think you can make it
M0001 Parameter Settings for Mail on Change to Infotype Record
Object
Feature
Task
This feature enables you to control who is sent a mail, the text sent,
and the processing type used.
Use
The feature can be used for all master data infotypes for both employees
and applicants.
Note
Decision field TCLAS enables you to control whether processing is
carried out only for employees (TCLAS=A) or only for applicants
(TCLAS=B).
Procedure
The return matrix of the feature has the following form: XXXXX ZZZZZ
XXXXX Mail attribute
o IDTXT - Name of a standard text. The first line is used as a title,
therefore you should formulate the mail after the second
line
of the standard text. The above variable is entered. You can
only activate the infotype fields that trigger a mail.
o RECV1 - Recipient 1 is the administrator for HR master data from the
Organizational Assignment infotype (0001) who is responsible
for the employee on today's date.
For applicants this is the personnel officer.
The user name contained in T526 is converted into an office
name. This conversion takes place for RECV2 and RECV3.
o RECV2 - Recipient 2 is the payroll administrator taken from
the Organizational Assignment infotype (0001) who is
responsible for the employee on today's date.
This field is not supported for applicants.
o RECV3 - Recipient 3 is for the Time Management administrator taken
from the Organizational Assignment infotype (0001) who is
responsible for the employee on today's date.
This field is not supported for applicants.
o SUBTY - You want the employee whose data is changed to receive an
e-mail
Here you specify which subtype is to be used to read the
employee's infotype 0105 record, that is, in which subtype
you
store the employee's mail name. The employee only
receives a mail if SUBTY is filled.
o OUTBX - The mail should be in the sender's outbox.
o DISTR - Distribution list that is stored in the general folders
in SAP-Office (Transaction SO04).
o NAME1 - If the infotype that triggers the mail is not the
Organizational Assignment infotype (0001), then the feature
specified is read.
You can define distribution lists and recipients in
this feature. The standard SAP system contains the
feature RCIEV, which can be used as an example.
o NAME2 - If the infotype that triggers the mail is the
Organizational Assignment infotype (0001),
then the feature specified will be read
using the new data contained in infotype 0001. New data
means data contained in an infotype record for infotype
0001 that has been changed after the mail was sent. You
can define a distribution list and a recipient in this
feature.
The standard SAP system contains the feature RCNEW,
which can be used as an example.
o NAME3 - If the infotype that triggers the mail is the
Organizational Assignment infotype (0001),
then the feature specified here, will be
read using the old data contained in the infotype. Old
data means data prior to changing the infotype record that
triggered a mail to be sent. You can define distribution
lists and recipients in the feature. The standard SAP
system contains feature RCOLD, which can be used as an
example.
You can give a mail a process. The recipient of the mail can start the
transaction specified from the mail:
o TCODE - Transaction code
o PAINF - Infotype
o PASUB - Subtype
o PABEG - Begin date
o PAEND - End date
o PAFCD - Function code (OKcode)
ZZZZZ 30-character value that is entered in the field.
o XXXXX = IDTXT: ZZZZZ is a standard text from SAPScript with the text
ID PAMA (Transaction SO10)
o XXXXX = RECV1, RECV2, RECV3: ZZZZZ=X is the appropriate
administrator who is to receive the mail
o XXXXX = SUBTY: ZZZZZ is 4-digit subtype for the infotype 0105
o XXXXX = OUTBX: ZZZZZ=X the mail is put in the sender's outbox
o XXXXX = TCODE: ZZZZZ=PA30, PA20, PB30 or PB20
o XXXXX = PAINF: ZZZZZ is the 4-digit number of an infotype
o XXXXX = PASUB: ZZZZZ is the 4-digit number of a subtype
o XXXXX = PABEG, PAEND: ZZZZZ= either an 8-digit date in the format
YYYYMMDD, e.g. ZZZZZ=19950630 for "30.06.1995", or enter the name of
a variable in inverted commas, e.g. ZZZZZ='P0001-ENDDA'. The
following exist: P0001-BEGDA, P0001-ENDDA, P0002-BEGDA, P0002-ENDDA,
Pnnnn-BEGDA, Pnnnn-ENDDA, nnnn is the number of the infotype that
triggers the mail to be sent.
o XXXXX = PAFCD: ZZZZZ=COP Copy, ZZZZZ=DEL Delete, ZZZZZ=DIS
Display, ZZZZZ=EDQ Lock/Unlock, ZZZZZ=INS Create, ZZZZZ=MOD Change
By using the operation NEXTR, you will jump into the feature's
subsequent line. The last line of an action is closed with commas (not
NEXTR). -
Here's how to use DYNAMIC tables for almost any structure (4.6C onwards)
Hi guys
I'm describing a feature here that has been around since 4.6C that is not really well known but can really simplfy programming where you need to get data into some sort of internal table and then display it either as a classical list or as al ALV grid.
This feature is RTTI which allows you to retrieve your structure, build a dynamic FCAT (Field catalog) and a Dynamic table.
Here's a really quick little program which reads 200 entries from VAPMA into a dynamic table. Any structure will work if you use the code sample shown.
To pass it to an ALV GRID is then really simple as you've already got the Field Catalog, Table and Data.
The method I'm showing below will work for almost ANY structure you care to name whether or not the fields are in the data dictionary.
I create a dynamic FCAT and dynamic table based on the FCAT and then populate it.
You can create field catalogs dynamically quite simply by using the new RTTI facility available from 4.6C onwards.
(From here it's only a small step to dynamic tables and EASY ALV grid displays)
Example to create dynamic FCAT and table and populate it with 200 entries from VAPMA
PROGRAM ZZ_BUILD_FLDCATALOG.
tables: vapma.
Define any structure
types: begin of s_elements,
vbeln type vapma-vbeln,
posnr type vapma-posnr,
matnr type vapma-matnr,
kunnr type vapma-kunnr,
werks type vapma-werks,
vkorg type vapma-vkorg,
vkbur type vapma-vkbur,
status type c,
end of s_elements.
end of your structure
data lr_rtti_struc type ref to cl_abap_structdescr .
data:
zog like line of lr_rtti_struc->components .
data:
zogt like table of zog,
wa_it_fldcat type lvc_s_fcat,
it_fldcat type lvc_t_fcat ,
dy_line type ref to data,
dy_table type ref to data.
data: dref type ref to data.
field-symbols: <fs> type any,
<dyn_table> type standard table,
<dyn_wa>.
*now I want to build a field catalog
*First get your data structure into a field symbol
create data dref type s_elements.
assign dref->* to <fs>.
lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( <fs> ).
zogt[] = lr_rtti_struc->components.
Now build the field catalog. zogt has the structure in it from RTTI.
loop at zogt into zog.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = zog-name .
wa_it_fldcat-datatype = zog-type_kind.
wa_it_fldcat-inttype = zog-type_kind.
wa_it_fldcat-intlen = zog-length.
wa_it_fldcat-decimals = zog-decimals.
wa_it_fldcat-coltext = zog-name.
wa_it_fldcat-lowercase = 'X'.
append wa_it_fldcat to it_fldcat .
endloop.
Let's create a dynamic table and populate it
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcat
importing
ep_table = dy_table.
assign dy_table->* to <dyn_table>.
create data dy_line like line of <dyn_table>.
assign dy_line->* to <dyn_wa>.
select vbeln posnr matnr kunnr werks vkorg vkbur
up to 200 rows
from vapma
into corresponding fields of table <dyn_table>.
from here you can pass your table to a GRID for display etc etc.
Cheers
JimboThanks for the info.
I went to their web site and also Googled.
I found a great review on their photographer's books on nikonians.org
They use an HP/Indigo Ultrastream 3000 digital offset press for all hardcover books, which is GREAT!
I did sign up and requested the 45 day trial "photographer" account.
I am curious if Shared Ink offers a size that matches the ONLY current book size from Aperture, the odd 8.5x11.
In the above review, I saw that Shared Ink offers a 12x12 book.. very nice! Except you will need to design that one in CS2
So then, all that Apple really needs to do is simply add the ability to select/create custom book sizes. Then we don't need a printing service from Apple, as there are plenty of options out there, and more arriving on the market each month! -
How to write a query for this output
I have a string ' if i know good acting , I am a hero '
now if 'hero' is present in the string it will return ' i am hero' else
'you are hero'
How to write a sql query to return the same .SQL> select (case
2 when '&a' like '%hero%' then 'I am hero'
3 ELSE 'u r hero'
4 end) output from dual;
Enter value for a: if i know good acting , I am a hero
old 2: when '&a' like '%hero%' then 'I am hero'
new 2: when 'if i know good acting , I am a hero ' like '%hero%' then 'I am hero'
OUTPUT
I am hero
SQL> /
Enter value for a: jkhkh
old 2: when '&a' like '%hero%' then 'I am hero'
new 2: when 'jkhkh' like '%hero%' then 'I am hero'
OUTPUT
u r hero
Hope this helps. -
How to use Start Routine for this requirement
Hello,
I am having data in 2 ods and should load that data into cube, but there isn't any common object in both the ods's. I need to analyze based on these ods objects. so I thought of pulling some objects into 1ods which are used for analysis and added some objects to ods and cube. Now I have to write a start routine in update rules to fetch the data from the info objects which are present in another ods. Can any one help me in this?
Rajesh.Hi Surya,
Extract all info from table BKPF
select * into it_bkpf
from bkpf
where gjahr = p_fisyr.
Select record based on internal table it_BKPF
The reason why FOR ALL ENTRIES syntax is used because of its cluster table.
select * into it_bseg
from bseg
for all entries in it_bkpf
where bukrs = it_bkpf-bukrs
and belnr = it_bkpf-belnr.
Delete duplicate record based on Company Code and GL No.
delete adjacent duplicates from it_bseg
comparing bukrs belnr. -
I have 2 tables
emp_master (emp_id, emp_name)
dept_master (dept_id, dept_name, emp_id (references emp_id in emp_master)Now there are 30 departments and each department can have maximum 5 employees.
Now I want a query that would list a department and all its employees in one line and if there are less than 5 employees it would show null for the rest of columns.
Dept_id emp_1 emp_2 emp_3 emp_4 emp_5
1 1 2 -- -- --
2 3 4 5 6 7
3 8 -- -- -- --
Please help me out
Thanks...One solution may be
Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
Connected as hr
SQL>
SQL> SELECT e.department_id, e.employee_id
2 FROM employees e
3 WHERE e.department_id IN (10, 20, 40, 60, 90)
4 /
DEPARTMENT_ID EMPLOYEE_ID
90 100
90 101
90 102
60 103
60 104
60 105
60 106
60 107
10 200
20 201
20 202
40 203
12 rows selected
SQL>
SQL> SELECT ee.department_id, ee.emp_1, ee.emp_2, ee.emp_3, ee.emp_4, ee.emp_5
2 FROM (SELECT MAX(CASE
3 WHEN MOD(r, 5) = 1 THEN
4 e.employee_id
5 ELSE
6 NULL
7 END) emp_1,
8 MAX(CASE
9 WHEN MOD(r, 5) = 2 THEN
10 e.employee_id
11 ELSE
12 NULL
13 END) emp_2,
14 MAX(CASE
15 WHEN MOD(r, 5) = 3 THEN
16 e.employee_id
17 ELSE
18 NULL
19 END) emp_3,
20 MAX(CASE
21 WHEN MOD(r, 5) = 4 THEN
22 e.employee_id
23 ELSE
24 NULL
25 END) emp_4,
26 MAX(CASE
27 WHEN MOD(r, 5) = 0 THEN
28 e.employee_id
29 ELSE
30 NULL
31 END) emp_5,
32 e.department_id
33 FROM (SELECT row_number() over(PARTITION BY department_id ORDER BY employee_id) r,
34 department_id,
35 employee_id
36 FROM employees
37 WHERE department_id IN (10, 20, 40, 60, 90)) e
38 GROUP BY e.department_id) ee
39 /
DEPARTMENT_ID EMP_1 EMP_2 EMP_3 EMP_4 EMP_5
10 200
20 201 202
40 203
60 103 104 105 106 107
90 100 101 102
SQL> Regards... -
How to write Dynamic SQL for this SQL ?
EXECUTE IMMEDIATE 'select COUNT(*) from dba_Tab_privs@' ||db_link|| ' WHERE Grantee <> 'DELETE_CATALOG_ROLE'
AND Table_Name = 'LINK$'
AND Grantee NOT IN (SELECT Grantee
FROM dba_Role_privs
WHERE Granted_Role = 'DBA')' into i using x;Hi bapalu,
I take that x is the name of your db_link?
If so,
DECLARE
i NUMBER;
x dba_db_links.db_link%TYPE;
stmt VARCHAR2(255);
BEGIN
x := 'some_link';
stmt :=
'SELECT count(*)
FROM dba_tab_privs@:db_link
WHERE grantee <> ''DELETE_CATALOG_ROLE''
AND table_name = ''LINK$''
AND grantee NOT IN(SELECT grantee
FROM dba_role_privs
WHERE granted_role = ''DBA'')';
EXECUTE IMMEDIATE REPLACE(stmt, ':db_link', x)
INTO i;
dbms_output.put_line('The count: ' || i);
END;Also, I think this is maybe not what you want:
AND table_name = ''LINK$''Regards
Peter
Maybe you are looking for
-
Performance problems loading an XML file into oracle database
Hello ODI Guru's, I am trying to load and XML file into the database after doing simple business validations. But the interface takes hours to complete. 1. The XML files are large in size >200 Mb. We have an XSD file for the schema definition instead
-
XML/AS3 Lightbox style gallery - need starting point....
I've made a gallery slideshow before but wasn't as intuitive looking back at it now and I want to start fresh on this new project. I would like to convert a jQuery lightbox style gallery into a flash XML based AS3 image gallery with categories. I don
-
Hi Sir, I have designed the SSIS Package in 2012 Version. and i have deployed into the Integration Server,using Project Deployment Model. In the SSIS Pacakge we are calling the batch file using Execute Process task. when i am Executing the SSIS pacak
-
I have a Mac OS X running Snow Leopard version 10.6.8. I have iPhoto '09 version 8.1.2. I have been having a problem the last two times I have imported photos to my iPhoto library from my camera. I edited a few photos, and it worked, but when I doubl
-
Need to extract data from a bricked hard drive - Failure ID ucx77t-69j7ms-mfpx1f-60vp03
Hi My laptop (HP Pavilion Sleekbook 14, purchased in October 2012) had gone slow recently, and finally its hard drive developed problems. At one point, it was so slow that it took a few minutes to sign off my user, so I shut it down manually while i