Using variables in sql session
HI
i want to use lv_file value to spool the file how can i use it
set define off
set serveroutput on size 100000;
variable lv_file varchar2(200)
begin
:lv_file := 'amt_test_config'||to_char(sysdate,'HH24:MI:SS')||'.err';
end;
prompt &&lv_file
spool &&lv_file
thanx
kb
one workaround could be something like this:
I changed the date format because windows doesn't accept colon in file name.
SQL> undefine file_nm
SQL> col file_nm new_value file_nm
SQL> select 'amt_test_config'||to_char(sysdate,'HH24_MI_SS')||'.err' file_nm from dual;
FILE_NM
amt_test_config11_58_48.err
SQL> prompt &&file_nm;
amt_test_config11_58_48.err
SQL> host dir amt_test_config11_58_48.err
Volume in drive C has no label.
Volume Serial Number is F881-DE11
Directory of C:\
File Not Found
SQL> spool &&file_nm
SQL> rem NEW FILE CREATED
SQL> spool off;
SQL> host dir amt_test_config11_58_48.err
Volume in drive C has no label.
Volume Serial Number is F881-DE11
Directory of C:\
2007/08/31 11:59 AM 44 amt_test_config11_58_48.err
1 File(s) 44 bytes
0 Dir(s) 22,329,233,408 bytes free
SQL> host type amt_test_config11_58_48.err
SQL> rem NEW FILE CREATED
SQL> spool off;
SQL> undefine file_nm
SQL> col file_nm new_value file_nm
SQL> select 'amt_test_config'||to_char(sysdate,'HH24_MI_SS')||'.err' file_nm from dual;
FILE_NM
amt_test_config11_58_48.err
SQL> prompt &&file_nm;
amt_test_config11_58_48.err
SQL> host dir amt_test_config11_58_48.err
Volume in drive C has no label.
Volume Serial Number is F881-DE11
Directory of C:\
File Not Found
SQL> spool &&file_nm
SQL> rem NEW FILE CREATED
SQL> spool off;
SQL> host dir amt_test_config11_58_48.err
Volume in drive C has no label.
Volume Serial Number is F881-DE11
Directory of C:\
2007/08/31 11:59 AM 44 amt_test_config11_58_48.err
1 File(s) 44 bytes
0 Dir(s) 22,329,233,408 bytes free
SQL> host type amt_test_config11_58_48.err
SQL> rem NEW FILE CREATED
SQL> spool off;
Similar Messages
-
How to swap column values using variable in sql?
Hi,
I have a table and i want to swap two column values using variable
please help meHi,
Let us assume that the DeptNAME and DeptNo columns are of type VARCHAR2. However, DeptNO column is VARCHAR2(10) and DeptNAMe is VARCHAR2(100).
First of all DeptNo column needs to be modified to be 100.
i) ALTER TABLE DEPT MODIFY DEPTNO VARCHAR2(100);
Secondly, you will swap DEPTNAME and DEPTNO values using the SQL as follows:
ii) update dept t1
set deptname = (select deptno from dept2 t2 where t1.deptno = t2.deptno),
deptno = (select deptname from dept2 t2 where t1.deptno = t2.deptno);
Now, finally you want the deptname columns to be VARCHAR2(10)
iii) ALTER TABLE DEPT MODIFY DEPTNAME VARCHAR2(10).
If DEPTNO is a NUMBER column, you cannot alter the datatype unless the table is empty; in that case the whole swapping requirement would be moot.
Trinath Somanchi,
( http://www.myospages.com ) -
Is it possible to pass or set a variable in SQL LOADER? In this case I want the file name (eg $data) that is getting passed from the command line to load into my table into the extract_date field.
For example. The command line:
sqlldr user/password control=deposit.ctl data=080322.txt
Control file:
Load data
infile '$data'
Append into table deposit
, id position (1-10)
, extract_date date "YYMMDD" $data
Any thoughts?user567866 wrote:
Is it possible to pass or set a variable in SQL LOADER? In this case I want the file name (eg $data) that is getting passed from the command line to load into my table into the extract_date field.
For example. The command line:
sqlldr user/password control=deposit.ctl data=080322.txt
Control file:
Load data
infile '$data'
Append into table deposit
, id position (1-10)
, extract_date date "YYMMDD" $data
Any thoughts?Just wonder, why do you need a variable, if you are passing the filename on the command line? The sqlldr is perfectly capable to read the data from the file given as argument with parameter data. Just remove the line with infile from your controlfile and leave your commandline as is.
Best regards
Maxim -
Use variable in SQL for column name
Hi All,
We want to use a user input as a column name in APEX.
For e.g user will enter "ALLOWABLE_AMOUNT" then the query will be as follows :
select Rule,rule_name,rule_desc,"User Input" from rule_dim
where "User_input" > 100
So here the User_input will be substitued with Allowable_amount. Is this doable using any bind/substitution variables ? I tried ":P2_USER_VARIABLE" and "&P2_USER_VARIABLE." but did not work.
Please advice.Hi Andy,
You do that with an Interactive Report and a Dynamic Action.
I'll assume that you're using APEX 4.2
Here's how:
Create Page 2 with an Interactive Report
Create New Page > Report > Interactive Report > Next > Next
Enter a SQL Select statement: select Rule,rule_name,rule_desc from rule_dim
Next > Create > Edit Page
Create the item P2_USER_VARIABLE
Add Item > Number Field > Next
Item Name: P2_USER_VARIABLE
Next > Next > Next
Source Used: Always, replacing any existing value in session state
Source Type: Static Assignment (value equals source attribute)
Create Item
Create a Dynamic Action to refresh the Interactive Report when P2_USER_VARIABLE is changed
Add Dynamic Action
Name: Refresh IRR
Next >
Event: Lose Focus
Selection Type: Item(s)
Item(s): P2_USER_VARIABLE
Next >
Action: Refresh
Next >
Selection Type: Region
Region: Report 1 (10)
Create Dynamic Action
Add the ALLOWABLE_AMOUNT to the Interactive Report
Report 1
Region Source: SELECT * FROM (select Rule,rule_name,rule_desc, :P2_USER_VARIABLE AS ALLOWABLE_AMOUNT from rule_dim) WHERE ALLOWABLE_AMOUNT > 100
Apply Changes > Apply Changes
Get the Interactive Report to submit P2_USER_VARIABLE
Report 1
Page Items to Submit: P2_USER_VARIABLE
Apply Changes
Change the Heading for ALLOWABLE_AMOUNT in the Interactive Report
Interactive Report
Change the Heading of ALLOWABLE_AMOUNT to &P2_USER_VARIABLE.
Apply Changes
Run
Enter something into the USER VARIABLE field and select something else on the page. Watch the last column update to that value.
Tim. -
Using Variables in SQL*PLUS
Hi,
I hope to get any insight possible. I am using External tables and the Default directory is set. Now the process is that I get an automatic downloads of files placed in that directory. They are all to have the same naming system.
Test_June_2006 or Test_July_2006 and so on. Basically the month will be one behind, so Since it is August, I am looking for Test_July_2006.
I was able to set the "location" parameter to accept a variable, but i am having some trouble with set the value to that variable.
My code:
define month = EXTRACT(MONTH FROM CURRENT_DATE)-1||'_'||EXTRACT(YEAR FROM CURRENT_DATE).txt
variable month varchar2(100)
drop table ext_Test;
create table ext_Test
(field1 varchar2(25),
field2 varchar2(10),
field3 varchar2(10),
field4 varchar2(15),
field5 Float,
field6 Float,
field7 Float
organization external
( default directory sourcedata
access parameters
( records delimited by newline
SKIP 1
fields terminated by ','
OPTIONALLY ENCLOSED BY '"'
missing field values are null
location ('Test_&month')
reject limit 0;
When I tried "location ('&month') and setting month to July, it worked fine, but now that I am adding functions, it is not setting the variable properly.
Any help would be appreciated. Thank you.You cannot use & substitution variable to replace file name dynamically.
You will have to use the ALTER TABLE command at run time to alter the location of the file to what you want before you start processing.
SQL> create table ext_Test
2 (field1 varchar2(25),
3 field2 varchar2(10),
4 field3 varchar2(10),
5 field4 varchar2(15),
6 field5 Float,
7 field6 Float,
8 field7 Float
9 )
10 organization external
11 ( default directory sourcedata
12 access parameters
13 ( records delimited by newline
14 SKIP 1
15 fields terminated by ','
16 OPTIONALLY ENCLOSED BY '"'
17 missing field values are null
18 )
19 location ('Test_&month')
20 )
21 reject limit 0;
Enter value for month: july
old 19: location ('Test_&month')
new 19: location ('Test_july')
Table created.
SQL> alter table ext_test location('Test_August') ;
Table altered.
SQL> -
Using variables in SQL Plus Worksheet
I'm new to Oracle. I've developed in MS SQL for some time. I'm trying to debug a query we're using in an application. I paste it into SQL Plus Worksheet and get the message:
SP2-0552: Bind variable "COUNTYPK" not declared.
I could paste in a value, but I would like to define a variable before the query so that it will work the same way as it would in production.
SELECT rsiplate.OWNER.work_area_code || '-' || SUBSTR(rsiplate.OWNER.work_phone_number, 1, 3) || '-' || SUBSTR(rsiplate.OWNER.work_phone_number, 4, 4) AS BUSINESSPHONE, trim(rsiplate.OWNER.first_name||' '||rsiplate.OWNER.middle_name||' '||rsiplate.OWNER.last_name) AS BUSINESSNAME, rsiplate.ADDRESS.address_line1 AS ADDRESSLINE1, rsiplate.ADDRESS.address_line2 AS ADDRESSLINE2, rsiplate.ADDRESS.city_name AS CITY, rsiplate.ADDRESS.state_code AS STATE, SUBSTR(rsiplate.ADDRESS.zip_code, 1, 5) AS POSTALCODE FROM rsiplate.WATERCRAFT_MASTER, rsiplate.WATERCRAFT_CURRENT, rsiplate.WATERCRAFT_REGIST_CURRENT, rsiplate.OWNER, rsiplate.WATERCRAFT_OWNER_CURRENT, rsiplate.ADDRESS WHERE rsiplate.WATERCRAFT_MASTER.WATERCRAFT_ID = rsiplate.WATERCRAFT_CURRENT.WATERCRAFT_ID AND rsiplate.WATERCRAFT_MASTER.LF_WATERCRAFT_REGIST_ORDER = rsiplate.WATERCRAFT_REGIST_CURRENT.WATERCRAFT_REGIST_ORDER AND rsiplate.WATERCRAFT_MASTER.LF_WATERCRAFT_ORDER = rsiplate.WATERCRAFT_CURRENT.WATERCRAFT_ORDER AND rsiplate.WATERCRAFT_MASTER.watercraft_id = rsiplate.WATERCRAFT_REGIST_CURRENT.watercraft_id and rsiplate.WATERCRAFT_MASTER.watercraft_id = rsiplate.WATERCRAFT_OWNER_CURRENT.watercraft_id and rsiplate.WATERCRAFT_OWNER_CURRENT.owner_id = rsiplate.OWNER.owner_id and rsiplate.WATERCRAFT_MASTER.watercraft_owner_group = rsiplate.WATERCRAFT_OWNER_CURRENT.watercraft_owner_group and rsiplate.ADDRESS.address_set_id = rsiplate.OWNER.address_set_id and rsiplate.WATERCRAFT_MASTER.data_status_code = 1 and rsiplate.WATERCRAFT_OWNER_CURRENT.watercraft_owner_order = 1 and rsiplate.WATERCRAFT_REGIST_CURRENT.REGIST_EXPIRATION_DATE >= SYSDATE AND rsiplate.WATERCRAFT_CURRENT.WATERCRAFT_USE_CODE = 3 AND rsiplate.ADDRESS.COUNTY_NUMBER = :CountyPK GROUP BY rsiplate.OWNER.work_area_code, rsiplate.OWNER.work_phone_number, rsiplate.OWNER.first_name, rsiplate.OWNER.middle_name, rsiplate.OWNER.last_name, rsiplate.ADDRESS.address_line1, rsiplate.ADDRESS.address_line2, rsiplate.ADDRESS.city_name, rsiplate.ADDRESS.state_code, rsiplate.ADDRESS.zip_code;Okay, I made some adjustements:
SET DEFINE :
DEFINE :COUNTYPK = '01'
SELECT rsiplate.OWNER.work_area_code||'-'||SUBSTR(rsiplate.OWNER.work_phone_number, 1, 3)||'-'||SUBSTR(rsiplate.OWNER.work_phone_number, 4, 4) AS BUSINESSPHONE, trim(rsiplate.OWNER.first_name||' '||rsiplate.OWNER.middle_name||' '||rsiplate.OWNER.last_name) AS BUSINESSNAME, rsiplate.ADDRESS.address_line1 AS ADDRESSLINE1, rsiplate.ADDRESS.address_line2 AS ADDRESSLINE2, rsiplate.ADDRESS.city_name AS CITY, rsiplate.ADDRESS.state_code AS STATE, SUBSTR(rsiplate.ADDRESS.zip_code, 1, 5) AS POSTALCODE FROM rsiplate.WATERCRAFT_MASTER, rsiplate.WATERCRAFT_CURRENT, rsiplate.WATERCRAFT_REGIST_CURRENT, rsiplate.OWNER, rsiplate.WATERCRAFT_OWNER_CURRENT, rsiplate.ADDRESS WHERE rsiplate.WATERCRAFT_MASTER.WATERCRAFT_ID = rsiplate.WATERCRAFT_CURRENT.WATERCRAFT_ID AND rsiplate.WATERCRAFT_MASTER.LF_WATERCRAFT_REGIST_ORDER = rsiplate.WATERCRAFT_REGIST_CURRENT.WATERCRAFT_REGIST_ORDER AND rsiplate.WATERCRAFT_MASTER.LF_WATERCRAFT_ORDER = rsiplate.WATERCRAFT_CURRENT.WATERCRAFT_ORDER AND rsiplate.WATERCRAFT_MASTER.watercraft_id = rsiplate.WATERCRAFT_REGIST_CURRENT.watercraft_id and rsiplate.WATERCRAFT_MASTER.watercraft_id = rsiplate.WATERCRAFT_OWNER_CURRENT.watercraft_id and rsiplate.WATERCRAFT_OWNER_CURRENT.owner_id = rsiplate.OWNER.owner_id and rsiplate.WATERCRAFT_MASTER.watercraft_owner_group = rsiplate.WATERCRAFT_OWNER_CURRENT.watercraft_owner_group and rsiplate.ADDRESS.address_set_id = rsiplate.OWNER.address_set_id and rsiplate.WATERCRAFT_MASTER.data_status_code = 1 and rsiplate.WATERCRAFT_OWNER_CURRENT.watercraft_owner_order = 1 and rsiplate.WATERCRAFT_REGIST_CURRENT.REGIST_EXPIRATION_DATE >= SYSDATE AND rsiplate.WATERCRAFT_CURRENT.WATERCRAFT_USE_CODE = 3 AND rsiplate.ADDRESS.COUNTY_NUMBER = :CountyPK GROUP BY rsiplate.OWNER.work_area_code, rsiplate.OWNER.work_phone_number, rsiplate.OWNER.first_name, rsiplate.OWNER.middle_name, rsiplate.OWNER.last_name, rsiplate.ADDRESS.address_line1, rsiplate.ADDRESS.address_line2, rsiplate.ADDRESS.city_name, rsiplate.ADDRESS.state_code, rsiplate.ADDRESS.zip_code;
But I still get this:
SP2-0317: expected symbol name is missing
old 2: iplate.WATERCRAFT_REGIST_CURRENT.watercraft_id and rsiplate.WATERCRAFT_MASTER.watercraft_id = rsiplate.WATERCRAFT_OWNER_CURRENT.watercraft_id and rsiplate.WATERCRAFT_OWNER_CURRENT.owner_id = rsiplate.OWNER.owner_id and rsiplate.WATERCRAFT_MASTER.watercraft_owner_group = rsiplate.WATERCRAFT_OWNER_CURRENT.watercraft_owner_group and rsiplate.ADDRESS.address_set_id = rsiplate.OWNER.address_set_id and rsiplate.WATERCRAFT_MASTER.data_status_code = 1 and rsiplate.WATERCRAFT_OWNER_CURRENT.watercraft_owner_order = 1 and rsiplate.WATERCRAFT_REGIST_CURRENT.REGIST_EXPIRATION_DATE >= SYSDATE AND rsiplate.WATERCRAFT_CURRENT.WATERCRAFT_USE_CODE = 3 AND rsiplate.ADDRESS.COUNTY_NUMBER = :CountyPK GROUP BY rsiplate.OWNER.work_area_code, rsiplate.OWNER.work_phone_number, rsiplate.OWNER.first_name, rsiplate.OWNER.middle_name, rsiplate.OWNER.last_name, rsiplate.ADDRESS.address_line1, rsiplate.ADDRESS.address_line2, rsiplate.ADDRESS.city_name, rsiplate.ADDRESS.state_code, rsiplate.ADDRESS.zip_code
new 2: iplate.WATERCRAFT_REGIST_CURRENT.watercraft_id and rsiplate.WATERCRAFT_MASTER.watercraft_id = rsiplate.WATERCRAFT_OWNER_CURRENT.watercraft_id and rsiplate.WATERCRAFT_OWNER_CURRENT.owner_id = rsiplate.OWNER.owner_id and rsiplate.WATERCRAFT_MASTER.watercraft_owner_group = rsiplate.WATERCRAFT_OWNER_CURRENT.watercraft_owner_group and rsiplate.ADDRESS.address_set_id = rsiplate.OWNER.address_set_id and rsiplate.WATERCRAFT_MASTER.data_status_code = 1 and rsiplate.WATERCRAFT_OWNER_CURRENT.watercraft_owner_order = 1 and rsiplate.WATERCRAFT_REGIST_CURRENT.REGIST_EXPIRATION_DATE >= SYSDATE AND rsiplate.WATERCRAFT_CURRENT.WATERCRAFT_USE_CODE = 3 AND rsiplate.ADDRESS.COUNTY_NUMBER = 01 GROUP BY rsiplate.OWNER.work_area_code, rsiplate.OWNER.work_phone_number, rsiplate.OWNER.first_name, rsiplate.OWNER.middle_name, rsiplate.OWNER.last_name, rsiplate.ADDRESS.address_line1, rsiplate.ADDRESS.address_line2, rsiplate.ADDRESS.city_name, rsiplate.ADDRESS.state_code, rsiplate.ADDRESS.zip_code
iplate.WATERCRAFT_REGIST_CURRENT.watercraft_id and rsiplate.WATERCRAFT_MASTER.watercraft_id = rsiplate.WATERCRAFT_OWNER_CURRENT.watercraft_id and rsiplate.WATERCRAFT_OWNER_CURRENT.owner_id = rsiplate.OWNER.owner_id and rsiplate.WATERCRAFT_MASTER.watercraft_owner_group = rsiplate.WATERCRAFT_OWNER_CURRENT.watercraft_owner_group and rsiplate.ADDRESS.address_set_id = rsiplate.OWNER.address_set_id and rsiplate.WATERCRAFT_MASTER.data_status_code = 1 and rsiplate.WATERCRAFT_OWNER_CURRENT.watercraft_owner_order = 1 and rsiplate.WATERCRAFT_REGIST_CURRENT.REGIST_EXPIRATION_DATE >= SYSDATE AND rsiplate.WATERCRAFT_CURRENT.WATERCRAFT_USE_CODE = 3 AND rsiplate.ADDRESS.COUNTY_NUMBER = 01 GROUP BY rsiplate.OWNER.work_area_code, rsiplate.OWNER.work_phone_number, rsiplate.OWNER.first_name, rsiplate.OWNER.middle_name, rsiplate.OWNER.last_name, rsiplate.ADDRESS.address_line1, rsiplate.ADDRESS.address_line2, rsiplate.ADDRESS.city_name, rsiplate.ADDRESS.state_code, rsiplate.ADDRESS.zip_code
ERROR at line 2:
ORA-00933: SQL command not properly ended -
PL SQL using variable in SQL statement
I am trying to execute several sql statements, that have the same format but different values. Does this
mean I need a bind variable?
ie
select TO_CHAR ( (SYSDATE - 2), 'YYYY_MM_DD') from dual
select TO_CHAR ( (SYSDATE - 4), 'YYYY_MM_DD') from dual
select to_char(add_months(sysdate,-2*1) from dual
When I try to put the values into a varaiable (date, varchar2 or number) I am getting a conversion
error.
Can somebody show me an example of how to do something like this? Or at least point me to the correct
part of the documentation that provides and example. Pardon my syntax as I know it is incorrect
val :=add_months(sysdate,-2*1
select to_char(val) from dual
Thanks in advance to all who answerHi,
840386 wrote:
I am trying to execute several sql statements, that have the same format but different values. Does this
mean I need a bind variable?No, you don't need a bind variable, though bind variables may be more efficient than using PL/SQL variables. I don't see where you're trying to use any varibables at all in your examples. Is it in place of the literals, such as 2 or 'YYYY_MM_DD'? You can use either bind varibales or PL/SQL variables in those places.
ie
select TO_CHAR ( (SYSDATE - 2), 'YYYY_MM_DD') from dual
select TO_CHAR ( (SYSDATE - 4), 'YYYY_MM_DD') from dual
select to_char(add_months(sysdate,-2*1) from dualIn PL/SQL, when you have a SELECT statement, you must specify what you want to do with the results. For example, a SELECT ... INTO statement:
SELECT AVG (sal)
INTO avg_salary
FROM scott.emp;There's usually no point in SELECTing from dual in PL/SQL. It's not an error, but it's simpler just to use an assignment statement.
When I try to put the values into a varaiable (date, varchar2 or number) I am getting a conversion
error.Post a complete procedure or anonymous block, including variable declarations, that shows exactly what you're trying to do.
>
Can somebody show me an example of how to do something like this? Or at least point me to the correct
part of the documentation that provides and example. Pardon my syntax as I know it is incorrect
val :=add_months(sysdate,-2*1Assuming val is a DATE, that's basically correct. You have unbalanced parentheses (there's a '(', but no matching ')' ), and you need a semicolon (';') at the end of the statement. Perhaps ');' just got cut off when you were posting this.
select to_char(val) from dualAgain, SELECTing from dual is unnecessary, but if you had some way to catch the returned value, that would work.
Usually, the reason why you need to call TO_CHAR is that you want a value in a particular format, which is specified in the 2nd argument to TO_CHAR. Calling TO_CHAR with only one argument is a possible mistake, but not something that would raise an error.
Here's an example that works:
SET SERVEROUTPUT ON
DECLARE
d DATE;
v VARCHAR2 (30);
BEGIN
d := ADD_MONTHS (SYSDATE, -2); -- -2 = (-2*1)
v := TO_CHAR (d, 'DD-Mon-YYYY');
dbms_output.put_line (v || ' = v');
END;
/Output (when run on March 13, 2011):
13-Jan-2011 = v -
HI guys:
I need code three SQL statements.the returned field and selected table are all same,there is only a difference in their "where" statement.
Sample code:
select marcmatnr marcwerks
into table it_data
from MARC inner join MBEW on marcmatnr = mbewmatnr
where marcmatnr like 'A%' and mbewzplp1 = '001'.
second one........................ mbew~zplp2 = '001'
third one......................... mbew~zplp3 = '001'
Could I write a FORM gather them with transporting a parameter ZPLPX to determine which condiniton will be execute?
thank you very much.Hi tianli,
1. source text
This concept of dynamic where
condition is called source text.
2. use like this.
This is important in the code ---> WHERE (mywhere).
REPORT abc LINE-SIZE 80.
DATA : it_data LIKE TABLE OF mara WITH HEADER LINE.
QUOTES ARE IMPORTANT
PERFORM mysql USING 'mbew~zplp2 = ''001'''.
FORM mysql USING mywhere.
SELECT marcmatnr marcwerks
INTO TABLE it_data
FROM marc INNER JOIN mbew ON marcmatnr = mbewmatnr
WHERE (mywhere).
ENDFORM. "mysql
regards,
amit m. -
Using variables in sql scripts
I am trying to pass a variable into a simple
sql script - but each time I run it, it still asks for the variable.
Here is my example:
test.sql contains:
select count(*) from &tbl
I try to run it by typing the following
at the sqlplus prompt:
@test the_tbl
Even though I provide a value for &tbl,
sqlplus still asks me for the value:
Enter value for tbl:
I am sure that the answer is very simple.
what am I doing wrong ?
Thanks !<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by KR:
I am trying to pass a variable into a simple
sql script - but each time I run it, it still asks for the variable.
Here is my example:
test.sql contains:
select count(*) from &tbl
I try to run it by typing the following
at the sqlplus prompt:
@test the_tbl
Even though I provide a value for &tbl,
sqlplus still asks me for the value:
Enter value for tbl:
I am sure that the answer is very simple.
what am I doing wrong ?
Thanks !<HR></BLOCKQUOTE>
In SQL Plus 8.0 this command goes correctly:
select count(*) from &tb ;
null -
HELP - using variables in SQL statement
Hi,
I am sure that this is a small problems for the gurus out there.
I am trying to execute the following statement usign JDBC:
String myVariable = "XYZ";
sSQL = "select COL1, COL2 from TABLE1 where COL3 = '" + myVariable + "'";
CODE ABOVE DOES NOT WORK FOR ME!!!!!
HOWEVER, if I were to directly substitute the value XYZ as shown below, then things work. But that does not solve my problem.
sSQL = "select COL1, COL2 from TABLE1 where COL3 = '" + "XYZ" + "'";
Any suggestions?
nullUse methods setXXXX of the PreparedStatement class.
Connection conn =
DriverManager.getConnection("jdbc:default:connection:");
PreparedStatement stm=conn.prepareStatement(
"select name from persons where inn=?");
String inn="ASDDGF12345";
String name=new String;
stm.setString(1,inn);
ResultSet rss = stm.executeQuery();
if (rss.next())
name = rss.getString(1);
rss.close();
stm.close();
conn.close(); -
Error using presentation variable in SQL Expression
Hi all,
I'm receiving an error - '...Error getting drill information...' due to a presentation variable being used in a SQL Expression. It probably has something to do with a data type issue. I've narrowed the error to the use of the presentation variable.
I'm setting a presentation variable, pres_mth_nme_to, from a dashboard prompt. The prompt contains a month name.
I'm using the presentation variable as part of a SQL Expression in a filter. The gist of the SQL Expression is to use the
presentation variable in a CASE and set a value accordingly. For example:
Column: Month Sort Value
Operator: Between
Value: *10*
SQL Expression: *Case @{pres_mth_nme_to}{some default} WHEN 'NOV' THEN '10' WHEN 'DEC' THEN '11' WHEN 'JAN' THEN '12' WHEN 'FEB' THEN '13' WHEN...END*
The month name is character. If I were to hard code this, I don't recieve the error. For example:
CASE 'SEP' WHEN 'NOV' THEN '10' WHEN 'DEC' ...END
There something going on with the data type from the prompt and it being used in the comparison. If I use a CAST, the problem still exists.
CASE CAST(@{pres_mth_nme_to} as char(3)) WHEN 'NOV' THEN ... END
If I'm in Answers, the problem doesn't exist, I'm assuming because of the default values. If I'm on the dashboard, it does exist, I'm assuming because of recieving the prompt value.
I don't know what I'm missing. Any suggestions?
Thanks.DJ,
if the formula presented by you is exactly true, i mean it was not fabricated to present as an example in the forum, you should include the presentation variable in single quotes.
i.e. your formula must look somthing like
Case '@{pres_mth_nme_to}{some default}' WHEN 'NOV' THEN '10' WHEN 'DEC' THEN '11' WHEN 'JAN' THEN '12' WHEN 'FEB' THEN '13' WHEN...END
let me know if it did solve the issue...
-bifacts
http://www.obinotes.com
Edited by: bifacts on Oct 25, 2010 1:50 PM -
How to set a variable in portal session using web dynpro java.
Hi,
I have created a web dynpro application, which is running inside portal. I have created a role called "R1". Inside role R1, i have created 3 workset W1, W2 and W3. and inside each workset i have some pages and iviews.
My requirement is when user logins to the portal , and when he clicks on role R1 for the first time, a login page should come (so that we can do revalidation), and when he enters his password again in that login page , then only workset W1, W2 and W3 should be visible/accessible to him and after successful revalidation, if he clicks again on role R1, in that particular portal session, than that login page should not come.
for this, i thought i will set a variable in portal session, whenever user successfully revalidated himself, and if after successful revalidation he clicks again on role R1, i will check in doinit method of webdynpro whether variable is set or not (which i already set on successful revalidation), and if it is set then i will do Donavigation else i will present login page to the user.
Can anyone tells me how to set a variable in portal session using web dynpro java.
thanks
ArushHi,
Try this:
WDScopeUtil.put(WDScopeType.CLIENTSESSION_SCOPE, key, value)
WDScopeUtil.get(WDScopeType.CLIENTSESSION_SCOPE, key)
Ex:
WDScopeUtil.put(WDScopeType.CLIENTSESSION_SCOPE,"Key1","Value1");
String value1=WDScopeUtil.get(WDScopeType.CLIENTSESSION_SCOPE,"Key1").toString();
/people/william.cui/blog/2007/02/12/sharing-session-context-between-parent-and-external-windows-running-on-same-host
Regards,
Charan -
How to Set and Use a global variable within a session?
Dear All,
I'm new to jsp, and would like to ask how to set and use a global variable within a session?
Thanks in advance.
Regards,
CecilWith session.setAttribute("name",object) you can store a Attribute in the session object.
with session.getAttribute("name") you can get it.
That's it.
Regards,
Geri -
Using variable coulmn name in sql function
Hi there,
I am not an expert with PL/SQL and I can not figure out how to use variable column names in my function.
My function is:
CREATE OR REPLACE FUNCTION RESET_TRIGGERS(aTrigger VARCHAR2) RETURN NUMBER IS
TEMP_ID NUMBER;
TEMP_USER_ID NUMBER;
BEGIN
SELECT 'LIMS.'||'$aTrigger'||'.NEXTVAL' INTO TEMP_ID FROM DUAL;
SELECT 'LIMS.'||'$aTrigger'||'_USER.NEXTVAL' INTO TEMP_USER_ID FROM DUAL;
IF TEMP_ID > TEMP_USER_ID THEN
LOOP
SELECT LIMS.SQ_U_FINALRESULT_USER.NEXTVAL INTO TEMP_USER_ID FROM DUAL;
EXIT WHEN TEMP_USER_ID = TEMP_ID;
END LOOP;
ELSE
WHILE TEMP_ID < TEMP_USER_ID LOOP
SELECT LIMS.SQ_U_FINALRESULT.NEXTVAL INTO TEMP_ID FROM DUAL;
END LOOP;
END IF;
COMMIT;
RETURN (TEMP_ID);
END;
What I want is that I pass a seqencename with aTrigger and that two triggers will be equal if not.
eg ifaTrigger = 'SQ_U_FINALRESULT'
than I want the triggers LIMS.SQ_U_FINALRESULT and LIMS.SQ_U_FINALRESULT_USER to be set equal.
The above function will not work, but what will?????
I hope you can help me out!
CheersA very strange function indeed.
But here is what I think he meant to do:
SQL> create procedure reset_sequences
2 ( p_sequence_name in varchar2
3 , p_nextval out number
4 )
5 is
6 l_nextval1 number;
7 l_nextval2 number
8 ;
9 procedure reset_sequence_value
10 ( p_sequence_name in varchar2
11 , p_current_value in number
12 , p_new_value in number
13 )
14 is
15 l_dummy number;
16 begin
17 execute immediate 'alter sequence ' || p_sequence_name || ' increment by ' || to_char(p_new_value-p_current_value);
18 execute immediate 'select ' || p_sequence_name || '.nextval from dual' into l_dummy;
19 execute immediate 'alter sequence ' || p_sequence_name || ' increment by 1';
20 end reset_sequence_value
21 ;
22 begin
23 execute immediate
24 'select ' || p_sequence_name || '.nextval,' || p_sequence_name || '_user.nextval from dual'
25 into l_nextval1, l_nextval2
26 ;
27 if l_nextval1 < l_nextval2
28 then
29 reset_sequence_value(p_sequence_name,l_nextval1,l_nextval2);
30 end if
31 ;
32 if l_nextval1 > l_nextval2
33 then
34 reset_sequence_value(p_sequence_name || '_user',l_nextval2,l_nextval1);
35 end if
36 ;
37 p_nextval := greatest(l_nextval1,l_nextval2)
38 ;
39 end reset_sequences;
40 /
Procedure is aangemaakt.
SQL> show err
Er zijn geen fouten.
SQL> create sequence testseq start with 5 increment by 1
2 /
Reeks is aangemaakt.
SQL> create sequence testseq_user start with 2 increment by 1
2 /
Reeks is aangemaakt.
SQL> declare
2 l_new_value number;
3 begin
4 reset_sequences('testseq',l_new_value);
5 dbms_output.put_line(l_new_value);
6 end;
7 /
5
PL/SQL-procedure is geslaagd.
SQL> select testseq.currval from dual
2 /
CURRVAL
5
1 rij is geselecteerd.
SQL> select testseq_user.currval from dual
2 /
CURRVAL
5
1 rij is geselecteerd.Regards,
Rob. -
Using Bind variables in SQL PLUS Report
using Bind variables in SQL PLUS Report. This report gets the arguments from the application concurrent program. Now my need is to convert the start_date and end_date to bind Variables to improve the performance. I have commented the original code in 'prompt List of Unapproved Adjustments' and used my Bind Variable but it is giving an error
error: Bind Variable "ENDING_DATE" not declared
Report Date and Time:
26-OCT-2010 15:44:13
List of Unapproved Adjustments
Bind Variable 'ENDING_DATE" not declared
Please see below the code for the sql plus report:
define p_org_id = '&1'
define p_fy_begin_date = '&2'
define p_start_date = '&3'
define p_end_date = '&4'
define p_conversion = '&5'
declare
variable begin_date date;
exec :begin_date := p_start_date;
variable ending_date date;
exec :ending_date := p_end_date;
/* Begin
:begin_date := to_date('&p_start_date','YYYY/MM/DD HH24:MI:SS');
:ending_date := to_date('&p_end_date','YYYY/MM/DD HH24:MI:SS');
End; */
set newpage none
set termout off
set pagesize 55
set linesize 180
set heading on
set feedback off
set wrap off
set space 1
set heading on
begin
dbms_application_info.set_client_info('&p_org_id');
end;
prompt
prompt Report Date and Time:
prompt ----------------------
select to_char(sysdate,'DD-MON-YYYY HH24:MI:SS')
from dual ;
prompt
prompt List of Unapproved Adjustments
prompt -------------------------------
select b.trx_number,
a.adjustment_number,
f.user_name created_by
from apps.ar_adjustments a,
apps.ra_customer_trx b,
apps.fnd_user f
where a.customer_trx_id = b.customer_trx_id
and a.status <> 'A'
and a.created_by = f.user_id
and a.creation_date between :begin_date
and :ending_date
-- and a.creation_Date between to_date('&p_start_date','YYYY/MM/DD HH24:MI:SS')
-- and to_date('&p_end_date','YYYY/MM/DD HH24:MI:SS')
order by
b.trx_number ;Hi
Please go to customization part of the report and verify..You have set a default value out there ..And also verify your lov and look at the values ..If it is again giving you the problem ..pl delete the report and develop it again from the scratch it will be solved...
vishnu
null
Maybe you are looking for
-
In iphoto '11 v 9.2.1 whenI share a photo via email I type an email address in the to: field and it keeps dissapearing.
-
Time Machine Killed My External Hard Drive
Tried to backup with Time Machine. Now my external La Cie Hard drive is not recognized. I don't want to initialize and loose all existing data. Anyone know if Apple is going to make everything right again?
-
Actions: Select by document name?
How can I select a document by its name? I have about 40 image files open, in which I'm attempting to create an action to copy elements from numerous documents into a common one. (which I've named "Common File") However when playing this back, the a
-
Moving persistent data from boss to boss (document conversion)
I'd like to move one of my persistent data implementations from one boss to another. Unfortunately, there are documents created with an older version of the plugin that are still in use and would become incompatible with the new plug-in version. Doub
-
Will the dng converter deal with CR2 raw files from Canon 7D?
Mine does not. If there is an upgrade, please remind me where to obtain it. Thank you -- ML