Help with SQL Date
Hi
How can I convert a string in 'YYYYMMDD' format to SQL date (in the format 'YYYYMMDD' and also 'YYYYMMDD HH24:MI:SS) to use in my SQL-query (for Oracle Database)
Thanks for your help
Praveen Padala
Hi
How can I convert a string in 'YYYYMMDD' format to
SQL date (in the format 'YYYYMMDD' and also 'YYYYMMDD
HH24:MI:SS) to use in my SQL-query (for Oracle
Database)
Thanks for your help
Praveen PadalaI've done quite a few dates from Java to an Oracle DB. I like to use the SimpleDateFormat class in the java.text packadge.
import java.text.*; //Use this import
//In your class
SimpleDateFormat myDateFormatter = new SimpleDateFormat("dd-MMM-yyyy", new Locale("en","US"));
//The .format method returns a string. With this format string it can be included in an SQL command
myDateFormatter.format(myDate);
You can also use a SimpleDateFormat object with the format of your other dates to get a Date object that can be given to the SimpleDateFormat object set up to format in Oracle compatable form.
myDate is an object of type Date.
Hope this helps!
Kevin.
Similar Messages
-
Please Help with sql.Date problem
I have spent alot of time on what I thought would be an otherwise simple task, and I beleive I am close to completion but I need some much needed help. I have posted various forms of my code to try and acheive the solution but the responses received have been limited.
I am trying to delete a record from a MS Access database where a Date/Time field in the database (Err_Date) equals a date entered by the user via a textbox.
I finally have gotten the correct record to delete from the database, but what is very strange is that Tomcat is throwing a 'java.lang.NullPointerException' error. Then when I re-open the database the correct record is deleted.
Here is my code:
<%@page import="java.sql.*"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%@ page import="java.util.Date"%>
<%
Connection con = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:errorlog", "admin", "");
catch(Exception e){
out.println(e.getMessage());
ResultSet rs=null;
Statement stmt=null;
try {
stmt=con.createStatement();
String end = request.getParameter("To");//FROM TEXTBOX
java.text.SimpleDateFormat df = new java.text.SimpleDateFormat ("dd/MM/yyyy");
java.util.Date d2 = df.parse(end);//CONVERT STRING TO UTIL DATE
java.sql.Date date2 = new java.sql.Date(d2.getTime());//CONVERT TO SQL
PreparedStatement stmnt = con.prepareStatement("DELETE FROM tblError WHERE Err_Date = ?");
stmnt.setDate(1, date2);
stmnt.executeUpdate();
stmnt.close();
//CLOSE RESULT SET
rs.close();
stmt.close();
con.close();
//CATCH EXCEPTIONS
catch (SQLException e) {
out.println(e.getMessage());
%>well, in case anyone ever runs into a problem this stupid again the solution is as follows.
the code to:
1. retrieve date from text box
2. covert string into util date
3. convert util date into sql date
4. delete from database
is all correct.
the problem is that I previously used String sql="SOME SQL DELETE" and then executed the result set, which of course I then had to close. This wasn't working so I switched to a Prepared Statement. I forgot to remove the 'rs.close()' statement in my code. So Tomcat was trying to close a result set that was never opened... -
Need help with SQL Query with Inline View + Group by
Hello Gurus,
I would really appreciate your time and effort regarding this query. I have the following data set.
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
Please Ignore '----', added it for clarity
I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
The query should return the following data set
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
The following is my query. I am kind of lost.
select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
from (
select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
from INVOICE
group by sequence_id,check_date, check_number, invoice_number, vendor_number
) A, INVOICE B
where A.sequence_id = B.sequence_id
Thanks,
NickIt looks like it is a duplicate thread - correct me if i'm wrong in this case ->
Need help with SQL Query with Inline View + Group by
Regards.
Satyaki De. -
Essbase Studio Error(1021001): Failed to Establish Connection With SQL Data
Hi.
I have trying to deploy a cube with Essbase Studio but I get the error: "*Error(1021001): Failed to Establish Connection With SQL Database Server*"
My environment is Linux 5, Oracle 11g and EPM 11.1.1.2. Oracle database and Essbase was installed with diferent users. In the .bash_profile of hypadmin user (that install Essbase) I have set the following variables
ORACLE_BASE=/u01/app/oracledb/product/11.1.0
ORACLE_HOME=$ORACLE_BASE/db_1
LD_LIBRARY_PATH=/usr/X11R6/lib:$ORACLE_HOME/lib:$LD_LIBRARY_PATH
ORACLE_HOSTNAME=devbi.sigfe2
PATH=$ORACLE_HOME/bin:$ORACLE_HOME/jdk/bin:$ORACLE_HOME/bin:/sbin:$ORACLE_HOME/opmn/bin:$PATH
ORACLE_SID=orcl
JAVA_HOME=/u01/app/installfiles/jdk1.5.0_19
In my pc (windows xp) I can open Essbase Studio console, do the connection to Oracle database, get tables and create minischema, mesures and hierarchies (I can see the preview of hierarchies). Also I can create cubes with EAS and can connect with MAXSHELL to essbase.
When I try to deploy the cube from Essbaes Studio y get the error "Error(1021001): Failed to Establish Connection With SQL Database Server".
The Essbase Studio Log File say:
+12:40:16 07/24/09 (admin-1) INFO Start creating outline in database "5.4.0.41:1423.POC_ESS.POC_ESS1"...+
+12:40:16 07/24/09 (admin-1) FINA Sign on Essbase by CSS token "5.4.0.41:1423" successfully...+
+12:40:16 07/24/09 (admin-1) INFO Start building dimension "DM_CIUDADES" ...+
+12:40:16 07/24/09 (admin-1) MÁS FINA Start creating rule file ...+
+12:40:16 07/24/09 (admin-1) INFO SQL statement has been created and put into rule file "/home/hypadmin/hyperion/products/Essbase/EssbaseStudio/Server/./ess_japihome/data/DM_CIU.rul"+
+12:40:16 07/24/09 (admin-1) INFO The query is "SELECT (CONCAT('reg_',CAST(cp_105."ID_REGIONPADRE" AS VARCHAR2(1000)))) as "REGION_PADRE", (CONCAT('reg_',CAST(cp_105."ID_REGION" AS VARCHAR2(1000)))) as "REGION_HIJO", cp_105."DE_REGION" as "REGION_HIJO.Default" FROM "POC"."DM_REGIONES_ESS3" cp_105 ORDER BY cp_105."DE_NIVEL" ASC, cp_105."ID_REGIONPADRE" ASC, cp_105."ID_REGION" ASC"+
+12:40:16 07/24/09 (admin-1) INFO Rule file has been created and saved as "/home/hypadmin/hyperion/products/Essbase/EssbaseStudio/Server/./ess_japihome/data/DM_CIU.rul"+
+12:40:16 07/24/09 (admin-1) FINA Essbase starts to add members to DM_CIUDADES dimensioin based on the rules file.+
+12:40:16 07/24/09 (admin-1) ADVERTENCIA (1021001): Error al establecer conexión con el servidor de bases de datos SQL. Consulte el registro para obtener más información.+
+12:40:16 07/24/09 (admin-1) ADVERTENCIA essbaseDriver.FailedToBuildDimensionException+
+12:40:16 07/24/09 (admin-1) GRAVE Unexpected exception in EssbaseExport prevented cube from being deployed+
-------------- Exception --------------
com.hyperion.cp.datasources.export.essbase.EssbaseDriverException: Failed to deploy Essbase cube
Thanks in advance to all that have any idea to help me to solve this issue.
A.S.Hi,
If you type database SID in lowercase, try to reenter iot in uppercase. Strange, but I and my colleagues encounter this behaviour many times. -
Need help with SQL*Loader not working
Hi all,
I am trying to run SQL*Loader on Oracle 10g UNIX platform (Red Hat Linux) with below command:
sqlldr userid='ldm/password' control=issue.ctl bad=issue.bad discard=issue.txt direct=true log=issue.log
And get below errors:
SQL*Loader-128: unable to begin a session
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux-x86_64 Error: 2: No such file or directory
Can anyone help me out with this problem that I am having with SQL*Loader? Thanks!
Ben PrusinskiHi Frank,
More progress, I exported the ORACLE_SID and tried again but now have new errors! We are trying to load an Excel CSV file into a new table on our Oracle 10g database. I created the new table in Oracle and loaded with SQL*Loader with below problems.
$ export ORACLE_SID=PROD
$ sqlldr 'ldm/password@PROD' control=prod.ctl log=issue.log bad=bad.log discard=discard.log
SQL*Loader: Release 10.2.0.1.0 - Production on Tue May 23 11:04:28 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL*Loader: Release 10.2.0.1.0 - Production on Tue May 23 11:04:28 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Control File: prod.ctl
Data File: prod.csv
Bad File: bad.log
Discard File: discard.log
(Allow all discards)
Number to load: ALL
Number to skip: 0
Errors allowed: 50
Bind array: 64 rows, maximum of 256000 bytes
Continuation: none specified
Path used: Conventional
Table TESTLD, loaded from every logical record.
Insert option in effect for this table: REPLACE
Column Name Position Len Term Encl Datatype
ISSUE_KEY FIRST * , CHARACTER
TIME_DIM_KEY NEXT * , CHARACTER
PRODUCT_CATEGORY_KEY NEXT * , CHARACTER
PRODUCT_KEY NEXT * , CHARACTER
SALES_CHANNEL_DIM_KEY NEXT * , CHARACTER
TIME_OF_DAY_DIM_KEY NEXT * , CHARACTER
ACCOUNT_DIM_KEY NEXT * , CHARACTER
ESN_KEY NEXT * , CHARACTER
DISCOUNT_DIM_KEY NEXT * , CHARACTER
INVOICE_NUMBER NEXT * , CHARACTER
ISSUE_QTY NEXT * , CHARACTER
GROSS_PRICE NEXT * , CHARACTER
DISCOUNT_AMT NEXT * , CHARACTER
NET_PRICE NEXT * , CHARACTER
COST NEXT * , CHARACTER
SALES_GEOGRAPHY_DIM_KEY NEXT * , CHARACTER
value used for ROWS parameter changed from 64 to 62
Record 1: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 2: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 3: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 4: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 5: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 6: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 7: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 8: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 9: Rejected - Error on table ISSUE_FACT_TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 10: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 11: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 12: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 13: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 14: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 15: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 16: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 17: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 18: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 19: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 20: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 21: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 22: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 23: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 24: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
Record 39: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
Column not found before end of logical record (use TRAILING NULLCOLS)
MAXIMUM ERROR COUNT EXCEEDED - Above statistics reflect partial run.
Table TESTLD:
0 Rows successfully loaded.
51 Rows not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.
Space allocated for bind array: 255936 bytes(62 rows)
Read buffer bytes: 1048576
Total logical records skipped: 0
Total logical records read: 51
Total logical records rejected: 51
Total logical records discarded: 0
Run began on Tue May 23 11:04:28 2006
Run ended on Tue May 23 11:04:28 2006
Elapsed time was: 00:00:00.14
CPU time was: 00:00:00.01
[oracle@casanbdb11 sql_loader]$
Here is the control file:
LOAD DATA
INFILE issue_fact.csv
REPLACE
INTO TABLE TESTLD
FIELDS TERMINATED BY ','
ISSUE_KEY,
TIME_DIM_KEY,
PRODUCT_CATEGORY_KEY,
PRODUCT_KEY,
SALES_CHANNEL_DIM_KEY,
TIME_OF_DAY_DIM_KEY,
ACCOUNT_DIM_KEY,
ESN_KEY,
DISCOUNT_DIM_KEY,
INVOICE_NUMBER,
ISSUE_QTY,
GROSS_PRICE,
DISCOUNT_AMT,
NET_PRICE,
COST,
SALES_GEOGRAPHY_DIM_KEY
) -
Want to create a recordset using this SQL statement but I get a msg that says Enter a Select statement. Seems it only recognizes Select as first part of the statement. This query runs fine in SQL. Anyway around this. Any help is greatly appreciated.
IF EXISTS (SELECT DISTINCT t_aven_dc_site.__NAME, t_aven_dc_site._CONS_ID,
CASE WHEN t_aven_dc_site_1._COMPANY_NAME IS NULL OR
t_aven_dc_site_1._COMPANY_NAME = ' '
THEN 'NA'
ELSE t_aven_dc_site_1._COMPANY_NAME END
AS Consultant
FROM t_aven_dc_contact
INNER JOIN t_aven_dc_site AS t_aven_dc_site_1 ON t_aven_dc_contact._INTERNID = t_aven_dc_site_1._INTERNID INNER JOIN
t_aven_dc_site ON t_aven_dc_site_1._SPS_ID = t_aven_dc_site._CONS_ID
WHERE
t_aven_dc_site._IDB_CLNT_ID_N = 716166 )
Select Distinct t_aven_dc_site_1._COMPANY_NAME AS Consultant FROM t_aven_dc_contact
INNER JOIN t_aven_dc_site AS t_aven_dc_site_1 ON t_aven_dc_contact._INTERNID = t_aven_dc_site_1._INTERNID INNER JOIN
t_aven_dc_site ON t_aven_dc_site_1._SPS_ID = t_aven_dc_site._CONS_ID
WHERE
t_aven_dc_site._IDB_CLNT_ID_N = 716166
ELSE
Select 'NA' As ConsultantAcrobat in versions prior to 9 has the ADBC, Adobe Data Base Connection, object which through a series of function or method calls could interact with an SQL data base by passing the SQL statements as a parameter.
The ability to connect to an SQL data base is now limited to LiveCycle Designer forms. -
I need help with SQL Server 2012
Hi Everyone,
I am using the query pane to create a database with the data file and log file but keep getting this error message. I will be glad if someone can help.
You can see below the syntax:
Msg 5123, Level 16, State 1, Line 1
CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\project.mdf'.
Msg 1802, Level 16, State 4, Line 1
CREATE DATABASE failed. Some file names listed could not be created. Check related errors..
CREATE DATABASE project
ON
(Name= 'project_dat',
FILENAME ='C:\project.mdf',
SIZE = 10,
MAXSIZE = 100,
FILEGROWTH = 5)
LOG ON
(NAME = project_log,
FILENAME = 'C:\project.ldf',
SIZE =40,
MAXSIZE = 100,
FILEGROWTH = 10);Look at the second number in your constraints ValidBirthYear and ValidDeathYear. Do you mean to limit it to years between 1000-1199 and 2000-2199? Also, your ValidDeathYear constraint is using DateOfBirth.
CONSTRAINT
ValidBirthYear
CHECK
(DateOfBirth LIKE '[1-2]
[0-1] [0-9] [0-9]'),
CONSTRAINT
ValidDeathYear
CHECK
(DateOfBirth LIKE '[1-2]
[0-1] [0-9] [0-9]'));
I'm very much a beginner so that may not fix your issue but it sure looks like the cause of the second message to me. -
Where to find help with SQL Developer installation?
Hi,
I just want to try out SQL Developer and compare its capabilities to TOAD's. Unfortunately, I am not PC software savvy and now am stuck with a SQL Developer (sqldeveloper-1.2.2998) installation problem. When I clicked on the .exe file, I got a blank SQL Developer screen - there is nothing in the screen except a heading that reads 'Oracle SQL Developer'...
Does anyone know of a blog or a site that I can get some help with problems like mine?
Any help is much appreciated!Hi,
SQL Developer forum link:
"http://forums.oracle.com/forums/forum.jspa?forumID=260"
There are 2 versions of SQL Developer, with/without JRE.
Try out the full install version with JRE.
HTH
Zack -
Need help with saving data and keeping table history for one BP
Hi all
I need help with this one ,
Scenario:
When adding a new vendor on the system the vendor is suppose to have a tax clearance certificate and it has an expiry date, so after the certificate has expired a new one is submitted by the vendor.
So i need to know how to have SBO fullfil this requirement ?
Hope it's clear .
Thanks
BonganiHi
I don't have a problem with the query that I know I've got to write , the problem is saving the tax clearance certificate and along side it , its the expiry date.
I'm using South African localization.
Thanks -
I'm creating a jscript to automatically rename a file the current days date, but i can't figure out how to get it to put a zero in front of days/months that are single digits. Can anyone help me real quick? Heres the code i already have, pay no attention to the "dh" part, it has to be there:
var todayFileName = "dh" +
today.getFullYear() + "" +
today.getMonth() + "" +
(today.getDate()+1); + " " +This little javascript function should help.
Note that it is only meant to work with valid dates. Putting in a -7 for the parameter will result in something not so nice :-)
function twoDigitNo(no){
return (no < 10) ? "0" + no : no;
}Cheers,
evnafets -
Open Toad Data Modeler diagram with SQL Data Modeler
hi, I've made a diagram with TOAD Data Modeler in Windows. Now I'm working with Linux, so I need a portable application to work with. Oracle SQL Data Modeler seems to be the solution to my problems, but I can't open/import my TOAD's diagrams into SQL Data Modeler.
Anyone knows how to do it?
Thanks in advance,
Neuquino
Edited by: Neuquino2 on Nov 1, 2010 1:30 PMHi Neuquino,
there is no import from TOAD Data Modeler. You can generate DDL script with TOAD DM and import that script.
Philip -
Pls help with extracting dates
I wish to produce the output in table customer1 based on the customer table DOP field.
The values in DOP (0030500) indicates wed and fri, (0000007) indicates sunday.
how can i extract all the dates for wed and fri (0030500) between the period ST_DT and ED_DT (23/02/2005) to (20/03/2005).
SQL> select * from customer;
CUSTOMER_ID ST_DT ED_DT DOP
429100 23/02/2005 20/03/2005 0030500
428950 14/03/2005 02/04/2005 0000007
SQL> select * from customer1;
CUSTOMER_ID ST_DT ED_DT DOP DT
429100 23/02/2005 20/03/2005 0030500 23/02/2005
429100 23/02/2005 20/03/2005 0030500 25/02/2005
429100 23/02/2005 20/03/2005 0030500 02/03/2005
429100 23/02/2005 20/03/2005 0030500 04/03/2005
429100 23/02/2005 20/03/2005 0030500 09/03/2005
429100 23/02/2005 20/03/2005 0030500 11/03/2005
429100 23/02/2005 20/03/2005 0030500 16/03/2005
429100 23/02/2005 20/03/2005 0030500 18/03/2005
428950 14/03/2005 02/04/2005 0000007 20/03/2005
428950 14/03/2005 02/04/2005 0000007 27/03/2005
pls help, thanks.SQL> select * from customer;
CUSTOMER_ID ST_DT END_DT DOP
429100 23-FEB-05 20-MAR-05 0030500
428950 14-MAR-05 02-APR-05 0000007
SQL> select a.customer_id,a.st_dt,a.end_dt,a.dop,a.st_dt+b.tita
2 from customer a,(select rownum-1 tita from user_objects) b
3 where a.st_dt+b.tita <= a.end_dt
4 and instr(a.dop,decode(to_char(a.st_dt+b.tita,'d')-1,0,7,to_char(a.st_dt+b.tita,'d')-1))>0
5 order by a.customer_id,a.st_dt+b.tita;
CUSTOMER_ID ST_DT END_DT DOP A.ST_DT+B
428950 14-MAR-05 02-APR-05 0000007 20-MAR-05
428950 14-MAR-05 02-APR-05 0000007 27-MAR-05
429100 23-FEB-05 20-MAR-05 0030500 23-FEB-05
429100 23-FEB-05 20-MAR-05 0030500 25-FEB-05
429100 23-FEB-05 20-MAR-05 0030500 02-MAR-05
429100 23-FEB-05 20-MAR-05 0030500 04-MAR-05
429100 23-FEB-05 20-MAR-05 0030500 09-MAR-05
429100 23-FEB-05 20-MAR-05 0030500 11-MAR-05
429100 23-FEB-05 20-MAR-05 0030500 16-MAR-05
429100 23-FEB-05 20-MAR-05 0030500 18-MAR-05
10 rows selected.
SQL> Assuming the date range does not exceed the number of user objects :-) -
Hi,
I'm trying to update a record but I don't know how to update one field in this record. This is my code so far
private void updateProcess() {
int nrows;
String sql = "UPDATE student SET s_first = '" + txtS_first.getText()
+ "', s_mi = '" + txtS_mi.getText()
+ "', s_last = '" + txtS_last.getText()
+ "', s_dob = TO_DATE('" + txtS_dob.getText() + "', 'MM/DD/YYYY')"
/* In a database table, after the s_dob column is f_id column, but a user will see info of this field by f_first and f_last instead of f_id. How can I update this column with f_id if a user's input is f_first and f_last? What if f_first and f_name that a user enters doesn't exist in the database, is there anyway to display an error for this case?
+ "', f_first = '" + txtF_first.getText()
+ "', f_last = '" + txtF_last.getText()
+ "' WHERE s_id = " + txtS_id.getText();
try {
nrows = stmt.executeUpdate(sql);
// I think this part I'm doing wrong because the text area doesn't display these strings
if(nrows > 0) {
lblShowResult.setText("Update successed");
lblShowResult.setVisible(true);
} // end if
else {
lblShowResult.setText("Update failed");
lblShowResult.setVisible(true);
} // end else
rset.close();
} // end try
catch (SQLException e) {}
catch (NullPointerException e){}
} // end updateProcessIf you read the docs for executeUpdate, you'll see that it returns the number of rows affected. So if it returns zero, then no rows matched.
Also, you should be using PreparedStatement rather than Statement. Then you won't have to worry about weird characters in strings or formatting dates (you can just give it a java.sql.Date object). -
Please help with SQL amount calulation
-- Results
with t as (
select 'P11877' Mstr_Program, 1 Year_of_study, 'BUSI1490' program_module, 20 no_of_stud, 1 rank, 30 program_credits, 30 cumm_credits from dual union all
select 'P11877', 1, 'COMP1365', 20, 2, 30, 60 from dual union all
select 'P11877', 1, 'BUSI1375', 20, 3, 30, 90 from dual union all
select 'P11877', 1, 'COMP1363', 20, 4, 30, 120 from dual union all
select 'P11877', 2, 'MARK1174', 8, 1, 30, 30 from dual union all
select 'P11877', 2, 'FINA1068', 8, 2, 15, 45 from dual union all
select 'P11877', 2, 'INDU1062', 8, 3, 30, 75 from dual union all
select 'P11877', 2, 'BUSI1329', 8, 4, 15, 90 from dual union all
select 'P11877', 2, 'MARK1138', 8, 5, 30, 120 from dual)
select * from t;-- Each MSTR_PROGRAM can have 1 or many program_module
-- MSTR_PROGRAM's can run for 1 or 2 years (case above is two years) so some modules run in year 1 and some in year 2
-- NO_OF_STUD is the number of students on the module
-- RANK basically ranks the modules by the number of students on them grouped by program and year
-- e.g.row_number() OVER (PARTITION BY Mstr_Program, Year_of_study) ORDER BY COUNT(STUDENT_ID) DESC) rank
-- PROGRAM_CREDITS: each module has a fixed number of credits
-- CUMM_CREDITS: Increments the credit count of modules
-- SUM(program_credits * 10) OVER (PARTITION BY Mstr_Program, Year_of_study
-- ORDER BY count(STUDENT_ID) desc ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) cumm_credits
-- I want to trim of any modules once the CUM_CREDITS hits 120. As seen above. I achieve this by wrapping the main query is another SELECT then LIMIT
-- that WHERE cum_credit <=120.
-- But what I need is:
-- In some cases the the cumm_credit maybe on lets say 90credits then the next module is worth 40 credits. This next module will not show as it
-- will be greater than 120 credits, so i need to pro-rata it:
-- So if credit_count > 120, then the last module is counted pro-rata as follows: 1- ((credit count - 120) / credits from last module
-- Can anyone help with how I can incorporate this into my current code: The SELECT portion of the Original SQL is below: I simplified column names
-- e.t.c in the above so they wont be the same
SELECT * FROM (
SELECT
,SR_PROGRAM Mstr_Program
,DECODE (SORLCUR_YEAR, 1, 1,
2, 2,
3, 3,
4, 3, SR_YEAR) year_of_study
,SCT_SUBJ_CODE||SCT_CRSE_NUMB program_module
,COUNT(student_ID) no_of_stud
,row_number() OVER (PARTITION BY sr_program,
DECODE (sr_year, 1, 1,
2, 2,
3, 3,
4, 3, SR_YEAR) ORDER BY COUNT(student_id) DESC, scbcrse_title asc) rank
,(SCT_CREDIT_HRS * 10) program_credits
,SUM(SCT_CREDIT_HRS * 10) OVER (PARTITION BY sr_program, DECODE (sorlcur_year, 1, 1,
2, 2,
3, 3,
4, 3, SR_YEAR)
ORDER BY count(student_id) desc ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) cumm_credits
WHERE cumm_credit <=120
ORDER BY Mstr_Program, YEAR_OF_STUDY, RANK asc;Maybe
SELECT Mstr_Program,year_of_study,program_module,no_of_stud,rank,program_credits old_program_credits,cumm_credits old_cumm_credits,
case when cumm_credits > 120
then program_credits - cumm_credits + 120
else program_credits
end new_program_credits,
case when cumm_credits > 120
then 120
else cumm_credits
end new_cumm_credits
FROM (SELECT SR_PROGRAM Mstr_Program,
DECODE(SORLCUR_YEAR,1,1,2,2,3,3,4,3,SR_YEAR) year_of_study,
SCT_SUBJ_CODE||SCT_CRSE_NUMB program_module,
COUNT(student_ID) no_of_stud,
row_number() OVER (PARTITION BY sr_program,DECODE(sr_year,1,1,2,2,3,3,4,3,SR_YEAR)
ORDER BY COUNT(student_id) DESC,scbcrse_title) rank,
10 * SCT_CREDIT_HRS program_credits,
10 * SUM(SCT_CREDIT_HRS) OVER (PARTITION BY sr_program,DECODE(sorlcur_year,1,1,2,2,3,3,4,3,SR_YEAR)
ORDER BY count(student_id) desc
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) cumm_credits
WHERE 0 <= case when cumm_credits > 120
then program_credits - cumm_credits + 120
else program_credits
end
ORDER BY Mstr_Program,YEAR_OF_STUDY,RANKRegards
Etbin
Edited by: Etbin on 16.12.2011 8:50
with
t as /* simulating the result achieved */
(select 'P11877' Mstr_Program,1 Year_of_study, 'BUSI1490' program_module,20 no_of_stud,1 rank,30 program_credits,30 cumm_credits from dual union all
select 'P11877', 1, 'COMP1365', 20, 2, 40, 70 from dual union all
select 'P11877', 1, 'BUSI1375', 20, 3, 30, 100 from dual union all
select 'P11877', 1, 'COMP1363', 20, 4, 40, 140 from dual union all
select 'P11877', 2, 'MARK1174', 8, 1, 30, 30 from dual union all
select 'P11877', 2, 'FINA1068', 8, 2, 50, 80 from dual union all
select 'P11877', 2, 'INDU1062', 8, 3, 30, 110 from dual union all
select 'P11877', 2, 'BUSI1329', 8, 4, 50, 160 from dual union all
select 'P11877', 2, 'MARK1138', 8, 5, 30, 190 from dual
select Mstr_Program,Year_of_study,program_module,no_of_stud,rank,program_credits old_credits,cumm_credits old_cumm,
case when cumm_credits > 120
then program_credits - cumm_credits + 120
else program_credits
end new_program_credits,
case when cumm_credits > 120
then 120
else cumm_credits
end new_cumm_credits
from t
where 0 <= case when cumm_credits > 120
then program_credits - cumm_credits + 120
else program_credits
end -
Hi All,
I have a problem in the query below. When I run the query I got a pop-up screen to ente value for
:total_balance,
:emp_code,
:from_date,
:to_date
total_balance supose to be a result of a calculation.
Your assistance is apreciated. Thanks,
Ribhi
select FK_VOUCHERSERIAL_N,
FK_VOUCHERVALUE_DA,
DESCRIPTION,
nvl(AMOUNT,0) amount,
TYPE,
Accnt101.postive_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) postive_amount,
Accnt101.negative_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) negative_amount,
Accnt101.total_balanceformula(:total_balance, EMPLOYEE_TRANSACTI.TYPE,Accnt101.negative_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) ,Accnt101.postive_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) , nvl(AMOUNT,0)) total_balance
from EMPLOYEE_TRANSACTI
where FK_EMPLOYEENUMBER0=:emp_code
and STATUS=1
and FK_VOUCHERVALUE_DA<=:to_date
and FK_VOUCHERVALUE_DA>=:from_date
and ((TYPE >7 and TYPE <16)
or (TYPE >34 and TYPE <43)
or (TYPE =7)
or (TYPE =18)
or (TYPE >26 and TYPE <35)
or (TYPE =17)
OR (TYPE = 60)
OR (TYPE = 70)
OR (TYPE = 72)
OR (TYPE = 73)
OR (TYPE = 74)
or (type = 21)
or (type =24)
or (type = 81)
or (type = 82))
order by FK_VOUCHERVALUE_DA asc, FK_VOUCHERSERIAL_N asc, type descHi Satyaki,
My problem is with SQL and PL/SQL codd. I managed to convert some of my reports and now I'm facing a problem with converted SQL and PL/SQL code. To give you an Idea the following is a sample of a converted report.
Pls have a look. (p.s how can i post formated text)
Thanks,
Ribhi
1 - XML template file
<?xml version="1.0" encoding="UTF-8" ?>
- <dataTemplate name="Accnt101" defaultPackage="Accnt101" version="1.0">
- <properties>
<property name="xml_tag_case" value="upper" />
</properties>
- <parameters>
<parameter name="FROM_DATE" dataType="date" defaultValue="01/01/1998" />
<parameter name="TO_DATE" dataType="date" defaultValue="31/12/1998" />
<parameter name="EMP_CODE" dataType="number" defaultValue="44" />
</parameters>
<lexicals />
- <dataQuery>
- <sqlStatement name="employee_trans">
- <![CDATA[
select FK_VOUCHERSERIAL_N,
FK_VOUCHERVALUE_DA,
DESCRIPTION,
nvl(AMOUNT,0) amount,
TYPE,
Accnt101.postive_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) postive_amount,
Accnt101.negative_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) negative_amount,
Accnt101.total_balanceformula(:total_balance, EMPLOYEE_TRANSACTI.TYPE,Accnt101.negative_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) ,Accnt101.postive_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) , nvl(AMOUNT,0)) total_balance
from EMPLOYEE_TRANSACTI
where FK_EMPLOYEENUMBER0=:emp_code
and STATUS=1
and FK_VOUCHERVALUE_DA<=:to_date
and FK_VOUCHERVALUE_DA>=:from_date
and ((TYPE >7 and TYPE <16)
or (TYPE >34 and TYPE <43)
or (TYPE =7)
or (TYPE =18)
or (TYPE >26 and TYPE <35)
or (TYPE =17)
OR (TYPE = 60)
OR (TYPE = 70)
OR (TYPE = 72)
OR (TYPE = 73)
OR (TYPE = 74)
or (type = 21)
or (type =24)
or (type = 81)
or (type = 82))
order by FK_VOUCHERVALUE_DA asc, FK_VOUCHERSERIAL_N asc, type desc
]]>
</sqlStatement>
- <sqlStatement name="employee">
- <![CDATA[
select NAME,NUMBER0
from EMPLOYEE
where NUMBER0=:emp_code
]]>
</sqlStatement>
</dataQuery>
<dataTrigger name="beforeReportTrigger" source="Accnt101.beforereport" />
- <dataStructure>
- <group name="G_employee_trans" dataType="varchar2" source="employee_trans">
<element name="FK_VOUCHERSERIAL_N" dataType="number" value="FK_VOUCHERSERIAL_N" />
<element name="FK_VOUCHERVALUE_DA" dataType="date" value="FK_VOUCHERVALUE_DA" />
<element name="DESCRIPTION" dataType="varchar2" value="DESCRIPTION" />
<element name="AMOUNT" dataType="number" value="AMOUNT" />
<element name="postive_amount" dataType="number" value="postive_amount" />
<element name="negative_amount" dataType="number" value="negative_amount" />
<element name="total_balance" dataType="number" value="total_balance" />
<element name="TYPE" dataType="number" value="TYPE" />
<element name="CS_1" function="sum" dataType="number" value="G_employee_trans.total_balance" />
</group>
- <group name="G_employee" dataType="varchar2" source="employee">
<element name="NUMBER0" dataType="number" value="NUMBER0" />
<element name="NAME" dataType="varchar2" value="NAME" />
</group>
<element name="balance" dataType="number" value="Accnt101.balance_p" />
<element name="CS_2" function="count" dataType="number" value="G_employee.NUMBER0" />
<element name="CS_3" function="count" dataType="number" value="G_employee_trans.AMOUNT" />
</dataStructure>
</dataTemplate>
2 - PLS/SQL package
CREATE OR REPLACE PACKAGE Accnt101 AS
from_date date;
to_date date;
emp_code number;
balance number := 0 ;
function postive_amountformula(TYPE in number, amount in number) return number ;
function negative_amountformula(TYPE in number, amount in number) return number ;
function BeforeReport return boolean ;
function total_balanceformula(total_balance in number, TYPE in number, negative_amount in number, postive_amount in number, amount in number) return number ;
Function balance_p return number;
END Accnt101;
3- Package Body
CREATE OR REPLACE PACKAGE BODY Accnt101 AS
function postive_amountformula(TYPE in number, amount in number) return number is
begin
if ((TYPE>26 and TYPE<35)
or (TYPE=17))
then
return(amount);
elsif (type = 70)and (amount >=0) then
return (amount) ;
elsif (type = 72)and (amount >=0) then
return (amount) ;
elsif (type = 73)and (amount >=0) then
return (amount) ;
elsif (type = 74)and (amount >=0) then
return (amount) ;
elsif (type = 60)and (amount >=0) then
return (amount) ;
else
return (null) ;
end if;
RETURN NULL; end;
function negative_amountformula(TYPE in number, amount in number) return number is
begin
if ((TYPE>7 and TYPE<16)
or (TYPE >34 and TYPE <43)
or (TYPE=7)
or (TYPE=18)
or (type=21)
or (type=24)
or (type= 81)
or (type=82))
then
return(amount);
elsif (type = 70)and (amount <0) then
return (abs (amount)) ;
elsif (type = 72)and (amount <0) then
return (abs (amount)) ;
elsif (type = 73)and (amount <0) then
return (abs (amount)) ;
elsif (type = 74)and (amount <0) then
return (abs (amount)) ;
elsif (type = 60)and (amount <0) then
return (abs(amount)) ;
else
return (null) ;
end if;
RETURN NULL; end;
function BeforeReport return boolean is
var_pos number(15,3) ;
var_neg number(15,3) ;
beg_bal number(15,3) ;
Begin
begin
select sum (nvl(amount,0)) into beg_bal
from EMPLOYEE_TRANSACTI
where (TYPE=99 or type = 92 or type = 93 or type = 94)
and to_char(from_date,'YYYY')=to_char(date0,'YYYY')
and FK_EMPLOYEENUMBER0=emp_code;
EXCEPTION
WHEN NO_DATA_FOUND THEN
beg_bal := 0;
end;
begin
select sum(nvl(amount,0)) into var_pos
from EMPLOYEE_TRANSACTI
where
(TYPE=17
or type=60
OR TYPE=70
oR TYPE=72
OR TYPE=73
OR TYPE=74
or (TYPE>26 and TYPE<35))
and fk_vouchervalue_da<from_date
and fk_vouchervalue_da>= trunc(from_date,'year')
and FK_EMPLOYEENUMBER0=emp_code;
EXCEPTION
WHEN NO_DATA_FOUND THEN
var_pos := 0;
end;
Begin
select sum(nvl(amount,0)) into var_neg
from EMPLOYEE_TRANSACTI
where ((TYPE>7 and TYPE<16)
or (TYPE >34 and TYPE <43)
or (TYPE=7)
or (TYPE=18)
or (type=21)
or (type=24)
or (type= 81)
or (type=82) )
and fk_vouchervalue_da<from_date
and fk_vouchervalue_da>= trunc(from_date,'year')
and FK_EMPLOYEENUMBER0=emp_code;
balance :=nvl(beg_bal,0) + nvl(var_pos,0) - nvl(var_neg,0);
return(true);
EXCEPTION
WHEN NO_DATA_FOUND THEN
balance :=nvl(beg_bal,0) + nvl(var_pos,0) - nvl(var_neg,0);
RETURN (TRUE);
end;
RETURN NULL; end;
function total_balanceformula(total_balance in number, TYPE in number, negative_amount in number, postive_amount in number, amount in number) return number is
begin
if total_balance is null then
if ((TYPE>7 and TYPE<16)
or (TYPE >34 and TYPE <43)
or (TYPE=7)or (TYPE=18)
or (type=21) or (type=24)
or (type= 81)
or (type=82))
then
return(balance-negative_amount);
elsif ((TYPE>26 and TYPE<35) or (TYPE=17))
then
return(balance+postive_amount);
elsif (type=70 or type=72 or type=73 or type=74
or type=60) and (amount >=0) then
return(balance+postive_amount);
elsif (type=70 or type=72 or type=73 or type=74
or type=60) and (amount <0) then
return(balance-negative_amount);
end if;
else
if ((TYPE>7 and TYPE<16)
or (TYPE >34 and TYPE <43)
or (TYPE=7)or (TYPE=18)
or (type=21) or (type=24)
or (type= 81)
or (type=82))
then
return(total_balance-negative_amount);
elsif ((TYPE>26 and TYPE<35) or (TYPE=17))
then
return(total_balance+postive_amount);
elsif (type=70 or type=72 or type=73 or type=74
or type=60) and (amount >=0) then
return(total_balance+postive_amount);
elsif (type=70 or type=72 or type=73 or type=74
or type=60) and (amount <0) then
return(total_balance-negative_amount);
end if;
end if ;
RETURN NULL; end;
Functions to refer Oracle report placeholders
Function balance_p return number is
Begin
return balance;
END;
END Accnt101 ;
Maybe you are looking for
-
Creating Page Format In Quality
I want to create a new page format, for the purpose I did the following... spad-> Full Administration-> Device Types-> Page Format-> Change-> Create-> (Page Format=ZA4, Orientation=Landscape, Paper Size (Width=215 mm, Height=300 mm)) When I click on
-
Core 2 Quad & late MacBook Pro
Hi all! Really glad to be here as an all new Mac user - got my MacBook Pro just four days ago and already I start wondering where to go from here. See, its probably 2-4 months from here until Apple is going to introduce a quad core MacBook Pro. It al
-
Odi Jobs not getting triggered through Scheduler Agent
Hi Guru's, i have Scheduled jobs in odi using Scheduler agent but jobs doesn't get triggered even though my scheduler agent is up and running and i have updated scheduled plan also. Please help me in resolving the issue. Regards Vinod
-
Merged Clips in Pr don't import into AE (or export from Pr via Dynamic Link)
anyone else encounter this?? Exporting ANY sequence from Premiere that contains Merged Clips to Ae via Dynamic Link results in NO clips showing up in the AE Comp. On the flip side, I can Import a Premiere Pro Sequence in Ae, but the only clips that d
-
ERGH my iphone 5 has been charging for over 4 hours and will not turn itself on, what do i do?! reply asap please