TO_DAYS equivalant in Oracle
I have a db table (calendar)
calendar_id NUMBER(15) NOT NULL,
event_name VARCHAR2(20) NOT NULL,
event_date DATE NOT NULL,
EVENT_DESCRIPTION VARCHAR2(4000) NOT NULL,
date_stamp DATE NOT NULL,
admin_id NUMBER(15) NOT NULL,
CONSTRAINT PK_CALENDAR PRIMARY KEY (calendar_id )
and have to replace the following sql from MySql to an oracle version.
SELECT CALENDAR_ID, EVENT_DATE, EVENT_DESCRIPTION, EVENT_NAME FROM calendar WHERE TO_DAYS(EVENT_DATE) >= TO_DAYS('09-28-03 ') ORDER BY EVENT_DATE
Could someone let me know how to do this in Oracle.
Thanks
TO_DATE on a date is a bug in your code. TO_DATE accepts character input, if you input a date, it will be implicitly converted to a character parameter, and then converted back to a date result.
When using implicit type conversion in this way, no format mask is specified. If you are lucky you may get the same date back, if you are not you won't.
SQL> create table t (d date);
Table created.
SQL> alter session set nls_date_format = 'MM/DD/RR';
Session altered.
SQL> insert into t values (date '1901-01-01');
1 row created.
SQL> insert into t select to_date(d) from t;
1 row created.
SQL> select * from t;
D
01/01/01
01/01/01
SQL> alter session set nls_date_format = 'MM/DD/YYYY';
Session altered.
SQL> select * from t;
D
01/01/1901
01/01/2001
SQL>Apologies in advance for any borked formatting courtesy of the Formatting of posts.
Similar Messages
-
DMBS_SQL.to_refcursor equivalent in Oracle 10g
Hello,
Is there any other way to get result as a refcursor in Oracle 10g with DBMS_SQL? I have the function that function generate dynamic query and execute with DBMS_SQL. This function called by java code for viewing result as report. How can I do this, is there equivalent in Oracle 10g for DMBS_SQL.to_refcursor? Please help.
Thanks,ilkinesrefli wrote:
Is it difficult to understand my answers?Yes, because they are not accurate. You keep saying you can't use ref cursors and must use DBMS_SQL, but you have failed to show us why that is so.
It is impossible because there is dynamic where clause in my query. Show us why it's impossible.
BluShadow please solve this one:
p_sql := 'select empno, ename, deptno from emp where deptno=:pdeptno';
if ... then
p_sql := p_sql || ' AND empno=:pempno';
end if;
...Is it possible by your way?Yes, ref cursors can be used for dynamic queries. basic example...
SQL> ed
Wrote file afiedt.buf
1 create or replace function get_refcursor(p_sql in varchar2
2 ,p_whereclause in varchar2 := null
3 ,p_whereval in number := null) return sys_refcursor is
4 v_rc sys_refcursor;
5 begin
6 if p_whereval is not null then
7 open v_rc for p_sql||' where '||p_whereclause using p_whereval;
8 else
9 open v_rc for p_sql;
10 end if;
11 return v_rc;
12* end;
SQL> /
Function created.
SQL> var rc refcursor;
SQL> exec :rc := get_refcursor('select empno, ename, deptno from emp');
PL/SQL procedure successfully completed.
SQL> print rc;
EMPNO ENAME DEPTNO
7369 SMITH 20
7499 ALLEN 30
7521 WARD 30
7566 JONES 20
7654 MARTIN 30
7698 BLAKE 30
7782 CLARK 10
7788 SCOTT 20
7839 KING 10
7844 TURNER 30
7876 ADAMS 20
7900 JAMES 30
7902 FORD 20
7934 MILLER 10
14 rows selected.
SQL> exec :rc := get_refcursor('select empno, ename, deptno from emp', 'deptno = :1', 20);
PL/SQL procedure successfully completed.
SQL> print rc;
EMPNO ENAME DEPTNO
7369 SMITH 20
7566 JONES 20
7788 SCOTT 20
7876 ADAMS 20
7902 FORD 20
SQL>So, please explain to us again why ref cursors are impossible to use and you have to use DBMS_SQL? -
SQL XMLExplicit equivalent in oracle
Hi
Is there any equivalent in oracle for SQL XMLExplicit?
In SQL the XMLExplicit will add all the retunded nodes under the single root node like that any equivalent is available in oracle.
Thanks
SurendraI hope you will get better answers if you post this in Sql/Plsql Forum ..
PL/SQL
This one is one of the genuine and active forums .. :) -
HANA equivalent of oracle's sql%rowcount to get affected rows.
I want to get the number of rows affected from an insert or update statement inside a stored procedure.
Is there any equivalent to oracle's sql%rowcount that can be called after the query.
For example:
create procedure procedure_name
begin
declare l_c integer;
insert into table values ('somevalue');
l_c := sql%rowcount; -- This would return 1 for the row inserted.
end;Yes, after the INSERT statement....
SELECT ::ROWCOUNT into L_C FROM DUMMY;
Cheers,
Rich Heilman -
TIBCO Businessworks equivalent in Oracle SOA Suite
Hello Experts,
What is the equivalent of TIBCO Business works in Oracle SOA world??
I guess Oracle Service Bus. Am I right??
Thanks
Rgds
NatrajanNatrajan,
For process orchestration, ACTIVEMATRIX BusinessWorks is equivalent to Oracle BPEL (which is part of Oracle SOA Suite). ACTIVEMATRIX Service Bus is equivalent to Oracle Service Bus.
Regards,
Anuj -
Does SQL Server has an equivalent to Oracle's OEM?
I am not sure if this is the correct area to ask my question. My manager asked me if SQL Server has an equivalent to Oracle's OEM. Does it? I mean OEM is not like Microsoft SQL Server Management Studio.
lcerniHello,
You can use SQL Server Management Studio to manage SQL Server instances as you do with Oracle Enterprise Manager, and you can have a management and performance
data warehouse using SQL Server Management Data Warehouse (MDW) as explained on the following article:
http://msdn.microsoft.com/en-us/library/dd939169(v=SQL.100).aspx
MDW data collection can be customized.
Hope this helps.
Regards,
Alberto Morillo
SQLCoffee.com -
10g Express Edition equivalent for Oracle 8.1.7?
Hi all,
Exist any Oracle 10g Express Edition equivalent (free edition) for Oracle 8.1.7?
Many thanks in advance.user5880436 wrote:
Hi all,
Exist any Oracle 10g Express Edition equivalent (free edition) for Oracle 8.1.7?
Many thanks in advance.Express edition was started from 10G onwards. So there is no equivalent in 8 i.
Regards
Rajesh -
WITH clause equivalent in oracle 8i
Hi friends,
The "WITH" clause is very well supported in Oracle 9i. Is there any equivalent ways to use it in Oracle 8i?
Regards
J.BDear J. B.!
No, there isn't an equivalent for WITH in Oracle 8i. The only workaround for you is to build inline views in the FROM-Clause of your statements. Please have a look at the following link. It shows some example using a WITH-Clause and the equivalent SQL-Statements with an inline view.
[http://www.oracle-base.com/articles/misc/WithClause.php]
Yours sincerely
Florian W. -
Hi,
I am having trouble understanding equivalent data types in my conversion from SQL Server to Oracle.
Let's say I have this statement in SQL Server, where the string being "passed in" is a uniqueidentifier:
select cast(substring('EFDA8997-63AA-4F33-96CF-29BFC2CE252E',8,1) as binary(1));
The tool I've used to convert this to Oracle says the equivalent statement to this is (where the string being "passed in" is a char:
select cast((substr('EFDA8997-63AA-4F33-96CF-29BFC2CE252E',8,1)) as raw(1)) from dual;
However, I get different results when testing these two statements:
SQL Server: 0x37
Oracle: 07
What is the correct what to convert this statement to Oracle?
Thank you!
MimiI should add that this an n-tier application, where data is passed across multiple tiers, so the client UI has no connection to the database.
I'm assuming this means that select..for update is not suitable, as that would require a connection to the database to be held open for a specific user in the middle-tier. Not suitable for a scalable, n-tier scenario. -
Hello,
What is the equivalent of "WIN_API_SESSION.Timeout_Get_Inactive_Time" in oracle 10G developer suite using webutil.
I want to exit the form if the session is inactive for a set period of time calculated as above in earlier versions.
Thanks and Regards
MohanDo you have any other solution on this?
Regards,
MKBH -
PROMPT Command equivalent in Oracle 7
Hi All,
I am working on a database Health check script . I Have to implement this on a Oracle7 server running on OS HP-unix. I have done with this health check script on all the 9i servers. The same script i have to modify and implement in Oracle7 database also. To print Headings or titles in Oracle 9i i used PROMPT command. So which is the equivalent command that can be used in Oracle7. I want to print the headings. Kindly assist me.877920 wrote:
Same error. Unable to login.
SQL> connect / as sysdba
ERROR: ORA-01017: invalid username/password; logon deniedAs far as I recall, sqlplus back then did not support this specific logon syntax. Qualify the connection string using username and password. e.g.
sqlplus sys/mysecretpassword
The sysdba role will likely not be enabled - but that should not be an issue for running a bunch SQL selects.
Also reconsider using the sys schema for logging on. The only time this schema should be used is for actual database maintenance - like doing a shutdown, changing initialisation settings, doing an upgrade and so on.
Using it as your personal superuser logon is not a good idea and one that you will be nailed for (and very hard) in any security review or audit.
Rather create a new schema and grant it the minimal rights needed to do perform the required job.
PS. Cannot recall if connect internal also worked in sqlplus back then - but that can be tried if you want a sysdba connection from sqlplus itself. -
Hi,
In SQL Server, there is a function datediff with datepart 'q'/quarter which behaves as follows :--
select datediff(q,'03-30-2005','04-01-2005') will return 1
datediff(q,start date,end date)
i.e it takes the quarter in which the start date exists and subtracts it from the quarter in which the end date exists.
I need the equivalent for the above in Oracle.
I found the below in OMWB document :--
Equivalent as : round(months_between(date2, date1)/3)
But this will not work for particular data, since the logic in which SQL Server executes the DATEDIFF is different as I have explained above. Please can anyone give the exact equivalent if any available.
Thanks,
SamTom Kyte has written a datediff function for Oracle here:
http://osi.oracle.com/~tkyte/Misc/DateDiff.html
You could modify it to include quarters like so:
scott@ORA92> create or replace function datediff
2 (p_what in varchar2,
3 p_d1 in date,
4 p_d2 in date)
5 return number
6 as
7 l_result number;
8 begin
9 if upper (p_what) = 'Q' then
10 l_result := ((to_char (p_d2, 'yyyy') - to_char (p_d1, 'yyyy')) * 4)
11 + (to_char (p_d2, 'q') - to_char (p_d1, 'q'));
12 else
13 select (p_d2-p_d1) *
14 decode (upper (p_what),
15 'SS', 24*60*60,
16 'MI', 24*60,
17 'HH', 24,
18 NULL)
19 into l_result
20 from dual;
21 end if;
22 return l_result;
23 end datediff;
24 /
Function created.
scott@ORA92> show errors
No errors.
scott@ORA92> alter session set nls_date_format = 'mm-dd-yyyy'
2 /
Session altered.
scott@ORA92> select datediff ('q', '03-30-2005', '04-01-2005') from dual
2 /
DATEDIFF('Q','03-30-2005','04-01-2005')
1
scott@ORA92> select datediff ('q', '03-30-2005', '04-01-2006') from dual
2 /
DATEDIFF('Q','03-30-2005','04-01-2006')
5
scott@ORA92> select datediff ('q', '04-01-2005', '03-30-2006') from dual
2 /
DATEDIFF('Q','04-01-2005','03-30-2006')
3
scott@ORA92> -
MySQL LIMIT clause equivalent in ORACLE statement
Is there an Oracle SQL statement that would be equivalent to the MySQL LIMIT clause used to return only part of a result set?
The preferred solution is to make use of the analytic function ROW_NUMBER. There is a description in the Oracle documentation. The final example shown returns only the fifty-first through one-hundredth row of the EMPLOYEES table:
SELECT last_name FROM
(SELECT last_name, ROW_NUMBER() OVER (ORDER BY last_name) R FROM employees)
WHERE R BETWEEN 51 and 100;An alternative is to use:
select *
from ( select a.*, rownum rnum
from ( YOUR_QUERY_GOES_HERE -- including the order by ) a
where rownum <= MAX_ROWS )
where rnum >= MIN_ROWS;which is discussed on asktom.oracle.com. This works from Oracle 8.1 onwards.
-- cj -
SQLServer 7 sp_executesql equivalent in Oracle 8
Hi!
Looking for an example or a code equivalent for the system
procedure "sp_executesql" in SQLServer 7 for Oracle 8... If you
have any information of this kind, please send me a message.
Thanks!
nullPierre,
The facilities for dynamic sql from plsql are:
dbms_sql
and (new in 8( or 8i?))
execute immediate
see pl/sql documentation for details.
simplest example:
execute immediate 'select * from emp';
calling procedures with bind variables is a little more
complicated.
the following gives some simple examples:
convienience function for dbms_sql:
CREATE OR REPLACE PROCEDURE EXEC_SQL(STRING
IN VARCHAR2) AS
CURSOR_NAME INTEGER;
RET INTEGER;
BEGIN
CURSOR_NAME := DBMS_SQL.OPEN_CURSOR;
BEGIN
DBMS_SQL.PARSE(CURSOR_NAME, STRING, DBMS_SQL.native);
RET := DBMS_SQL.EXECUTE(CURSOR_NAME);
EXCEPTION
WHEN OTHERS THEN
DBMS_SQL.CLOSE_CURSOR(CURSOR_NAME);
RAISE;
END;
DBMS_SQL.CLOSE_CURSOR(CURSOR_NAME);
END;
procedure that does something;
CREATE OR REPLACE PROCEDURE usefunc AS
CURSOR_NAME INTEGER;
RET INTEGER;
BEGIN
EXEC_SQL('insert into tt values (''fred'')');
END;
procedure to do something dynamically using execute immediate;
CREATE OR REPLACE PROCEDURE usevar(STRING
IN VARCHAR2) AS
CURSOR_NAME INTEGER;
RET INTEGER;
BEGIN
execute immediate STRING;
END;
SQL> execute usevar('begin usefunc ; end;')
PL/SQL procedure successfully completed.
SQL> select * from tt;
CHARS
fred
procedure to do something dynamically using dbms_sql;
CREATE OR REPLACE PROCEDURE usevar(STRING
IN VARCHAR2) AS
CURSOR_NAME INTEGER;
RET INTEGER;
BEGIN
EXEC_SQL(STRING);
END;
SQL> execute usevar('begin usefunc ; end;')
PL/SQL procedure successfully completed.
SQL> select * from tt;
CHARS
fred
fred
Pierre Lessard (guest) wrote:
: Hi!
: Looking for an example or a code equivalent for the system
: procedure "sp_executesql" in SQLServer 7 for Oracle 8... If you
: have any information of this kind, please send me a message.
: Thanks!
Turloch
Oracle Migration Workbench team
Oracle Technology Network
http://technet.oracle.com
null -
Implementing work queues? (or, "readpast equivalent in oracle?")
Without going to Advanced Queuing, is there a
more straightforward way to implement a work
queue?
As an example of what I'd like to do,
I have a table with rows, each row identifying some
work that has to be done.
I would like to have multiple processes pick up the
first available "unlocked" row, and select it for update.
When the work is done the process would update the row and
mark it done, and commit it, etc. If the process fails,
it would rollback and that will be the right behaviour
for my needs.
I think a SQL-server equivalent of the READPAST hint
to ignore row-locked entries would work nicely for what
I want to do, but I'm interested in other solutions, etc
for this problem?
Thanks,
-kbHello,
Two thoughts come to mind. You could have a Java Message Listener listening on a queue for an event and then do whatever you need to do after it has received that event.
The other option is to use the external procedure mechanism to invoke a bit of c code to start you Java code. A bit convoluted compared to the first option.
Thanks
Peter
Maybe you are looking for
-
Looking for All on one with USB Flash Drive Print/Scan support
I am looking for an All in One Print/scan/copy. It should support print from USB Flash drive and scan to the same. Thanks
-
I finally know why some of my files get corrupted. If you use the following method to assign one kind of file to always open with the same application; http://docs.info.apple.com/article.html?path=Mac/10.6/en/8387.html (File -> Get Info -> Open With
-
I cannot play music from my itunes library. I keep getting an itunes message that says, "The song could not be used because the original file could not be found." Is there a fix for this? Has this happened to anyone else? Is there a fix for this?
-
How do I pass Solid Edge- SAP configs on multiple computers
Hello All, How do I pass the 'User/System preferences -configs I did on Solid Edge side' on multiple computers on which I am installing the SE-SAP interface. Do I have to go to each machine, open the user/system preferences and then check the boxes,
-
Prompts me for a Safe Mode Password and the reenter
When I add a ADDS object powershell still prompts me for a Safe Mode Password and the reenter even thought I have the code below. Where am I going wrong? $SecurePassword = ConvertTo-SecureString "E#$rty1248" -Asplaintext -Force Install-ADDSForest ` -