How to bind DATE variables in SQL*Plus
I have a stored procedure in a package that has a DATE OUT parameter
myPackage.myProcedure( outDate OUT DATE )
I am trying to test this from SQL*Plus
How do I specify a Bind variable for the outDate? The VARIABLE command does not allow DATE types?
If this was a CHAR type I could have done
VARIABLE myChar CHAR
BEGIN
myPackage.myProcedure( :myChar )
END;
PRINT myChar
How do I do this with DATE data types instead? I am using Oracle 8.1.7.
you should use VARCHR2 type with the minimum length that can store a value defined by your NLS_DATE_FORMAT
string. The returned date will be converted to a VARCAHR2 type and the size and format will depend on
your NLS_DATE_FORMAT setting.
=============================================================================
SQL> variable dt VARCHAR2(20)
SQL> create or replace procedure ret_date(dt OUT DATE) is
2 begin
3 dt := SYSDATE ;
4 end ;
5 /
Procedure created.
SQL> exec ret_date(:dt) ;
PL/SQL procedure successfully completed.
SQL> print dt
DT
13-OCT-02
SQL> select sysdate from dual ;
SYSDATE
13-OCT-02
SQL> alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS' ;
Session altered.
SQL> exec ret_date(:dt) ;
PL/SQL procedure successfully completed.
SQL> print dt
DT
13-OCT-2002 10:43:23
SQL>
================================================================
Similar Messages
-
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 -
How to execute procedure returning data rows from sql plus
Hi,
I want to execute a stored procedure that returns data rows from sql plus. please let me know the syntax for the same.
Thanks,
YGuser13065317 wrote:
Even if i get the result set into the cursor, do i have to do normal fetch into all the coumn variables within a loop
But suppose no of columns in my result set varies depending on a parameter to the stored procedure.
Is there any straightforward way to retrieve all the data irrespective of no of columns in the result set.There is no such thing as a "+result set+". Oracle does not create a temporary data set in memory that contains the results of your query. What would happen if this result set is a million rows and is too large to fit into memory? Or there are a 100 clients each with a 100,000 row result set?
This is not scalable. You will be severely limited in the number and sizes of these "+result sets+" that can be created in server memory.
A cursor is in fact a "program" that is created by compiling the SQL source code that you provide. This source code is parsed and compiled into what Oracle calls an execution plan. This is nothing but a series of instructions that the cursor will execute in order to return the rows required.
Thus the result set is actually the output from a cursor (a program). Likewise, bind variables are the input parameters to this program.
All SQLs are parsed and compiled as cursors and stored in the SQL Shared Pool. Oracle gives you handle in return to use to address this cursor - bind values to it, execute it, describe the output structure returned by the cursor, and fetch the output from the cursor.
On the client side, this handle is used in different ways. In PL/SQL alone, this cursor handle can be used as an implicit cursor (you do not even see or use the cursor handle in your PL/SQL code). Or you can use a PL/SQL cursor variable. Or a DBMS_SQL cursor variable. Or a reference cursor variable.
Why so many different client structures for the very same SQL cursor handle returned by Oracle? Because to allow you, the programmer, all kinds of different features and flexibility.
The ref cursor feature is the ability to pass this cursor handle around, not only between PL/SQL code, but also from PL/SQL to the actual client process (Java. VB, SQL*Plus, TOAD, etc).
The primary thing to remember - irrespective of what the client calls this (e.g. ref cursor, SQL statement handle, etc), this all refers to the same SQL cursor in the Shared Pool. And that this SQL cursor is a program that outputs data, and not a result set in itself. -
Windows System Environment Variables in "Sql * plus"
Can i use/reference Windows System Environment variables in "Sql * plus"?
For example, i want to create sql-script to run in database server computer that asks variable "ORA_HOME" and uses this value to execute some sql/plsql sentences.
Oracle 10g Personal, Windows 7.
Edited by: CharlesRoos on 12.11.2010 17:28CharlesRoos wrote:
Business problem:
I have created 2 databases in my computer. Both databases needs tablespaces created by a script. Tablespaces' datafiles (.dbf files) names are same for both database. Both database has it's own directory where it holds datafiles at the moment. At the moment the datafiles for Database1 are in folder something like "%ORACLE_HOME%"\oradata\%databasename1%\*.dbf, and second database has its datafiles in other folder, somewhere ""%ORACLE_HOME%"\oradata\%databasename1%\*.dbf". I want now the script to create tablespace called "INDX" with same datafile name "indx1.dbf" into both database. So into both mentioned folder the file "indx1.dbf" must be created by script. I think the script should do following:
1. get ORACLE_HOME.
2. connect to database "databasename1"
3. EXECUTE IMMEDIATE "Create TableSpace INDX....file=%ORACLE_HOME% || databasename1 || indx1.dbf"
4. connect to database "databasename2"
5. EXECUTE IMMEDIATE "Create TableSpace INDX....file=%ORACLE_HOME% || databasename2 || indx1.dbf"I don't have Oracle database near by anymore, so the code was pseudocode.
I don't understand how to use ?-shortcut.OK, my first impression is "why does this even NEED to be scripted? Creation of new tablespaces is usually a one-off operation.
But that aside how about this sqlplus command-line substitution variables. This example is in linux, but will work as well in Windows with the change of the way environment variables are referenced:
*nix - echo $myvariable
Windows - echo %myvariable%
First, the sqlscript to create the TS. Note the use of the substitution variable "&1"
{code}
[oracle@vmlnx01 ~]$ cat cat makets.sql
set echo on feedback on verify on trimsp on
prompt &1
CREATE SMALLFILE TABLESPACE EDSTEST
DATAFILE '/ora01/oradata/&1/edstest.dbf'
SIZE 5M
REUSE
AUTOEXTEND ON
NEXT 1280K
MAXSIZE 32767M
LOGGING
EXTENT MANAGEMENT LOCAL
SEGMENT SPACE MANAGEMENT AUTO
drop tablespace edstest
including contents and datafiles
exit
{code}
So, at the OS prompt: Notice that the @ is separated by a space, makeing it a command line parm instead of part of the connect string
{code}
[oracle@vmlnx01 ~]$ export myparm=vlnxora1
[oracle@vmlnx01 ~]$ sqlplus system/pswd @makets $myparm
SQL*Plus: Release 10.2.0.4.0 - Production on Fri Nov 12 13:18:05 2010
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> prompt &1
vlnxora1
SQL> --
SQL> CREATE SMALLFILE TABLESPACE EDSTEST
2 DATAFILE '/ora01/oradata/&1/edstest.dbf'
3 SIZE 5M
4 REUSE
5 AUTOEXTEND ON
6 NEXT 1280K
7 MAXSIZE 32767M
8 LOGGING
9 EXTENT MANAGEMENT LOCAL
10 SEGMENT SPACE MANAGEMENT AUTO
11 ;
old 2: DATAFILE '/ora01/oradata/&1/edstest.dbf'
new 2: DATAFILE '/ora01/oradata/vlnxora1/edstest.dbf'
Tablespace created.
SQL> --
SQL> drop tablespace edstest
2 including contents and datafiles
3 ;
Tablespace dropped.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@vmlnx01 ~]$
{code} -
How to replicate data from MS SQL Server to Oracle
Hi,
Can someone please help me on how to replicate data from MS SQL Server to Oracle 8i database.Dear,
I'm a student.
I do simple replication on Oracle 8.0.5 successfully. (one master site and one snapshot site). I only use the SQL*Plus and Schema Manager to do.
But when I do advance replication (multimaster replication) I meet many problem. So I don't get the result.
Do you show me the technology to do that ?
Thanks ! -
How to retreive this file in SQL*Plus
If I upload files which name is KOREAN, name of files is invisible.
I dont't know cause of this problem.
How is keeping korean name of file from breaking?
Also, answer how to retreive this file in SQL*Plus
Thanks
silverbellTo access ifs data from SQL, you need to (officially) setup a 'user view'. Refer to the Java API documentation on how to do this. Once you have created the user view, then you may access this view using any SQL tool.
-
How to return a value from sql plus activity
Hi,
I want to return a value from sqlplus activity to a processflow variable.
SQL PLUS activity has a property :"RESULT_CODE", whenever i run the process flow this value is always reurned as 0.
in sqlplus activity i have written some pl/sql block....
for example
begin
end;
exit
i want to do something like
begin
if v=100 then
return 1
else
return 0;
end if;
end;
exit
can some please tell me how can i return value from this pl/sql block to proessflow.
Regards,
RD_RBStable ==> function
input param from table to function. ==> input mapping paramter to store the output from the mapping.
Will this now work. -
Passing a Date variable to SQL
Hi,
I am trying to pass in a Date variable into SQL query, but I am getting this error:
"inconsistent datatypes: expected DATE got NUMBER"
and my code looks like this. I would appreciate any help on how I need to create the Date variable that SQL would accept it.
THANKS A LOT!
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yy");
String txt = "01/01/1990";
java.util.Date startYear2 = (java.util.Date) formatter.parse(txt, new ParsePosition(0));
java.sql.Date startYear = new java.sql.Date(startYear2.getTime());
String txt2 = "12/31/1990";
java.util.Date endYear2 = (java.util.Date) formatter.parse(txt2, new ParsePosition(0));
java.sql.Date endYear = new java.sql.Date(endYear2.getTime());
String scoredGoalsQuery = "SELECT count(name) from player_goal_rel where name = '" + pName + "' and pdate BETWEEN "+ startYear +" and "+ endYear;
ResultSet scoredGoalsResult = stmt.executeQuery(scoredGoalsQuery);You should be using prepared statements.
String scoredGoalsQuery = "SELECT count(name) from player_goal_rel where name = ? and pdate BETWEEN ? and ?":
PreparedStatement pstmt = connection.prepareStatement(scoredGoalsQuery);
pstmt.setString(1, pName);
pstmt.setDate(2, startYear);
pstmt.setDate(3, endYear);
ResultSet scoredGoalsResult = pstmt.executeQuery(); -
*Urgent*How to insert data from MS SQL to the table that create at the adobe form?
Hi,
I'm using Adobe life cycle designer 8 to do my interactive form. I would like to ask how to insert data from MS SQL to the table that i have created in my adobe interactive form?
I really need the information ASAP as i need to hand in my project by next week... i really appreciate any one who reply this post.
ThanksTou need to do a couple of things
1. On the Essbase server, set up an odbc system connection to your MySQL database
2. In the load rule , go to the file menu and select open SQL data source and in the data source put in your SQL statement . A couple of hints. Where it says Select, don't put in the word select and where it say from don't put in from. The system adds them for you. The easiest way ti enter a SQL statement is to do it all in the select area So if your SQL would normanlly say select * from mytable just enter the code as * from mytable in the select area
The click ol/retrieve and enter in your connection info. Itshould bring data back into the load rule. Save the load rule and use it -
How to convert DATE variable to CHAR variable
dear all,
How to convert DATE variable to CHAR variable
thanqDepending on your final goal here are 2 options.
DATA: datein TYPE d.
DATA: dateout(10) TYPE c.
DATA: dateout2(8) TYPE c.
datein = sy-datum.
WRITE datein TO dateout MM/DD/YYYY.
dateout2 = datein.
WRITE:/ datein, dateout, dateout2.
and the output
05022008 05/02/2008 20080502 -
How to Generate Trace Files in SQL*Plus
Hi Friends ,
How to Generate Trace Files in SQL*Plus ?
i have no idea
thanks
rajWhat trace files would you like to generate?
Are we talking SQL trace files?
ALTER SESSION SET sql_trace = TRUE;This will be generated in the user_dump_dest on the server.
show parameter dump -
How to find session information in sql plus
Can someone please tell me how to find session information in sql plus? I specifically want to know my privileges for the current session. Thanks in advance.
SELECT * FROM session_privs;
SELECT * FROM session_roles; -
How to invoke multiple sessions of sql*plus thru pl/sql program
Hi
How to invoke multiple sessions of sql*plus thru pl/sql program.
ThanksHow to invoke sql*plus in a procedure?????
I have to invoke more pl/sql sessions?????No you don't "have to".
Look at what you are trying to do.
You have a program running inside the PL/SQL engine. This is running nicely inside the Oracle database and is perfectly capable of issuing other SQL statements, PL/SQL programs etc. inside it's nice cosy Oracle environment.
You are asking for this PL/SQL to shell out to the operating system, run an external application, for which it will have to supply a username and password (are you planning on hard coding those into your PL/SQL?), and then that external application is supposed to run more SQL or PL/SQL against the database.
a) Why hold all this code external to the database when it can quite happily reside on the database itself and be executed through jobs or whatever.
b) Consider what would happen if someone were to replace the external application with their own program of the same file name... they'd be able to capture the username and password for connecting to the database, therefore a major security flaw.
The whole idea of doing what you want through external calls to SQL*Plus is ridiculous. -
Hide new/old value of bind variable in SQL*Plus
Hi,
I have a SQL*Plus script to create a new user. It asks for username & password and then passes these values to a SP to do some checks and finally create the user.
The output is currently the following :
New user will be created in ORCL LAB
Enter the requested username : fleet2
Enter the password for fleet2 : *****
Re-enter the password for fleet2 : *****
old 2: labadmin_cr_user('&username', '&pswd', '&pswd2');
new 2: labadmin_cr_user('fleet2', 'fleet', 'fleet');
The requested username is already in use in the database. Please choose another username.
As you can see the passwords are now exposed when the procedure is called. This is not what I want off course. I cannot do termout off as the serveroutput is not shown as well in that case. I use dbms_output to show error messages to users. (see example above in case of an existing user).
Can anybody tell me how to hide these 2 lines (old 2, new 2) without hiding my dbms_output.
Thanks!
Krisset verify offhttp://download-uk.oracle.com/docs/cd/B10501_01/server.920/a90842/ch13.htm#1013382
-
How to bind local variables in complex query in PL/SQL
Hi
I have long complex query with local varibales; when I run in Dynamic SQL I get an error. Not sure which is the easiest way to bind local variables.
L_QUERY := q'[select m.segment1 col1,
'1' col2,
'13' col3,
l.operand col4,
0 col5,
'Y' col8,
'N' col9,
'N' col10,
decode(h.name,'09_UKOR_*','EOS Credit','10_UKOR_*','TopUp','11_UKOR_*','Main') col18
from qp_list_headers_v h,
qp_list_lines_v l,
mtl_system_items m
where h.name in ('09_UKOR_*','10_UKOR_*','11_UKOR_*')
and h.list_header_id = l.list_header_id
and m.inventory_item_id = l.product_attr_value
and m.organization_id = 84
UNION all
SELECT qs.PRODUCT_ATTR_VALUE col1,
hca.account_number col2,
decode (su.site_use_code,'BILL_TO','21','SHIP_TO','18') col3,
0 col4,
qs.operand col5,
null col6,
null col7,
'N' col8,
'Y' col9,
'N' col10,
--Local variables
(case when (trunc(nvl(qq.start_date_active,sysdate)) between l_cur_year_from and l_cur_year_to) and
( trunc(nvl(qq.end_date_active,l_cur_year_to)) >= trunc(l_cur_year_to) ) then 'TopUp'
when (trunc(qq.start_date_active) between l_next_year_from and l_next_year_to) and
( trunc(nvl(qq.end_date_active,l_next_year_to)) >= l_next_year_to) then 'Main'
when (trunc(qq.start_date_active) between l_last_year_from and l_last_year_to) and
( trunc(nvl(qq.end_date_active,l_last_year_to)) >= l_last_year_to ) then 'EOS Return'
end )col18,
--Local variables
(case when (trunc(qq.start_date_active) between l_next_year_from and l_next_year_to) and
( trunc(nvl(qq.end_date_active,l_next_year_to)) >= l_cur_year_to ) then 'N'
else
'Y' end ) col21
FROM qp.qp_list_headers_b qlhb,
qp.qp_list_headers_tl qlht,
qp.qp_qualifiers qq,
qp_modifier_summary_v qs,
hz_cust_site_uses_all su,
hz_cust_acct_sites_all sa,
hz_cust_accounts hca
WHERE 1=1
and qlhb.LIST_TYPE_CODE = 'DLT'
and nvl(qlhb.active_flag,'Y') = 'Y'
and qlhb.list_header_id = qlht.list_header_id
AND qq.list_header_id = qlhb.list_header_id
and qq.list_type_code = qlhb.LIST_TYPE_CODE
and qq.QUALIFIER_CONTEXT = 'CUSTOMER'
and qs.list_header_id = qlhb.list_header_id
and qs.LIST_LINE_TYPE_CODE = 'DIS'
and su.site_use_id = qq.qualifier_attr_value --1064
AND su.cust_acct_site_id = sa.cust_acct_site_id
AND sa.cust_account_id = hca.cust_account_id ]';
--call Dynamic SQL function
l_cursor := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(l_cursor, p_QUERY , DBMS_SQL.NATIVE);
l_rows := DBMS_SQL.EXECUTE(l_cursor);
Any help will be much appreciated.
iI guess I should use DBMS_SQL.BIND_VARIABLE to bind all variables seperately so not to mess with query1) What is the error you get?
2) If you use bind variables inside a query, you should prefix them with colons, so use :l_cur_year_from etc.
3) Why are you using dbms_sql instead of native dynamic sql and/or ref-cursors?
Toon
Maybe you are looking for
-
How to pull and display the document from an external storage medium?
HI, We are having one external storage medium for SAP documents. In our case it is filenet server. My concern is . How can we pull the doc from the filenet server (external storage medium)?. I am in need, how and what an abap development team needs t
-
Safari quits while trying to open
I have a new MacBook Pro to which I migrated applications and folders from my old MacBook Pro and now Safari will not open at all on the new machine. The Fault report reads: Process: Safari [1335] Path: /Applications/Safari.app/Con
-
Hi, I use DAD to upload and download DOC files from BLOB in JSPs,How can I convert DOC format to HTML format in downloading and display tithe files in IE browser? Best Regard, Yanming Xu
-
How do you auto generate series of dates or numbers in iPad Numbers?
Hi, I am using Numbers app on the latest iPad Air 2 running iOS 8. On the OS X version of Numbers, you could type the first two numbers in two rows and drag them while they are both selected to generate the rest of the numbers or dates or formulas ac
-
Hi All, I have a formula like this NODIV(100((A-B)/A)) But this is showing that syntax errors are there. Please let me know if any error is and is it correct? Thanks in advance Sravani