Sysdate in pl/sql
Hi all
I am executing following pl/sql block
DECLARE
hiredate emp.hiredate%TYPE;
sysdate hiredate%TYPE;
empno emp.empno%TYPE := 7839;
BEGIN
SELECT hiredate,sysdate
INTO hiredate,sysdate
FROM emp
WHERE empno = 7839;
dbms_output.put_line(hiredate||' '||sysdate);
END;
17-NOV-81
only hiredate id displaying at runtime , why sysdate is not displaying?????
but if i could not declare sysdate in PL/SQL block, it should not get compiled.The point is, you can declare sysdate in your pl/sql block and because of the way that oracle handles naming resolution, you will not get the result you appear to be looking for as your local delcaration of SYSDATE will override the global declaration of SYSDATE
SQL> DECLARE
2
3 sysdate date;
4 BEGIN
5 SELECT
6 sysdate
7 INTO
8 sysdate
9 FROM
10 dual;
11
12 dbms_output.put_line(NVL(sysdate,TO_DATE('01/01/2005','dd/mm/yyyy')));
13 END;
14 /
01-JAN-05
PL/SQL procedure successfully completed.
SQL> DECLARE
2
3 sysdate date :=TO_DATE('31/12/2005','dd/mm/yyyy');
4 BEGIN
5 SELECT
6 sysdate
7 INTO
8 sysdate
9 FROM
10 dual;
11
12 dbms_output.put_line(NVL(sysdate,TO_DATE('01/01/2005','dd/mm/yyyy')));
13 END;
14 /
31-DEC-05
PL/SQL procedure successfully completed.
SQL> DECLARE
2
3 sysdate date;
4 BEGIN
5 -- SELECT
6 -- sysdate
7 -- INTO
8 -- sysdate
9 -- FROM
10 -- dual;
11 --
12 dbms_output.put_line(NVL(sysdate,TO_DATE('01/01/2005','dd/mm/yyyy')));
13 END;
14 /
01-JAN-05
PL/SQL procedure successfully completed.
SQL> DECLARE
2
3 -- sysdate date;
4 BEGIN
5 -- SELECT
6 -- sysdate
7 -- INTO
8 -- sysdate
9 -- FROM
10 -- dual;
11 --
12 dbms_output.put_line(NVL(sysdate,TO_DATE('01/01/2005','dd/mm/yyyy')));
13 END;
14 /
14-SEP-05
PL/SQL procedure successfully completed.
SQL> DECLARE
2
3 sys_date date;
4 BEGIN
5 SELECT
6 sysdate
7 INTO
8 sys_date
9 FROM
10 dual;
11
12 dbms_output.put_line(NVL(sys_date,TO_DATE('01/01/2005','dd/mm/yyyy')));
13 END;
14 /
14-SEP-05
PL/SQL procedure successfully completed.Also, if you get rid of your declaration of sysdate and try the same query again, you will get an error:
SQL> DECLARE
2
3 -- sysdate date;
4 BEGIN
5 SELECT
6 sysdate
7 INTO
8 sysdate
9 FROM
10 dual;
11
12 dbms_output.put_line(NVL(sysdate,TO_DATE('01/01/2005','dd/mm/yyyy')));
13 END;
14 /
sysdate
ERROR at line 8:
ORA-06550: line 8, column 3:
PLS-00321: expression 'SYSDATE' is inappropriate as the left hand side of an
assignment statement
ORA-06550: line 5, column 2:
PL/SQL: SQL Statement ignoredHave a look at the docs for more info on how oracle handles naming resolution:
http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96624/d_names.htm#3693
HTH
David
Similar Messages
-
Problem in loading "SYSDATE" through the sql loader
Hi experts,
I have problems in inserting the sysdate while loading the data from the flatfile. The details of the control file is as follows:
OPTIONS (ERRORS=100, SILENT=(FEEDBACK))
LOAD DATA
INFILE 'c:\sample.dat'
APPEND
INTO TABLE RTD_TMO_MODEL_SCORES_BI
FIELDS TERMINATED BY ','
--OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(RECORD_ID "SQ_RTD_TMO_MODEL_SCORES_BI.NEXTVAL",
MODEL_ID,
BAN,
MISDN,
INSERT_DT date "SYSDATE",
SCORING_JOB_ID,
SCORE_ENTITY_ID,
MODEL_SCORE_DECIMAL,
MODEL_SCORE_INTEGER,
MODEL_SCORE_CHAR,
ANCHOR_DT date "YYYYMMDD",
RUN_DT date "YYYYMMDD")
The data values for columns RECORD_ID and INSERT_DT are not present in the data file. The first one is planned to insert with the sequence created in database. While the second one is inserted based on the SYSDATE function of the database.
Please guide me how to specify so that I can insert the sysdate for the INSERT_DT column.
Thanks in Advance
VenkatInstead of this
INSERT_DT date "SYSDATE",
Try this
INSERT_DT SYSDATE, -
Calling PL/SQL API from OAF
Hi all,
i have a stored procedure(xyz) in a package (abc) as below:
procedure xyz
(p_validate in boolean default false
,p_ptnl_ler_for_per_id out nocopy number
,p_csd_by_ptnl_ler_for_per_id in number default null
,p_lf_evt_ocrd_dt in date default null
,p_trgr_table_pk_id in number default null
,p_ptnl_ler_for_per_stat_cd in varchar2 default null
,p_ptnl_ler_for_per_src_cd in varchar2 default null
,p_mnl_dt in date default null
,p_enrt_perd_id in number default null
,p_ler_id in number default null
,p_person_id in number default null
,p_business_group_id in number default null
,p_dtctd_dt in date default null
,p_procd_dt in date default null
,p_unprocd_dt in date default null
,p_voidd_dt in date default null
,p_mnlo_dt in date default null
,p_ntfn_dt in date default null
,p_request_id in number default null
,p_program_application_id in number default null
,p_program_id in number default null
,p_program_update_date in date default null
,p_object_version_number out nocopy number
,p_effective_date in date) is
End;
In oaf i am calling this stored procedure in a function as below:
public String callToApi(String event_date, String event_name, String person_id) {
int ler_pk = 0;
int ovn = 0;
LifeEventIdVOImpl LifeEventIdVOObj = getLifeEventIdVO1();
LifeEventIdVOObj.setWhereClauseParams(null);
LifeEventIdVOObj.setWhereClauseParam(0, event_name);
LifeEventIdVOObj.executeQuery();
String ler_id = LifeEventIdVOObj.first().getAttribute("LerId").toString();
try {
OracleCallableStatement oracleCallableStatement = null;
OADBTransactionImpl txn =
(OADBTransactionImpl)getOADBTransaction();
String statement =
"BEGIN" + " abc.xyz(" +
" p_validate => :1" +
" ,p_ptnl_ler_for_per_id => :2" +
" ,p_csd_by_ptnl_ler_for_per_id => NULL" +
" ,p_lf_evt_ocrd_dt => :3" +
" ,p_trgr_table_pk_id => NULL" +
" ,p_ptnl_ler_for_per_stat_cd => 'DTCTD'" +
" ,p_ptnl_ler_for_per_src_cd => NULL" +
" ,p_mnl_dt => NULL" +
" ,p_enrt_perd_id => NULL" +
" ,p_ler_id => :4" +
" ,p_person_id => :5" +
" ,p_business_group_id => 0" +
" ,p_dtctd_dt => :6" +
" ,p_procd_dt => NULL" +
" ,p_unprocd_dt => NULL" +
" ,p_voidd_dt => NULL" +
" ,p_mnlo_dt => NULL" +
" ,p_ntfn_dt => :7" +
" ,p_request_id => NULL" +
" ,p_program_application_id => NULL" +
" ,p_program_id => NULL" +
" ,p_program_update_date => NULL" +
" ,p_object_version_number => :8" +
" ,p_effective_date => :9);" + " END;";
java.util.Date sysdate = new java.util.Date();
java.sql.Date today_date = new java.sql.Date(sysdate.getTime());
java.sql.Date life_event_date = new java.sql.Date(new java.util.Date(event_date).getTime());
oracleCallableStatement = (OracleCallableStatement)txn.createCallableStatement(statement, DBTransaction.DEFAULT);
oracleCallableStatement.setBoolean(1, Boolean.FALSE);
oracleCallableStatement.registerOutParameter(2, Types.INTEGER);
oracleCallableStatement.setDate(3, life_event_date);
oracleCallableStatement.setInt(4, Integer.parseInt(ler_id));
oracleCallableStatement.setInt(5, Integer.parseInt(person_id));
oracleCallableStatement.setDate(6, today_date);
oracleCallableStatement.setDate(7, today_date);
oracleCallableStatement.registerOutParameter(8, Types.INTEGER);
oracleCallableStatement.setDate(9, today_date);
oracleCallableStatement.execute();
ler_pk = oracleCallableStatement.getInt(2);
ovn = oracleCallableStatement.getInt(8);
System.out.println(ler_pk);
System.out.println(ovn);
catch (Exception e) {
e.printStackTrace();
return(ler_pk + "/" + ovn);
But i am getting an error as:
java.sql.SQLException: ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'xyz' ORA-06550: line 1, column 7: PL/SQL: Statement ignored
But i think i have provided the right set of inputs...
Please have a look and let me know where i am wrong....
its urgent.. please reply asapShivam,
Use below code & let us know whether still throws the same error.
try
Connection conn = getOADBTransaction().getJdbcConnection();
CallableStatement cstmt = conn.prepareCall
("{call xyz (:1, :2, :3)}");
System.out.println("1" + Id);
cstmt.setString(1, IjpId);
System.out.println("2" + EmpNum);
cstmt.setString(2, EmpNum );
System.out.println("3" + EmpPositionTitle);
cstmt.setString(3, EmpPositionTitle );
System.out.println("before calling");
cstmt.execute();
System.out.println("after calling");
cstmt.close();
catch(Exception e)
String message = "Error in Data Saving: " + e;
throw new OAException(message, OAException.ERROR);
}Regards,
Gyan -
Linking to SQL Server using DG4ODBC
Hi all,
I've configured Oracle 11g R1 for Windows 2003 Server 32-bit to connect to MS SQL Server 2005 through ODBC.
Following is the error I got when I try to access SQL Server by the db link in Oracle:
SQL> select sysdate from dual@sqls ;
select sysdate from dual@sqls
ERROR at line 1:
ORA-28545: error diagnosed by Net8 when connecting to an agent
Unable to retrieve text of NETWORK/NCR message 65535
ORA-02063: preceding 2 lines from SQLSThe ODBC link to the SQL Server was successfully tested.
The listener, however, returned error as shown below.
/* The file E:\Oracle\OraDb11g\hs\admin\initsqls.ora */
HS_FDS_CONNECT_INFO = sqls
HS_FDS_TRACE_LEVEL = 1
/* Listener.ora */
LISTENER =
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(SID_NAME=sqls)
(ORACLE_HOME=E:\Oracle\OraDb11g)
(PROGRAM=dg4odbc)
/* tnsnames.ora */
sqls =
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))
(CONNECT_DATA=(SID=sqls))
(HS=OK)
/* sqlnet.ora */
SQLNET.AUTHENTICATION_SERVICES= (NTS)
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT, HOSTNAME)
/* testing the connection */
E:\Oracle\OraDb11g\BIN>tnsping sqls
TNS Ping Utility for 32-bit Windows: Version 11.1.0.6.0 - Production on 14-JUN-2
010 09:36:35
Copyright (c) 1997, 2007, Oracle. All rights reserved.
Used parameter files:
E:\oracle\OraDb11g\network\admin\sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION= (ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT
=1521)) (CONNECT_DATA=(SID=sqls)) (HS=OK))
OK (20 msec)
/* code to create the db link */
CREATE PUBLIC DATABASE LINK sqls CONNECT TO
"SRV11\Administrator" IDENTIFIED BY "ospassword" using 'sqls';
/* Contents of Listener Log */
Mon Jun 14 11:25:59 2010
14-JUN-2010 11:25:59 * trc_level * 0
14-JUN-2010 11:26:06 * (CONNECT_DATA=(CID=(PROGRAM=)(HOST=)(USER=Administrator))(COMMAND=status)(ARGUMENTS=64)(SERVICE=LISTENER)(VERSION=185599488)) * status * 0
Mon Jun 14 11:26:22 2010
14-JUN-2010 11:26:22 * (CONNECT_DATA=(SID=sqls)(CID=(PROGRAM=)(HOST=WORKGROUP\SRV10)(USER=SRV10\Administrator))) * (ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=3333)) * establish * sqls * 12505
TNS-12505: TNS:listener does not currently know of SID given in connect descriptorAny hint is appreciated.You did create a DUAL table in the Sqlserver database?
Sybrand Bakker
Senior Oracle DBA -
Hi,
I am using oracle 10.2.0 on linux. my database is performing slow user complain.
I use addm to find the issue. This is my addm for that period.
FINDING 2: 69% impact (903 seconds)
Individual database segments responsible for significant user I/O wait were
found.
RECOMMENDATION 1: Segment Tuning, 69% benefit (903 seconds)
ACTION: Investigate application logic involving I/O on TABLE
"MPE_SCHEMA3.SUBSCRIBERS" with object id 25149.
RELEVANT OBJECT: database object with id 25149
RATIONALE: The I/O usage statistics for the object are: 0 full object
scans, 46058 physical reads, 1 physical writes and 0 direct reads.
RATIONALE: The SQL statement with SQL_ID "4bqrym38a9ths" spent
significant time waiting for User I/O on the hot object.
RELEVANT OBJECT: SQL statement with SQL_ID 4bqrym38a9ths
SELECT COUNT(*) FROM "SUBSCRIBERS" "A1" WHERE
"A1"."LS_CHG_DTE_CUS">:B3 AND "A1"."LS_CHG_DTE_CUS"<=:B2 AND
"A1"."CONNECT_DTE_SBB">=TRUNC(SYSDATE@!)-:B1 AND
"A1"."CONNECT_DTE_SBB"<=TRUNC(SYSDATE@!)
RATIONALE: The SQL statement with SQL_ID "51b5swtaaz42r" spent
significant time waiting for User I/O on the hot object.
RELEVANT OBJECT: SQL statement with SQL_ID 51b5swtaaz42r
SELECT "CUST_ACCT_NO","SUB_ACCT_NO","PHONE_NO","LS_CHG_DTE_CUS" FROM
"SUBSCRIBERS" "SC" WHERE "LS_CHG_DTE_CUS"<:1 AND :2="CUST_ACCT_NO"
AND :3="SUB_ACCT_NO" AND :4="PHONE_NO" AND :5<"LS_CHG_DTE_CUS"
SYMPTOMS THAT LED TO THE FINDING:
SYMPTOM: Wait class "User I/O" was consuming significant database time.
(72% impact [943 seconds])
FINDING 3: 67% impact (889 seconds)
SQL statements consuming significant database time were found.
RECOMMENDATION 1: SQL Tuning, 55% benefit (729 seconds)
ACTION: Run SQL Tuning Advisor on the SQL statement with SQL_ID
"4bqrym38a9ths".
RELEVANT OBJECT: SQL statement with SQL_ID 4bqrym38a9ths and
PLAN_HASH 2462067897
SELECT COUNT(*) FROM "SUBSCRIBERS" "A1" WHERE
"A1"."LS_CHG_DTE_CUS">:B3 AND "A1"."LS_CHG_DTE_CUS"<=:B2 AND
"A1"."CONNECT_DTE_SBB">=TRUNC(SYSDATE@!)-:B1 AND
"A1"."CONNECT_DTE_SBB"<=TRUNC(SYSDATE@!)
RATIONALE: SQL statement with SQL_ID "4bqrym38a9ths" was executed 1
times and had an average elapsed time of 725 seconds.
RECOMMENDATION 2: SQL Tuning, 14% benefit (182 seconds)
ACTION: Run SQL Tuning Advisor on the SQL statement with SQL_ID
"51b5swtaaz42r".
RELEVANT OBJECT: SQL statement with SQL_ID 51b5swtaaz42r and
PLAN_HASH 2608341829
SELECT "CUST_ACCT_NO","SUB_ACCT_NO","PHONE_NO","LS_CHG_DTE_CUS" FROM
"SUBSCRIBERS" "SC" WHERE "LS_CHG_DTE_CUS"<:1 AND :2="CUST_ACCT_NO"
AND :3="SUB_ACCT_NO" AND :4="PHONE_NO" AND :5<"LS_CHG_DTE_CUS"
RATIONALE: SQL statement with SQL_ID "51b5swtaaz42r" was executed 19649
times and had an average elapsed time of 0.0083 seconds.
FINDING 4: 67% impact (882 seconds)
Individual SQL statements responsible for significant user I/O wait were
found.
RECOMMENDATION 1: SQL Tuning, 55% benefit (729 seconds)
ACTION: Run SQL Tuning Advisor on the SQL statement with SQL_ID
"4bqrym38a9ths".
RELEVANT OBJECT: SQL statement with SQL_ID 4bqrym38a9ths and
PLAN_HASH 2462067897
SELECT COUNT(*) FROM "SUBSCRIBERS" "A1" WHERE
"A1"."LS_CHG_DTE_CUS">:B3 AND "A1"."LS_CHG_DTE_CUS"<=:B2 AND
"A1"."CONNECT_DTE_SBB">=TRUNC(SYSDATE@!)-:B1 AND
"A1"."CONNECT_DTE_SBB"<=TRUNC(SYSDATE@!)
RATIONALE: SQL statement with SQL_ID "4bqrym38a9ths" was executed 1
times and had an average elapsed time of 725 seconds.
RATIONALE: Average time spent in User I/O wait events per execution was
720 seconds.
RECOMMENDATION 2: SQL Tuning, 14% benefit (182 seconds)
ACTION: Run SQL Tuning Advisor on the SQL statement with SQL_ID
"51b5swtaaz42r".
RELEVANT OBJECT: SQL statement with SQL_ID 51b5swtaaz42r and
PLAN_HASH 2608341829
SELECT "CUST_ACCT_NO","SUB_ACCT_NO","PHONE_NO","LS_CHG_DTE_CUS" FROM
"SUBSCRIBERS" "SC" WHERE "LS_CHG_DTE_CUS"<:1 AND :2="CUST_ACCT_NO"
AND :3="SUB_ACCT_NO" AND :4="PHONE_NO" AND :5<"LS_CHG_DTE_CUS"
RATIONALE: SQL statement with SQL_ID "51b5swtaaz42r" was executed 19649
times and had an average elapsed time of 0.0083 seconds.
RATIONALE: Average time spent in User I/O wait events per execution was
0.0082 seconds.
SYMPTOMS THAT LED TO THE FINDING:
SYMPTOM: Wait class "User I/O" was consuming significant database time.
(72% impact [943 seconds])I know SUBSCRIBERS is the table which is creating problems. we have heavy insert, update and delete on this table this table have 4121886 records and no pertitions.
As per my observation pertitioning the table can help to improve the performence.
I am looking for experts suggestion. what is creating problem, how to resolve the issue, what else can be done other that partition the table
Thanks
umesh
Edited by: Umesh Sharma on Dec 21, 2009 11:38 PM
Edited by: Umesh Sharma on Dec 21, 2009 11:47 PMI often say here in forums that a solution is only as good as the problem definition.
The original analysis you posted shows mostly symptoms. For example:
RATIONALE: SQL statement with SQL_ID "4bqrym38a9ths" was executed 1
times and had an average elapsed time of 725 seconds.Of what benefit will it be for a 24h processing period by shaving off a few seconds from a 725 second SQL that is executed only once in that period?
Is there I/O contention? Serialised I/O is by nature slow. A process doing 46058 physical reads is unlikely to be considered fast, as there is an inherent latency per I/O call. This not necessarily mean I/O contention. The I/O subsystem could be handling this as fast as possible, with sufficient spare capacity to serve an additional 50% load.
There are numerous factors to consider when dealing with performance. I would not be comfortable only using output from such a report to drive performance tuning. Software and hardware systems are not that simple - a holistic view is needed before isolating specific areas and focusing on those only as the problem areas that need to be addressed. -
I just wanted to note this on the forum..
I'm using Apex 3.0.1.00.08
My DEV environment has just been upgraded from 10g version 10.2.0.2.0 to 10.2.0.4.0.
I created the following process to select some values into some items on my Form page.
select MAX(STAT_YEAR+1)
, pcd.pct_id
, pcd.stat_type_id
, pcd.stat_period_type_id
, pcd.measurement_id
into :P11_STAT_YEAR
, :P11_PCT_ID
, :P11_STAT_TYPE_ID
, :P11_STAT_PERIOD_TYPE_ID
, :P11_MEASUREMENT_ID
from plant_commodity_data pcd
, stat_type stt
where pcd.STAT_TYPE_ID = stt.STAT_TYPE_ID
and pcd.pct_id = :P0_PCT_ID
and stt.stat_type = 'PRD'
group by pcd.pct_id
, pcd.stat_type_id
, pcd.stat_period_type_id
, pcd.measurement_id;The process should run conditionally if there was at least one row to select...
So I copied the SQL into the Process condition, removed the "into" section and set the condition type to be "Exists (SQL query retruns at least one row) ...
select MAX(STAT_YEAR+1)
, pcd.pct_id
, pcd.stat_type_id
, pcd.stat_period_type_id
, pcd.measurement_id
from plant_commodity_data pcd
, stat_type stt
where pcd.STAT_TYPE_ID = stt.STAT_TYPE_ID
and pcd.pct_id = :P0_PCT_ID
and stt.stat_type = 'PRD'
group by pcd.pct_id
, pcd.stat_type_id
, pcd.stat_period_type_id
, pcd.measurement_id;This worked perfectly until the DEV environment was upgraded from 10g version 10.2.0.2.0 to 10.2.0.4.0.
The condition would fire even if there were no rows returning.
I pasted the condition code into SQL Developer connected to the DEV (10.2.0.4.0) environment and it returned no rows.
To solve the problem, I removed the MAX.
You can test this using this code if you have access to the two versions... select MAX(1)
, sysdate
, 'Gus'
from dual
where 1 = 2
group by sysdate, 2Now I know the MAX isn't required in the condition as I'm just trying to find out if any rows exist, but it was there as I copied the code in... I was just wondering why this happened between 10.2.0.2.0 and 10.2.0.4.0?
Gus..Hi Gus,
try to execute
select count(*) from dual where exists (select MAX(1)
, sysdate
, 'Gus'
from dual
where 1 = 2
group by sysdate, 2)in SQL Developer. The above statement is generated by APEX for an "Exists (SQL query retruns at least one row)". Can't test it, because I don't have a 10.2.0.4.0 at hand.
Does SQL Developer now show the same behavior?
Patrick
My APEX Blog: http://www.inside-oracle-apex.com
The APEX Builder Plugin: http://builderplugin.oracleapex.info/
The ApexLib Framework: http://apexlib.sourceforge.net/ -
SQL Loader- Default value is not inserted in table by direct method
Hi All,
I am trying to load data from a file to a table by SQL Loader. There is a particular date column which I am not loading from the File but have used a Default constraint to put SYSDATE in it. When I am using direct method load then it is not inserting nothin in this column but in conventional method it is inserting SYSDATE. But I want to do the load by direct method. Can anybody provide me a solution as how to load default value in direct method?
Thanks & regards.
SudiptaFor this special case, you can specify:
column_name SYSDATE
in your SQL*Loader control file. -
Using SQL Statements in Error Exceptions
Is there any way to include SQL statements within my catch routines (i.e.
catch (java.io.IOException ex) {
System.out.println("An error occurred whilst writing to the message buffer: " + ex);
#sql { INSERT INTO DEBUG_TBL(CURRENT_DT,PROGRAM_ID,DEBUG__MESG) VALUES (SYSDATE,'TEST',:ex) };
#sql { COMMIT };
As it stands I get the following error upon compile:
Error: Unsupported Java type for host item (at position#1): java.io.IOException
Any help would be greatly appreciated.
Thx,
Boybles
nullYou can use SQL statements in your catch blocks, just not SQL statements that use Java types which do not map to SQL.
You cannot pass exceptions from Java to SQL. You can catch a SQL exceptions as a SQLException in Java. However, any exception that is thrown by a Java Stored Procedure (including SQLException) is rendered as an "Uncaught Java exception" in SQL.
When you receive a SQLException there is information about the originator, the error message, etc. in the exception object. See:
http://technet.oracle.com/docs/products/oracle8i/doc_library/817_doc/java.817/a83723/keyprog5.htm#1004462
While you cannot insert a Java exception per se into a table, you can extract the message string(s)/code and insert that in a table. -
hi all,
Can anyone let me know how to display the number in the following manner thru sql query.
Actual value is 20 Then the output to be : 00002000
if the value is 20.34 Then the output to be : 000020.34 Thanks in advance.CCYYMMDDThere is. Give the centure, year, month and day.
SQL> select to_char(sysdate,'CCYYMMDD') from dual;
TO_CHAR(
21070128
if so wht the use of it.Just like it, I don't know, since it may have confusing against the year 2107...
But maybe like this will be more properly :
SQL> select to_char(sysdate,'CCth, YYYYMMDD') from dual
SQL> /
TO_CHAR(SYSDAT
21ST, 20070128
SQL> Nicolas. -
Reading Dates and Timestamps created by PL/SQL
Hello,
This is probably a FAQ (or stating the obvious) but I want to make sure I've got the right idea about things...
I recently noticed that our Java app reads dates/timestamps incorrectly from the database. Any date set using 'SYSDATE' in PL/SQL is an hour out when read by Java. This is because we are now in BST and the object read back by the JDBC driver thinks the timezone is GMT.
From reading around it seems that the DATE and TIMESTAMP types in Oracle don't persist timezone information. Fair enough, but to me this makes it dangerous to use SYSDATE at all in PL/SQL procedures.
Previously I've never relied on the database itself to generate timestamps so dates have always been stored as UTC. I'm currently using SYS_EXTRACT_UTC(SYSTIMESTAMP) when inserting data in to tables and basically wondering if this is the common way of achieving accuracy.
(using types such as "TIMESTAMP WITH LOCAL TIME ZONE" seem to have their own annoyances in JDBC so I've opted to avoid those)
Thanks.Tom,
This may be helpful...
http://www.javaworld.com/javaworld/jw-10-2003/jw-1003-time.html
Good Luck,
Avi. -
Can't evaluate functions or SQL
Hmmm, I'm wondering what I'm doing wrong here:
Using a text box and
select sysdate from dual
SQL query returns date
(no, I'm not using #)
I'm logged in as PORTAL30, have created a new form and am using 3.0.8 against 8.1.7 ... but the text area is empty when I run the form ...
I also can't get user or portal30.wwctx_api.get_user functions to work ...
Ideas?Doug,
Is this form item by any chance not part of the base table?
If it's not then you will need a Javascript function to populate the field. Non-table items do not support database-side default values yet.
Thanks,
Dmitry -
Hi all!
What does TRUNC(SYSDATE) do?
I didn't find any difference when I executed the following queries.
1.
SQL> SELECT SYSDATE FROM dual;
SYSDATE
20-JUL-2002 10:12:35 PM
2.
SQL> edit
Wrote file afiedt.buf
1* SELECT TRUNC(SYSDATE) FROM dual
SQL> /
TRUNC(SYSDATE)
20-JUL-2002 12:00:00 AM
Please help.Or to re-state what you've discovered. TRUNC(SYSDATE) removes the time element from the date. Any date that has been fed through the TRUNC function has a date of midnight. Consequently, TRUNC(SYSDATE) is always earlier than SYSDATE (unless you execute it on the very moment of midnight).
Cheers, APC -
Concurrent Program not executing
Hi All,
I have created new custom concurrent program of type SQL*Plus to purge the data. To my surprize when I submit the program, program is not getting executed, which I can confirm saying the data is not getting deleted. Also the log messages mentioned script is also not displayed in the LOG.
No debug message is displayed in neither LOG nor OUTPUT.
Executable File Name is correctly given and taken care of all other mandatory stuff while registration.
Bleow the script:
I am passing Number of Days ( 500 ) as parameter to this program.
So here &1 = 500:
DECLARE
L_deleted_rec_cnt NUMBER;
BEGIN
fnd_file.put_line ( fnd_file.LOG, ' Conc Program Starts');
DELETE
FROM xxX_TABLE_NAME
WHERE TRUNC (creation_date) < TRUNC (SYSDATE- &1);
L_deleted_rec_cnt := SQL%ROWCOUNT;
IF L_deleted_rec_cnt > 0 THEN
COMMIT;
fnd_file.put_line ( fnd_file.LOG, L_deleted_rec_cnt||' Records purged');
ELSE
fnd_file.put_line ( fnd_file.LOG, ' No Records to purge');
END IF;
fnd_file.put_line ( fnd_file.OUTPUT, ' Conc Program End');
EXCEPTION
WHEN OTHERS THEN
fnd_file.put_line (fnd_file.LOG, 'Error in purging '||SQLCODE||' '||SQLERRM);
END;
Please advise.
Regards,
RamIt is 11i and the LOG is showing as Concurrent Program executed succesfully. THere is not error reported in the LOG.
And also nothing writter to OUT file also.
Content in LOG file:
XXXX Customer Advocacy: Version : 1.0 - Development
Copyright (c) 1979, 1999, Oracle Corporation. All rights reserved.
XXCC module: XXXX Error Log Purge
Current system time is 28-DEC-2009 04:55:46
+-----------------------------
| Starting concurrent program execution...
+-----------------------------
Arguments
450
Start of log messages from FND_FILE
End of log messages from FND_FILE
Executing request completion options...
------------- 1) PRINT -------------
Printing output file.
Request ID : 52374634
Number of copies : 0
Printer : noprint
Finished executing request completion options.
Concurrent request completed successfully
Current system time is 28-DEC-2009 04:55:47
Content in Out FIle:
Input truncated to 2 characters
Regards,
Ram -
Received error when using Execute_Immediate proc in Oracle 8.0
Hi,
I was trying to use the execute_immediate proc (slightly
revised, for testing). When I run it with a 'Delete' statement
in it (or passed in), it works fine. But, when I use
an 'Update' or 'Insert' statement in it, I get the error below,
even though the proc compiled okay and it's in the database okay.
SQL> exec Exec_Immed;
begin Exec_Immed; end;
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00905: object TEST.EXEC_IMMED is invalid
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
I tried using both the SQL stmts below (one at a time), but got
the same error.
CREATE OR REPLACE PROCEDURE Exec_Immed /*(v_SQLStmt IN VARCHAR2)
IS
v_CursorID INTEGER DEFAULT DBMS_SQL.OPEN_CURSOR;
v_SQLStmt VARCHAR2(100);
v_RetRows INTEGER;
BEGIN
v_SQLStmt := 'Update emp SET fname = ''David'' WHERE empno =
40';
v_SQLStmt := 'Insert into softlookup
(softno,softname,updatedon,updatetype) values
(50,''VS7'',sysdate,''A'')';
DBMS_SQL.PARSE (v_CursorID, v_sqlstmt, DBMS_SQL.native);
v_RetRows := DBMS_SQL.EXECUTE(v_CursorID);
DBMS_SQL.CLOSE_CURSOR(v_CursorID);
END;The simplest way to do what you are doing is to use a SQL
statement by itself, either from the SQL prompt or from a .sql
file:
SQL> Update emp
2 SET ename = 'David'
3 WHERE empno = 40
4 /
0 rows updated.
SQL> Insert into softlookup
2 (softno,softname,updatedon,updatetype)
3 values (50,'VS7',sysdate,'A')
4 /
1 row created.
Or, if you want to do it from an anonymous pl/sql block:
SQL> BEGIN
2 Update emp
3 SET ename = 'David'
4 WHERE empno = 40;
5 Insert into softlookup
6 (softno,softname,updatedon,updatetype)
7 values (50,'VS7',sysdate,'A');
8 END;
9 /
PL/SQL procedure successfully completed.
Or, if you want to do it in a procedure:
SQL> CREATE OR REPLACE PROCEDURE procedure_name
2 AS
3 BEGIN
4 Update emp
5 SET ename = 'David'
6 WHERE empno = 40;
7 Insert into softlookup
8 (softno,softname,updatedon,updatetype)
9 values (50,'VS7',sysdate,'A');
10 END procedure_name;
11 /
Procedure created.
SQL> EXEC procedure_name
PL/SQL procedure successfully completed.
If you want to use DBMS_SQL to do it, even though it is
unnecessary:
SQL> CREATE OR REPLACE PROCEDURE procedure_name
2 IS
3 v_CursorID INTEGER DEFAULT DBMS_SQL.OPEN_CURSOR;
4 v_RetRows INTEGER;
5 v_SQLStmt VARCHAR2 (4000);
6 BEGIN
7 v_SQLStmt := 'Update emp
8 SET ename = ''David''
9 WHERE empno = 40';
10 DBMS_OUTPUT.PUT_LINE (v_SQLStmt);
11 DBMS_SQL.PARSE (v_CursorID, v_SQLStmt, DBMS_SQL.NATIVE);
12 v_RetRows := DBMS_SQL.EXECUTE (v_CursorID);
13 DBMS_SQL.CLOSE_CURSOR (v_CursorID);
14 v_SQLStmt := 'Insert into softlookup '
15 || ' (softno,softname,updatedon,updatetype) '
16 || ' values (50,''VS7'',sysdate,''A'')';
17 v_CursorID := DBMS_SQL.OPEN_CURSOR;
18 DBMS_OUTPUT.PUT_LINE (v_SQLStmt);
19 DBMS_SQL.PARSE (v_CursorID, v_SQLStmt, DBMS_SQL.NATIVE);
20 v_RetRows := DBMS_SQL.EXECUTE (v_CursorID);
21 DBMS_SQL.CLOSE_CURSOR (v_CursorID);
22 END procedure_name;
23 /
Procedure created.
SQL> EXEC procedure_name
Update emp
SET ename = 'David'
WHERE empno =
40
Insert into softlookup (softno,softname,updatedon,updatetype)
values
(50,'VS7',sysdate,'A')
PL/SQL procedure successfully completed.
Since you are using Oracle 8.0 and cannot use EXECUTE IMMEDIATE,
if you want to use some variation, which is also unnecessary,
then you can do something like I have shown below. Note that
the Exec_Immed procedure needs to be a procedure all by itself
and not be modified. Otherwise, you are defeating the purpose
of substituting it for EXECUTE IMMEDIATE and not having to
duplicate code. The idea of using the Exec_Immed is to only
create that procedure which contains all of the DBMS_SQL once,
then use the really simple code below that to execute SQL
statements from a pl/sql block. If you are going to modify it,
then you might as well use the DBMS_SQL method listed above. In
the version below, I have used the variable names and so forth
that you have substituted for the original, as much as possible:
SQL> CREATE OR REPLACE PROCEDURE Exec_Immed
2 (v_SQLStmt IN VARCHAR2)
3 IS
4 v_CursorID INTEGER DEFAULT DBMS_SQL.OPEN_CURSOR;
5 v_RetRows INTEGER;
6 BEGIN
7 DBMS_SQL.PARSE (v_CursorID, v_SQLStmt, DBMS_SQL.NATIVE);
8 v_RetRows := DBMS_SQL.EXECUTE (v_CursorID);
9 DBMS_SQL.CLOSE_CURSOR (v_CursorID);
10 END Exec_Immed;
11 /
Procedure created.
Then, to use your Exec_Immed procedure from an anonymous pl/sql
block:
SQL> BEGIN
2 Exec_Immed ('Update emp
3 SET ename = ''David''
4 WHERE empno = 40');
5 Exec_Immed ('Insert into softlookup
6 (softno,softname,updatedon,updatetype)
7 values (50,''VS7'',sysdate,''A'')');
8 END;
9 /
PL/SQL procedure successfully completed.
Or, to call your Exec_Immed procedure from another procedure:
SQL> CREATE OR REPLACE PROCEDURE procedure_name
2 AS
3 BEGIN
4 Exec_Immed ('Update emp
5 SET ename = ''David''
6 WHERE empno = 40');
7 Exec_Immed ('Insert into softlookup
8 (softno,softname,updatedon,updatetype)
9 values (50,''VS7'',sysdate,''A'')');
10 END procedure_name;
11 /
Procedure created.
SQL> EXEC procedure_name
PL/SQL procedure successfully completed. -
Error while passing date parameter to the XML data definition
Hi All,
I have developed a BI publisher report using XML data definition & RTF template.
This data definition contains a SQL query in it's CDATA section and runs as a concurrent program(without RDF) . We are looking to pass a date parameter to the SQL query and its not accepting the date parameter. However, when we hardcode SYSDATE in the SQL query in place of the parameter, the report runs fine. In the log file it shows that the parameter is being treated in American date style and we are using DD-MON-RRRR format. I have tried to convert the date format however still the error exists.
What we did ?
Created a XML data definition which contains the SQL query in its CDATA section & p_rundate (DATE) parameter.
Registerd the XML data definition as concurrent program with EXECUTABLE= XDODTEXE and Output format as XML with p_date as a date parameter.
Looking for any available solution for the same.
Thanks.Hi All,
I have developed a BI publisher report using XML data definition & RTF template.
This data definition contains a SQL query in it's CDATA section and runs as a concurrent program(without RDF) . We are looking to pass a date parameter to the SQL query and its not accepting the date parameter. However, when we hardcode SYSDATE in the SQL query in place of the parameter, the report runs fine. In the log file it shows that the parameter is being treated in American date style and we are using DD-MON-RRRR format. I have tried to convert the date format however still the error exists.
What we did ?
Created a XML data definition which contains the SQL query in its CDATA section & p_rundate (DATE) parameter.
Registerd the XML data definition as concurrent program with EXECUTABLE= XDODTEXE and Output format as XML with p_date as a date parameter.
Looking for any available solution for the same.
Thanks.
Maybe you are looking for
-
Sending of dynpro SAPLSPRI 0100 not possible: No window system type is spe
Upon clicking dictionary search help PREM tagged to "Personnel Number" input field in Web Dynpro ABAP application, error message "Sending of dynpro SAPLSPRI 0100 not possible: No window system type is specified." is encountered. This error message is
-
Hello Labviewers, So I just hooked up a couple of Honeywell UDA2182 controllers to my computer using an ethernet connection. I've established communications using modbus (specifically the Datalogging and Supervisory Control module's Modbus I/O serve
-
Problem with Redeem and country
Hi ! When give my redemption code i have this message: "This card was purchased in a country that does not match your Adobe ID. You can try signing in with a different Adobe ID or get in touch with us if you need help." This my my good profile... Wha
-
JavaFX Pie Chart populate from existing collections
Hi. I have a Person object with the structure Person(firstname,lastname,email, salary) I would like to draw a chart with the columns email and salary. I maintain the collection of objects in ObservableList which is populating a TableView. To populate
-
IM SO ANNOYED WHY DID I PREORDER A WEEK IN ADVANCE AND THE DAY ITS OUT I HAVE TO PAY AGAIN I ORDERED THE SOMEBODY TO YOU EP BY THE VAMPS AND IT IS NOW TELLING ME I HAVE TO BUY IT AGAIN WHAT I AM SO UPSET HOW AM I SUPPOSE TO GET IT IVE TRIED AND TRIED