Using a variable instead of a table reference
I have a table that contains a dblink name. I would like to have a procedure that reads the link into a variable and uses that link in select statements.
So far, I cannot get this to work. Any ideas?
Jamie, you would use dynamic SQL (either EXECUTE IMMEDIATE or DBMS_SQL) to handle any situation where you have to dynamically swap out table or column names in a statement. Here are a couple of examples using native dynamic SQL (NDS):
open x for 'select * from t@' || p_dblink || ' where ...';
execute immediate 'select name from t@' || p_dblink || ' where ...' into v_name;
Similar Messages
-
How can i pass a variable instead of a table name in the Select statement.
Dear all
how can i pass a variable instead of a table name in a select statement ?
Example :-
Begin
P_get_procedure_tname (aap_name,otable_name);--It will take an application name and will return a table name
Select col1 into ocol1
from ---- here i want to pass the variable OTABLE_NAME
End;How can i pass this ?Hi,
You can use dynamic sql.
EXECUTE IMMEDIATE 'SELECT COL1 INTO ' || OCOL1 || ' FROM " || OTABLE_NAME;
{code}
cheers
VT -
Can i use a variable instead of a fixed TextField?
Hello
I have to set the readOnly property to some set of fileds DYNAMICALLY (i mean, until run time, i dont know Which fields are readOnly and which are not? based on TYPE (Manager, Officer, Clerk....) of user...i hv to set it .
So, i want to replace the TextField1 dynamically with all the fileds in the below syntax. So, can i put some variable in the position of TextField1? if so, How can i do that?
xfa.resolveNode("VISITOR.Page3.SubFrom1.TextField1").access = "readOnly";
xfa.resolveNode("VISITOR.Page3.SubFrom1.MyVariableComesHere").access = "readOnly";
In ABAP, it looks lik below,
LOOP AT it_readOnly_fields_itab INTO wa_readOnly_fields_itab.
xfa.resolveNode("VISITOR.Page3.SubFrom1.wa_readOnly_fields_itab-FieldID").access = "readOnly";
ENDLOOP.
Pls. let me know the EQUILANT code (of above ABAP 3 lines code) in Java Script
How can i put the variable in the red position?
THank youSorry, am not looking that!!
Say, i have 5 fields, then, i want to make them readOnly, then i hv to write as below,
xfa.resolveNode("VISITOR.Page3.SubFrom1.TextField1").access = "readOnly";
xfa.resolveNode("VISITOR.Page3.SubFrom1.TextField2").access = "readOnly";
xfa.resolveNode("VISITOR.Page3.SubFrom1.TextField3").access = "readOnly";
xfa.resolveNode("VISITOR.Page3.SubFrom1.TextField4").access = "readOnly";
xfa.resolveNode("VISITOR.Page3.SubFrom1.TextField5").access = "readOnly";
Actually, my requirement is differnent (I know at run time only...that Wht wht fields i hv to set readOnly and wht wht fields should okay for input enable), for that reason i want to use a VARIABLE in the 'position' of TextField1, TextField2.....like bleow
var myVariable
myVariable = TextField1
LOOPing the ARRAY
xfa.resolveNode("VISITOR.Page3.SubFrom1.myVariable").access = "readOnly";
PLs. let me know Can i sue a variable like that? if so, what is the correct syntax (pls. suggest me a SYNTAX error free code, bcz am very very beginner to this)
THank you -
Using File Server instead of FND_LOBS table
Dear Experts
Hi,
we use R12.1 with UP-UX Itanium.
the approach of our company about Attachments in organization mades FND_LOBS table so big.
I couldn't change this approach to attach many file in ERP so I searched in google and metalink how can we reduce FND_LOBS size
but there is no useful information to do this
it seems that this problem is Unavoidable.
So I want to know if there is a way to using FILE SERVER in ebs 12.1.1 or any useful plan to reduce FND_LOBS size or its effects?
Thanks
Best RegardsI couldn't change this approach to attach many file in ERP so I searched in google and metalink how can we reduce FND_LOBS size
This topic was covered many times in the forum before, please see previous threads for the MOS Docs you need to follow.
https://community.oracle.com/search.jspa?view=content&resultTypes=&dateRange=all&q=Purge+AND+FND_LOB
https://community.oracle.com/search.jspa?view=content&resultTypes=&dateRange=all&q=Size++AND+FND_LOBS
Thanks,
Hussein -
I want to use static variable instead of using variable in servlet context
Hi all,
In my web application i have to generate a unique Id.
For this, At the application startup time i am connecting to the database and getting the Id and placing it in the servlet context.
Every time i am incrementing this id to generate a unique id.
But, now i want to place this id in a static variable which is available to all the classes.
why i want to do this is to reduce burden on servlet context.
my questing is, is this a best practice ? If not please give me your valuable suggestion.
thanks
tiruThere isn't a problem with this as long as you want to share the value of that variable with all requests. If this is read-only except when it is first set then you're fine. The only real issue will be how to initialize and/or reinitialize the variable. When the servlet is started, how will you get the value for the variable? If the servlet is shutdown and restarted (a possibility in any application server) how will you re-read the variable? You need to answer these questions to decide the best route. It may be as simple as a static initializer or it may be more complex like a synchronized method that is called to see if the variable is set.
-
Use of variable to generate a report
Hi,
Can anyone help!
I've created a selection list with submit, which displays a list of applications, the return value is the name of the remote database table which holds exceptions associated to the chosen application. This is in a html region called Database Selection and the return is P4_APPLICATIONS (e.g. aps_monitor_excp_codes@eds.
I then have a report in a region called Exceptions which must used the supplied database name in the from. Here is the source, when I change the table variable back to a literal it works so the problem must be with how or where I'm using the variable.
declare
v_return varchar2(4000);
begin
v_return := 'Select SortOrder, ExceptionSequence, DateStamp, Priority, ProcessID, ExceptionCode, ShortMsg, FullDesc, ProcessName, ExceptionObject, ErrorDetails, Action, apex_item.checkbox(1,Acknowledged, decode(Acknowledged,''Y'',''CHECKED'',Null)) Acknowledged
from (SELECT upper(nvl(a.exception_acknowledged_yn,''N'')) SortOrder,
a.exception_sequence_number ExceptionSequence,
a.exception_timestamp DateStamp,
decode(b.priority, ''A'', ''HIGH'', ''B'', ''MEDIUM'', ''C'', ''LOW'', ''D'', ''INFO'', ''UNKNOWN'') Priority,
a.unix_pid ProcessID,
a.exception_code ExceptionCode,
htf.escape_sc(b.short_exception_message) ShortMsg,
htf.escape_sc(b.full_description) FullDesc,
a.process_name ProcessName,
a.exception_object ExceptionObject,
htf.escape_sc(a.exception_detail) ErrorDetails,
htf.escape_sc(b.action) Action,
upper(nvl(a.exception_acknowledged_yn,''N'')) Acknowledged
FROM :P4_APPLICATIONS a, monitor_excp_codes@eds b
WHERE a.exception_code = b.exception_code (+))
order by 1, 2 desc';
return v_return;
end;
Any help would be appreciated, if I have to ask my colleagues I'll get a blonde joke!
Thanks
BecksYou can't use bind variables in place of table names in SQL. Change it to:
...FROM ' || :P4_APPLICATIONS || 'a ...
Scott -
Using a variable for STS Planning Sequence
Hi guys,
I would like to execute planning sequence when users approves data for Profit Center in STS. The filter used in the planning sequence have a variable for Profit Center. This is not working.
Whats the altenative of using a variable Instead of creating planning sequence for every profit center? Pls assistThe planning sequence runs when the user approves on STS. The planning sequence runs for all profit center (this is a variable in the filter). I want to execute planning sequence for the profit center level selected on STS.
-
Oracle 10g - can I use a variable to identifywhat user's tablesto access?
I have the following code in a trigger (PL/Sql block) of a form:
select fieldname into myvar from user1.sometable;
is there a way to use a variable instead of hard coding 'user1'? And on the same topic, could this variable be declared globally?
Thanks in advance,
DarrenHi again!
i've forgot something!
You are able to switch to another schema. If you are another user than user1, try:
alter session set current_schema = user1;after this there is no need to use synonyms or tableowners in front of the tablename in your sql-statements.
May you use this in a when-new-form-instance trigger in your first form like:
forms_ddl ( 'alter session set current_schema = ' || :parameter.your_schema );Regards -
Use a variable as a table name with NATIVE SQL
Hi all,
I am trying to execute a SELECT statement in order to fetch data from an external Oracle DB table to SAP with the following instructions:
EXEC SQL.
SELECT cityfrom, cityto
INTO STRUCTURE :wa
FROM spfli
WHERE mandt = :sy-mandt AND
carrid = :p_carrid AND connid = :p_connid
ENDEXEC.
However, I need to indicate the external table name from a variable instead of the solution above. That is, declaring a variable and store the name of the table (e.q. spfli) in it. The resulting ABAP code would be something like:
EXEC SQL.
SELECT cityfrom, cityto
INTO STRUCTURE :wa
FROM <VARIABLE>
WHERE mandt = :sy-mandt AND
carrid = :p_carrid AND connid = :p_connid
ENDEXEC.
Does anybody know if is possible to do that?
If not, is there any other solution?
Thank you in advanceYes, as Suhas said, you could use the ADBC API and his class CL_SQL_CONNECTION to achieve this...
Here is a small example:
PARAMETERS: p_carrid TYPE spfli-carrid,
p_connid TYPE spfli-connid.
DATA:
l_con_ref TYPE REF TO cl_sql_connection,
l_stmt TYPE string,
l_stmt_ref TYPE REF TO cl_sql_statement,
l_dref TYPE REF TO data,
l_res_ref TYPE REF TO cl_sql_result_set,
l_col1 TYPE spfli-carrid,
l_col2 TYPE spfli-connid,
l_wa TYPE spfli.
CONSTANTS:
c_tabname TYPE string VALUE 'SPFLI'.
* Create the connecction object
CREATE OBJECT l_con_ref.
* Create the SQL statement object
CONCATENATE 'select * from' c_tabname 'where carrid = ? and connid = ?'
INTO l_stmt SEPARATED BY space. "#EC NOTEXT
l_stmt_ref = l_con_ref->create_statement( ).
* Bind input variables
GET REFERENCE OF l_col1 INTO l_dref.
l_stmt_ref->set_param( l_dref ).
GET REFERENCE OF l_col2 INTO l_dref.
l_stmt_ref->set_param( l_dref ).
* Set the input value and execute the query
l_col1 = p_carrid.
l_col2 = p_connid.
l_res_ref = l_stmt_ref->execute_query( l_stmt ).
* Set output structure
GET REFERENCE OF l_wa INTO l_dref.
l_res_ref->set_param_struct( l_dref ).
* Show result
WHILE l_res_ref->next( ) > 0.
WRITE: / 'Result:', l_wa-carrid, l_wa-connid.
ENDWHILE.
* Close the result set object
l_res_ref->close( ).
Otherwise you can also use the FM DB_EXECUTE_SQL...
Kr,
m. -
How to use variable in :old. variable instead of :old.column name.
My requirement is to update the audit_update table with the old value and new value when an update statement gets executed. If i use :old.columnname the purpose is getting resolved.
My requirement is to loop through the columns taken dynamically and update the audit_update_details table. The updation is taking place in a function that called.
The first cursor holds the column name of a given table.
I have to use a statement like :old.variablename . where the variable holds the column name .
Is their an alternative?
CREATE OR REPLACE TRIGGER INSERT_EMP1
AFTER INSERT OR UPDATE OR DELETE
ON EMP FOR EACH ROW
declare
v_seq number(5);
v_result boolean;
v_col_name varchar2(20);
CURSOR FIRSTCURSOR IS
select COLUMN_NAME from user_tab_columns where table_name like 'EMP';
begin
if inserting then
INSERT INTO aud_details VALUES(seq_aud_log_id.nextval,'Emp','I','eno',:NEW.ENO);
end if;
if DELETING then
INSERT INTO aud_details VALUES(seq_aud_log_id.nextval,'Emp','D','eno',:OLD.ENO);
end if;
IF UPDATING THEN
INSERT INTO aud_details VALUES(seq_aud_log_id.nextval,'Emp','U','eno',:OLD.ENO);
select seq_aud_log_id.currval into v_seq from dual;
open FIRSTCURSOR;
LOOP
FETCH FIRSTCURSOR INTO v_col_name;
EXIT WHEN FIRSTCURSOR%NOTFOUND;
BEGIN
-- How to make the code to work successfully.
if (:old.v_col_name != :new.v_col_name) then
v_result := insert_fn('emp',:old.eno, v_col_name , :old.v_col_name, :new.v_col_name, v_seq );
end if;
end;
end loop;
THe below is an example that uses the column name .Instead of column name i need to use the variable. So that the trigger functions for any given table.
/* IF (:old.ename != :new.ename) THEN
v_result := insert_fn('emp',:old.eno, 'ename' , :old.ename, :new.ename, v_seq );
END IF;
IF (:old.dno != :new.dno) THEN
v_result := insert_fn('emp',:old.eno, 'dno' , :old.dno, :new.dno,v_seq );
END IF;
IF (:old.salary != :new.salary) THEN
v_result := insert_fn('emp',:old.eno, 'salary' , :old.salary, :new.salary, v_seq );
END IF;
END IF;
END INSERT_EMP1;
thanks,
vinodhAs Solomon said, it's not possible, but you could write a procedure that would generate the code to do it for each individual column. You could then execute the code generator procedure any time the tables DDL changed in order to update the triggers code.
-
How to use a table name in the select statement using a variable?
Hi Everybody,
I got a internal table which has a field or a variable that gets me some tables names. Now I need to retrieve the data from all these tables in that field dynamically at runtime. So could you suggest me a way out to use the select query which uses this variable as a table ?
Regards,
Mallik.Hi all,
Actually i need some more clarification. How to use the same select statement, if i've to use the tabname in the where clause too?
for ex : select * from (tab_name) where....?
Can we do inner join on such select statements? If so how?
Thanks & Regards,
Mallik. -
How can I reference a winforms control using a variable in Powershell?
I have a powershell winform that has a lot of text boxes, but for the sake of this post, lets say I have 5. I want to loop through the 5 text boxes to see if their text property is empty. If the textbox contains something, I want to add the text value to
an array. Here's an example of what I'm trying to do.
textbox1.text = "Red"
textbox2.text = ""
textbox3.text = "Blue"
textbox4.text = ""
textbox5.text = ""
$MyArray = @()
for ($i = 1; $i -le 5; $i++) {
If ($textbox[$i].text -ne "") {
$MyArray += $textbox[$i].text
I realize the textbox object is not an array so this code will not work. I guess the simple question is, How can I reference a set of static controls using a variable without having to do something like this
[object[]]$textboxes = New-Object System.Windows.Forms.TextBox
For ($i = 1; $i -lt 5; $i++) {
$textboxes += New-Object windows.forms.textbox
$textboxes[$i].DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
$textboxes[$i].Name = $textboxes[$i]
$BoxItems.Controls.Add($textboxes[$i])Hi D-Dub,
here are two ways to retrieve the text value of $Textbox1:
$Textbox1.Text
(Get-Variable "Textbox1").Value.Text
Now what could you do with the second way, inside a loop, I wonder ... ;)
Cheers,
Fred
There's no place like 127.0.0.1 -
Select tables filed name by using global variables
Hi
I try to redesign a BODI jobs for monthly statistics. At the moment, I have a job for every month because in the source system (MS Axapta) the source table have the following design:
YEAR JAN FEB MARCH ...
2010 100 231 233
So, if I load the data for the January, I will load only this filed from the table:
select YEAR, JAN from STATISTICS
For the February, I will load only this filed:
select YEAR, FEB from STATISTICS
otherwise, I have a lot of dublicated BODI Jobs and a lot of work for maintenance.
In this case, I try to use a variable in the mapping field in a Query transform, but doesn't working. Also in the SQL transform, but I was not able to do that.
I know, that I can solve that with a Pivot-Transform, but I have to load some millions of data and I have no time to wait until the Pivot is finish.
Do anybody have a other idee to solve my problem?
Many thanks
ChristophThanks for your answer.
How can I do that in the SQL Transform?
If I try the with the following SQL Code, I become a ORA-00911 Error Message:
SELECT Year, $Periode from STATISTIK
Any idea
Thanks
Christoph -
Help with using variable for name of table in PLSQL block...
I am trying to use a variable for the name of a table but getting errors ...i am sure I am close to the correct form here but something is wrong. I sure would appreciate some help!
DECLARE
ln_month Number;
ln_day Number;
ln_year Number;
ls_year VarChar2(4);
ls_prev_table VarChar2(30);
ls_cur_table VarChar2(30);
ln_prev_year Number;
ls_prev_year VarChar2(4);
ln_prev_month Number;
BEGIN
Select To_Number(To_Char(sysdate, 'MM')) into ln_month from dual;
Select To_Number(To_Char(sysdate, 'DD')) into ln_day from dual;
Select To_Number(To_Char(sysdate, 'YYYY')) into ln_year from dual;
If ln_month = 01 Then
ls_cur_table := "T_CPRS_FDW_CUR_JAN_ACTUALS";
ls_prev_table := "T_CPRS_FDW_PREV_DEC_ACTUALS";
ln_prev_year := ln_year - 1;
/***above is where I am trying to use variables for assignement to years and months tables***//// ln_prev_month := 12;
End If;
/*------MORE IF STATEMENTS FOR EACH MONTH ---OF --THE YEAR ...AND its the following 2 variable statements that the compiler doesnt like! */
If ln_day < 20 Then
Delete from :ls_prev_table;
INSERT INTO :ls_prev_table /*(STUFF TO BE INSERTED GOES HERE)*/
HELP PLEASE!
nullHi,
The parser does not under variables directly in dml statements.u need to form a statement and the parse and execute the same...
so the soln is
Declare
lv_stmt varchar2(250);
Begin
lv_stmt := 'Delete from '| |ls_prev_table;
execute immediate lv_stmt;
-- Same is the case with the insert stmt--
End;
This should solve ur problem.
u could also give a direct call like
execute immediate 'Delete from '| |ls_prev_table ;
Note: This statement "execute immediate" holds good for oracle versions 8.x and above which makes the stmt very simple. For lower version u need to use the dbms_sql package to parse and execute the statement which has a series of statements for the same.
Kiran -
When / why use XML to store data instead of database table ?
Hi All,
I still not use XML much in applications and don't know much about its utilization.
I read here and there about storing data as XML instead of into database tables.
- could any body please tell me when / why use XML to store data instead of database table ?
e.g : store inventory per warehouse in XML format. ?
- What is the other cases or reasons of extracting database records into XML or vice versa ?
- is there any good pdf on this ?
Thank you for your help,
xtantoIt depends entirely what you want to accomplish with the 'XML in the database'. There are basically 3 independent methods: As CLOB, as XMLType views or as native XMLType 'columns'
Each method has advantages and disadvantages, especially in the performance vs purpose tradeoff.
The Oracled Press book "Oracle Database 10g XML & SQL Design, Build, & Manage XML Applications in Java, C, C++, & PL/SQL" is highly recommended for anyone interested in Oracle and XML. http://books.mcgraw-hill.com/getbook.php?isbn=0072229527&template=oraclepress
Maybe you are looking for
-
Itunes 12 crashing on Windows 7 PC
I've tried all the steps in the troubleshooting section for this problem, as well as uninstalling and reinstalling itunes numerous times to no avail. It will randomly crash and shut down anytime I'm trying to use it.
-
Forcing Reader 9 to be the default (GPO Deployment)?
I have a company environment with several hundred PCs running XP and Vista with some Windows 7. Most to all will have some form of Acrobat Reader installed, most likely 7 or 8 with some of the newer machines having 9. Some will have full Acrobat Stan
-
Validation on selection screen parameter.
I have select options in my selection screen. 1) s_a 2) s_b Requirement:- 1) If I run the program and click the arrow on the "s_a" field, it should open multi selection screen. From that I can make multi entry or upload data from excel file. 2) If "s
-
How to set dimension level security with multiple levels
Hi, We have hierarchy with Level 0 codes to Level 4 codes. For e.g. Region 1 : Level 0 code 10000, Level 1 code 10001, Level 2 code 10011, Level 3 code 10111, Level 4 code 11111 Region 2: Level 0 code 20000, Level 1 code 20001, Level 2 code 20011, Le
-
Ora-01756: quoted string not properly terminated
Hi all, I have just practise Oracle REF obj_type. My codes are follows: CREATE or REPLACE TYPE home_type AS OBJECT ( street VARCHAR2(50), city VARCHAR2(20), state VARCHAR2(20), zipcode VARCHAR2(6), owner VARCHAR2(10) CREATE TABLE homes OF home_type;