Dynamic table in select statement
Hi All,
I have a requirement where i have a select option in which the input is table name , i need to use this input in my select statement and fetch entries in the table where bname is eq to ' ' or uname eq ' '.
the challenge that i am facing is not all the tables have both the fields (uname and Bname).
Request your help on how to code the above requirements.
Thanks,
Bhanu.
Bhanu,
I don't know what exactly is your requirement but I don't see any reason why a business user enters a table name as input in the selection screen.
MANDT NAME TYPE NUMB SIGN OPTI LOW HIGH
223 ZPROGNAME P 0001 I EQ XXX ZTABLENAME
You can maintain an entry like the above in TVARVC table and get the table name using a select query on TVARVC and then use the table as below
SELECT SINGLE * FROM (l_tabname)
into g_wa_tab2
WHERE quosrc EQ g_wa_tab1-quosrc AND
quotyp EQ g_wa_tab1-quotyp AND
quotno EQ g_wa_tab1-quotno AND
quotdate EQ g_wa_tab1-quotdate.
Funda is using TAVRVC to maintain the table names and determine the table based on a condition and the using the table in the select query.
Thanks,
K.Kiran.
Similar Messages
-
FETCHING VALUES IN MULTI RECORD BLOCK FROM ANOTHER TABLE USING SELECT STATEMENT.
Hi,
I have one multi record block in which i want to fetch values
(more then one record) from another table using select statement
IN KEY NEXT ITEM.I am getting following error.
ORA-01422: exact fetch returns more than requested number of rows
Thanks in advance.In your case I see no reason to use non-database block and to try to populate it from a trigger with a query, instead of using the default forms functionality where you can associate the block and the fields with table, create where clause using bind variables and simply use execute_query() build-in to populate the block. The power of the forms is to use their build-in functionality to interact with the database.
Also, you can base your block on a query, not on a table and you dynamically change this query using set_block_property() build-in. You can use any dynamic queries (based on different data sources) and you simply need to control the column's data type, the number of the columns and their aliases. Something like creating inline views as a block data source.
However, you can replace the explicit cursor with implicit one like
go_block('non_db_block_name');
first_record();
FOR v_tab IN (SELECT *
FROM tab
WHERE col_name = :variable)
LOOP
:non_db_block_name.field1 := v_tab.col1;
:non_db_block_name.field2 := v_tab.col2;
next_record();
END LOOP; -
Using plsql tables in select statement of report query
Hi
Anyone have experience to use plsql table to select statement to create a report. In otherwords, How to run report using flat file (xx.txt) information like 10 records in flat files and use this 10 records to the report and run pdf files.
thanks in advance
sureshhi,
u can use the utl_file package to do that using a ref cursor query in the data model and u can have this code to read data from a flat file
declare
ur_file utl_file.file_type;
my_result varchar2(250);
begin
ur_file := UTL_FILE.FOPEN ('&directory', '&filename', 'r') ;
utl_file.get_line(ur_file, my_result);
dbms_output.put_line(my_result);
utl_file.fclose(ur_file);
end;
make sure u have an entry in ur init.ora saying that your
utl_file_dir = '\your directory where ur files reside'
cheers!
[email protected] -
Dynamic field in Select Statement
I am able to create a dynamic statement to insert into the where clause of my sql, but I am unable to dynamically create a select statement. Oracle Reports produces the following error:
REP-0499: Column " selected by the query is incompatible with report definition.
Here is an example of my select:
Select
&dynamic_field
from
any_table
Any help is appreciated.I figured it out. Thanks
-
Dynamic internal table from SELECT - statement ?
Hi, is it possible to define an internal table just after a select statement is executed so that this internal table holds all the data that come back from the statement ?
thanks in advance,Check the link -
Re: Create Dynamic internal table
Regards,
Amit -
Dynamic sql for select statement
Hi,
Please help me with the below code:
It is updating null if the select statment returns one values. If it fetches multiple values then it throughs the below error msg when running the program.
Please let me know how to modify the below code. Or let me know is there anyother way to write this code.
Logic for development:
* View name should be passed as dynamic.
CREATE OR REPLACE
PROCEDURE "PKEP_LOAD_SO_EU" (p_var1 IN VARCHAR2)
IS
lv_sql VARCHAR2 (4000);
lv_name VARCHAR2 (20);
BEGIN
lv_sql :=
' SELECT DISTINCT LEVEL2
FROM BIIO_SALES_OB_IMPORT_'|| p_var1;
EXECUTE IMMEDIATE lv_sql
INTO lv_name;
BEGIN
UPDATE BIIO_SALES_OB_IMPORT_NA2 --table name for updation
SET SOB_1 = NULL,
SOB_DATE_1 = NULL
WHERE level2 = lv_name; -- validation ( eg. Select distinct level2 from biio_sales_ob_import_'||p_var1)
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line (SQLERRM);
NULL;
END;
END;
BEGIN
PKEP_LOAD_SO_EU ('NA1');
end;
Error report:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "DEMANTRA.PKEP_LOAD_SO_EU", line 11
ORA-06512: at line 2
01422. 00000 - "exact fetch returns more than requested number of rows"
*Cause: The number specified in exact fetch is less than the rows returned.
*Action: Rewrite the query or change number of rows requested
Thanks.
PadmaPadu wrote:
Please let me know whether is anyother way to write this code as im a beginner for SQl.You dont need to have a seperate SELECT statement. Just a single UPDATE will do the job for you.
create or replace procedure pkep_load_so_eu
p_var1 in varchar2
as
begin
lSql := ' update biio_sales_ob_import_na2 ' ||
' set sob_1 = null ' ||
' , sob_date_1 = null ' ||
' where level2 in ( ' ||
' select level2 ' ||
' from biio_sales_ob_import_' || p_var1 ||
execute immediate lSql;
end; -
Specify database field's name dynamically in a select statement
Hi to all!!
I have the following problem:
I got a paraneters statement where the user is to choose the month of the year,once i have the month, i need to make a query on a database(select field_name) of a field whose name deppend on the month that the user chose before, is it possible?
What I need? I think i can do it using field simbols but I've never worked with field simbols and I have no time to learn it now.
Thanks everybodyHi,
<b>Below code is the Simple one:</b>
<b>DATA: DYN_FIELD(15)
SELECT single (DYN_FIELD)
into corresponding fields of <IT_TABLE>
from <TABLE> where XXX = YYY.</b>
This is the complex program, have a look at it ...
REPORT zdany_dynamic_select.
* We use some parameters to dynamically control the select, this is not very
* clever but this is just a test program !!
PARAMETER : p_tabnam TYPE tabname DEFAULT 'SFLIGHT',
p_selfl1 TYPE edpline DEFAULT 'CARRID',
p_selfl2 TYPE edpline DEFAULT 'CONNID',
p_selfl3 TYPE edpline DEFAULT 'FLDATE',
p_selfl4 TYPE edpline DEFAULT 'PRICE',
p_selfl5 TYPE edpline DEFAULT 'CURRENCY',
p_where1 TYPE edpline DEFAULT 'PRICE > 300',
p_where2 TYPE edpline DEFAULT 'AND CURRENCY = ''EUR'''.
FIELD-SYMBOLS : <lt_outtab> TYPE ANY TABLE,
<ls_outtab> TYPE ANY,
<l_fld> TYPE ANY.
DATA: lt_where TYPE TABLE OF edpline,
lt_sel_list TYPE TABLE OF edpline,
lt_group TYPE TABLE OF edpline,
l_having TYPE string,
l_wa_name TYPE string,
l_sel_list TYPE edpline,
dref TYPE REF TO data,
itab_type TYPE REF TO cl_abap_tabledescr,
struct_type TYPE REF TO cl_abap_structdescr,
elem_type TYPE REF TO cl_abap_elemdescr,
comp_tab TYPE cl_abap_structdescr=>component_table,
comp_fld TYPE cl_abap_structdescr=>component.
TYPES: f_count TYPE i.
* Creation of the output table including a non standard field, f_count
* see ABAP FAQ #14 for more information on this topic
struct_type ?= cl_abap_typedescr=>describe_by_name( p_tabnam ).
elem_type ?= cl_abap_elemdescr=>describe_by_name( 'F_COUNT' ).
comp_tab = struct_type->get_components( ).
* We remove the unnecessary fields
LOOP AT comp_tab INTO comp_fld.
IF comp_fld-name <> p_selfl1 AND
comp_fld-name <> p_selfl2 AND
comp_fld-name <> p_selfl3 AND
comp_fld-name <> p_selfl4 AND
comp_fld-name <> p_selfl5.
DELETE TABLE comp_tab WITH TABLE KEY name = comp_fld-name.
ENDIF.
ENDLOOP.
comp_fld-name = 'F_COUNT'.
comp_fld-type = elem_type.
APPEND comp_fld TO comp_tab.
struct_type = cl_abap_structdescr=>create( comp_tab ).
itab_type = cl_abap_tabledescr=>create( struct_type ).
l_wa_name = 'l_WA'.
CREATE DATA dref TYPE HANDLE itab_type.
ASSIGN dref->* TO <lt_outtab>.
CREATE DATA dref TYPE HANDLE struct_type.
ASSIGN dref->* TO <ls_outtab>.
* Creation of the selection fields and the "group by" clause
APPEND p_selfl1 TO lt_sel_list.
APPEND p_selfl1 TO lt_group.
APPEND p_selfl2 TO lt_sel_list.
APPEND p_selfl2 TO lt_group.
APPEND p_selfl3 TO lt_sel_list.
APPEND p_selfl3 TO lt_group.
APPEND p_selfl4 TO lt_sel_list.
APPEND p_selfl4 TO lt_group.
APPEND p_selfl5 TO lt_sel_list.
APPEND p_selfl5 TO lt_group.
APPEND 'COUNT(*) AS F_COUNT' TO lt_sel_list.
* creation of the "where" clause
APPEND p_where1 TO lt_where.
APPEND p_where2 TO lt_where.
* Creation of the "having" clause
l_having = 'count(*) >= 1'.
* THE dynamic select
SELECT (lt_sel_list)
FROM (p_tabnam)
INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>
WHERE (lt_where)
GROUP BY (lt_group)
HAVING (l_having)
ORDER BY (lt_group).
* display of the results
LOOP AT <lt_outtab> ASSIGNING <ls_outtab>.
LOOP AT comp_tab INTO comp_fld.
ASSIGN COMPONENT comp_fld-name OF STRUCTURE <ls_outtab> TO <l_fld>.
WRITE: <l_fld>.
ENDLOOP.
SKIP.
ENDLOOP.
Have a look at the link, this link will have lot of examples :-
http://www.susanto.id.au/papers/DynOpenSQL.asp
Regards
Sudheer -
Dynamic fields in select statement
Hi all,
In selection screen we are having period as select option.The values for period are 01 to 16. Based on
the values entered in selection screen for period we need to select HSLXX from FAGLFLEXT.
For example if we enter 01 to 03 in selection screen then we need to select HSL01 HSL02 HSL03
from FAGLFLEXT.
Like this we need to select fields dynamically in select statement. Can any one tell me how to restrict fields dynamically.
Regards,
Swethahi Swetha,
the third select statemnet will work for you..
try this..
_Dynamic where clause in select query.._
* With a variable, result: AND rbusa = '5145'
concatenate 'AND rbusa = ' '''' i_tab-zgsber ''''
append where_clause to where_tab.
* Select
select * from zcostfreq
where (where_tab).
endselect.
_Using a dynamic table name_
parameters:
p_tab type tabname.
start-of-selection.
select count(*) from (p_tab) into l_count.
_Dynamic retrieval and writing of data_
FIELD-SYMBOLS:
<row> TYPE ANY,
<component> TYPE ANY.
PARAMETERS:
p_tab TYPE tabname.
CREATE DATA dataref TYPE (p_tab).
* The variable dataref cannot be accessed directly, so a field symbol is
* used
ASSIGN dataref->* TO <row>.
SELECT *
FROM (p_tab) UP TO 10 ROWS
INTO <row>.
NEW-LINE.
DO.
* Write all the fields in the record
ASSIGN COMPONENT sy-index
OF STRUCTURE <row>
TO <component>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
WRITE <component>.
ENDDO.
ENDSELECT.
Regards,
Prabhduas -
Dynamic Parameter LOV Select Statement
I have a parameter form with a value for the fiscal year and equipment ID. I want to populate the equipment ID list of values based on the fiscal year that is selected.
My query for the equipment ID list of values would be SELECT EQPID,NAME FROM EQPLIST WHERE FY = :FY.
When I tried to add this query to the list of values of the equipment ID parameter I get REP-0781: Bind variables are not allowed in the Select statement.
Is there a way to dynamically generate the list of values select statement in a reports trigger?Hi,
What version of Oracle Reports are you using?
Unfortunately, it is a limitation of Oracle Reports to not restrict values based on other parameters - for sure until Reports 6i and I believe until the recent new versions.
The other way to do what you want to do is to do it outside of Reports, if you have an Oracle Forms application. For example, you can create a simple Oracle Form that captures the Report parameters and then submits the report from the Forms. In Forms, you can implement the solution you are looking for - restricting values based on values of other parameters. In reports, you can't do that.
If you have a few other reports that have similar requirements, then you can create a form to launch reports and submit all your reports from there after capturing all your parameters there.
Venkat -
Performance problem(ANEA/ANEP table) in Select statement
Hi
I am using below select statement to fetch data.
Does the below where statement have performance issue?
can you Pls suggest.
1)In select of ANEP table, i am not using all the Key field in where condition. will it have performance problem?
2)does the order of where condition should be same as in table, if any one field order change also will have effect performance
SELECT bukrs
anln1
anln2
afabe
gjahr
peraf
lnran
bzdat
bwasl
belnr
buzei
anbtr
lnsan
FROM anep
INTO TABLE o_anep
FOR ALL ENTRIES IN i_anla
WHERE bukrs = i_anla-bukrs
AND anln1 = i_anla-anln1
AND anln2 = i_anla-anln2
AND afabe IN s_afabe
AND bzdat =< p_date
AND bwasl IN s_bwasl.
SELECT bukrs
anln1
anln2
gjahr
lnran
afabe
aufwv
nafal
safal
aafal
erlbt
aufwl
nafav
aafav
invzv
invzl
FROM anea
INTO TABLE o_anea
FOR ALL ENTRIES IN o_anep
WHERE bukrs = o_anep-bukrs
AND anln1 = o_anep-anln1
AND anln2 = o_anep-anln2
AND gjahr = o_anep-gjahr
AND lnran = o_anep-lnran
AND afabe = o_anep-afabe.
Moderator message: Please Read before Posting in the Performance and Tuning Forum
Edited by: Thomas Zloch on Aug 9, 2011 9:37 AM1. Yes. If you have only a few primary keys in youe WHERE condition that does affect the performance. But some times requirement itself may be in that way. We may not be knowing all the primary keys to given them in WHER conditon. If you know the values, then provide them without fail.
2. Yes. It's better to always follow the sequence in WHERE condition and even in the fields being fetched.
One important point is, whenever you use FOR ALL ENTRIES IN, please make sure that the itab IS NOT INITIAL i.e. the itab must have been filled in. So, place the same conditin before both the SELECT queries like:
IF i_anla[] IS NOT INITIAL.
SELECT bukrs
anln1
anln2
afabe
gjahr
peraf
lnran
bzdat
bwasl
belnr
buzei
anbtr
lnsan
FROM anep
INTO TABLE o_anep
FOR ALL ENTRIES IN i_anla
WHERE bukrs = i_anla-bukrs
AND anln1 = i_anla-anln1
AND anln2 = i_anla-anln2
AND afabe IN s_afabe
AND bzdat =< p_date
AND bwasl IN s_bwasl.
ENDIF.
IF o_anep[] IS NOT INITIAL.
SELECT bukrs
anln1
anln2
gjahr
lnran
afabe
aufwv
nafal
safal
aafal
erlbt
aufwl
nafav
aafav
invzv
invzl
FROM anea
INTO TABLE o_anea
FOR ALL ENTRIES IN o_anep
WHERE bukrs = o_anep-bukrs
AND anln1 = o_anep-anln1
AND anln2 = o_anep-anln2
AND gjahr = o_anep-gjahr
AND lnran = o_anep-lnran
AND afabe = o_anep-afabe.
ENDIF. -
Using Nested Table in Select Statement
Hi all ,
Can i use the PL/SQL nested table or Varray
in the select statement as a normal table joined with other database tables.
i.e.
I have a nested table NT_1 in PL/SQL proc
i have to use this NT_1 in the select statement as
select xxx from
tab_1,
tab_2,
NT_1
where
< some conditional joins >.
Please help me in this regard.
regds
Dhananjaya.Hyou can not use a varray as part of a SQL Statement in order to build joins.
Can you explain better what do you want to do ?
Joel P�rez -
Create table as select statement.
Hello Oracle Gurus,
I am trying to create a table using select * from other table.
The procedure that I am following is this:-
I have a temp table whose signature is on commit delete rows.
I insert records in this table.
when I do select * from temp_table,perm_table I get some rows.
then I try to create a result_table using this
CREATE TABLE result_table
AS SELECT * FROM temp_table,perm_table;
I see the table in created but number of records in 0. Can anyone please explain where commit takes place while sequence in this query occurs.
Thanks
Edited by: user10696492 on Nov 10, 2009 8:47 AMCreate table statement is a ddl - so an implicit commit is performed before the create statement begins. The implicit commit will delete all the rows from the temp table. If it is feasible change the definition of the temp table to on commit preserve rows.
-
How imrove the peformance of VBFA table in select statements.
Hi,
whenever execute program in production, program execution will taking long time due to below select statement.
Please help me how we imrove performance?
SELECT vbelv vbeln posnn vbtyp_v
FROM vbfa
INTO TABLE l_i_vbfa
FOR ALL ENTRIES IN l_i_bill_cs
WHERE vbeln EQ l_i_bill_cs-vbeln
AND posnn EQ '000010'
AND vbtyp_n IN ('K', 'H'). "MOD-024--
AND vbtyp_v IN ('K', 'H'). "MOD-024++
SORT l_i_vbfa BY vbeln vbtyp_n.
Regards,
Naidu
Moderator message: third time I have to remind you: for performance problems with VBFA table please search for previous discussions of the same topic
Edited by: Thomas Zloch on Nov 9, 2010 12:41 PMHi Naidu,
ranges: r_vbtypv type vbfa-r_vbtyp_v.
CLEAR r_vbtypv.
r_vbtypv-option = 'EQ'.
r_vbtypv-sign = 'I'.
r_vbtypv-low = 'K'.
APPEND r_vbtypv.
CLEAR r_vbtypv.
r_vbtypvl-option = 'EQ'.
r_vbtypv-sign = 'I'.
r_vbtypv-low = 'H'.
APPEND r_vbtypv.
sort l_i_bill_cs by vbenl.
if not l_i_bill_cs[] is initial.
SELECT vbelv vbeln posnn vbtyp_v
FROM vbfa
INTO TABLE l_i_vbfa
FOR ALL ENTRIES IN l_i_bill_cs
WHERE vbeln EQ l_i_bill_cs-vbeln
AND posnn EQ '000010'
AND vbtyp_v IN r_anlkl.
endif.
SORT l_i_vbfa BY vbeln vbtyp_n.
Thanks,
Nelson -
Picking the right values from tables - SQL (select statement)
Hi everyone,
I'm facing the litlle(?) problem in Oracle environment.
Let me explain:
I have two tables.
TABLE 1
Id1 | Val1 | Id2 | Val2
A | 44 | B | 36
B | 36 | A | 44
TABLE 2
Id | Name
A | New York
B | Seattle
I need to get from those tables, using SQL statement, result like this:
Id1 | Val1 | Name1 | Id2 | Val2 | Name2
A | 44 | New York | B | 36 | Seattle
NOTE !! Very important!! If in table 1 we have crossed the same values in fields IdX and ValX in two rows (like in example)- just one of them should be presented as a result.
I'm afraid it's a bit too complex. You, guys are my last hope.
Looking forward for any solutions.
Thanks in advance!jeneesh wrote:
This can give you a startJaneesh, the OP specified that the duplication was across the ID and the VAL columns, but your solution only checks the ID's..
SQL> ed
Wrote file afiedt.buf
1 with t1 as (select 'A' as id1, 44 as val1, 'A' as id2, 36 as val2 from dual union all
2 select 'A', 36, 'A', 36 from dual)
3 ,t2 as (select 'A' as id, 'New York' as name from dual union all
4 select 'B', 'Seattle' from dual)
5 -- END OF TEST DATA
6 select distinct greatest(id1,id2) id1,
7 case when id1 > id2 then val1 else val2 end val1,a.name name1,
8 least(id1,id2) id2,
9 case when id1 < id2 then val1 else val2 end val2,b.name name2
10 from t1 t,t2 a,t2 b
11 where greatest(id1,id2) = a.id
12* and least(id1,id2) = b.id
SQL> /
I VAL1 NAME1 I VAL2 NAME2
A 36 New York A 36 New York
SQL>With this data I would have expected both rows to be returned as there is a difference in the val columns..
SQL> ed
Wrote file afiedt.buf
1 with t1 as (select 'A' as id1, 44 as val1, 'A' as id2, 36 as val2 from dual union all
2 select 'A', 36, 'A', 36 from dual)
3 ,t2 as (select 'A' as id, 'New York' as name from dual union all
4 select 'B', 'Seattle' from dual)
5 -- END OF TEST DATA
6 ,t3 as (select distinct id1, val1, id2, val2
7 from
8 (
9 select decode(switch,1,id2,id1) as id1
10 ,decode(switch,1,val2,val1) as val1
11 ,decode(switch,1,id1,id2) as id2
12 ,decode(switch,1,val1,val2) as val2
13 from (select id1, val1, id2, val2
14 ,case when id1||val1 > id2||val2 then 1 else 0 end as switch
15 from t1)
16 )
17 )
18 --
19 select t3.id1, t3.val1, t2_1.name
20 ,t3.id2, t3.val2, t2_2.name
21 from t3 join t2 t2_1 on (t2_1.id = t3.id1)
22* join t2 t2_2 on (t2_2.id = t3.id2)
SQL> /
I VAL1 NAME I VAL2 NAME
A 36 New York A 36 New York
A 36 New York A 44 New York -
Problem in creaing the logical tables by SELECT statement
Hi,
I have created logical tables in the physical layer of the OBIEE tool by "select statement". Connection Pool is set up properly for the repository. Rows of the tables are updating properly by clicking to the "Update Row Count" but when I am clicking to the "View Data" it shows the following error
[nQSError:17001] Oracle Error code:936, message: ORA-00936:missing expression at OCI call OCIStmtExecute.
[nQSError:17010]SQL statement preparation failed.
Also for some tables data is coming properly by clicking to the "View Data" .
I'm stack in this point and cannot move forward. Please, help me guys.
Thanks
SandeepHi
I also face same type of error. Just do one thing Change the call interface OCI 10g to ODBC 3.5 and on Feature tab click revert to default.
I think that will work properly.
Best of Luck
Thanks
SIddhartha P
Maybe you are looking for
-
Why can't i print my calendar i use in iCLOUD from a PC
Why can't i print my calendar i use in iCLOUD from a PC
-
Runtime Error when trying to "Send for Review"
Runtime error on Contribute.exe This application has reqeusted the Runtime to terminate it in an unusual way..... User had just finished editing, clicked "Send", selected "Send for Review", then selected a person's name in the list to send it to....
-
Stepwise details to implement/correct the BADI - WORKORDER_GOODSMVT
Hi gurus, Please tell me the step by step procedure to implement the above badi for goods issue(back flush of proportionate (Batch split with partial componentavailability) quantity of components for partial order confirmation during CO11N).Also plea
-
Bonjour... where did it go?
Recently purchased the Airport Extreme wireless router. When I went to set up my USB printer, the directions said to enable Bonjour. For some reason, i can't locate Bonjour on my system, even after searching in Finder. Where did it go, and if it's go
-
Image flattening problem in CS 4
I am loosing details in an image when I try to save, flatten or merge visible. The top layer is a colored layer that I have used the dissolve blend mode to apply to the layer below. Whenever I flatten it, I loose a lot of the granular detail as wel