How to use SQL syntax in Oracle fast formula - oracle

I want to use extract(DAY from date) function in Oracle FastFormula. However I am getting error when I used above. Is there a similar seeded functionality that I can use for this purpose?

By looking at the function reference for OracleFormula, it seems that you have no other option than calling TO_CHAR with the appropriate format to achieve the desired result. based on the doc's example:
mesg = 'Birthday is: ' + TO_CHAR (birthdate,
'DD')

Related

Check queries output type

I'm working with Oracle DB and faced with a problem. I cannot say for sure what the type will value have once the output is generated.
I have the following simple query:
select 1+'1234' from dual;
For me it's clear that the output "1235" will present a simple number. But how can I check that it is not converted into text afterwards for example? Is there any kind of "type_of" function which will help me with that?
Thank you in advance for your help!
You can use the dump() function:
select dump(1+'1234') from dual;
which will give you the datatype, as well as the byte values used to represent tha value, which you don’t seem to be interested in here.
Typ=2 Len=3: 194,13,36
where type 2 is NUMBER.
I think a way to find the return type would be to create a table using that query.
for eg.
create table temp_table_name1 as select 1+'1234' a from dual;
desc temp_table_name1;
Should give the type.
If you are worried about the return type then you can manually set it using
select Cast(1+'1234' As Varchar2(30)) a from dual;
OR
select Cast(1+'1234' As Number(4)) a from dual;

Oracle - applying the to_number function to a varchar column

I want to convert a varchar column into a number using the to_number function however I have some trouble understanding the order in which Oracle attempts to execute my SQL.
The statement looks like this;
select * from table where column is not null and to_number(column, '999.9') > 20
When Oracle executes this it throws an invalid number exception. I understand that Oracle optimized the SQL statement using some kind of relational algebraic formula however can someone tell me how I can safely use the to_number operator to achieve my goal?
can someone tell me how I can safely use the to_number operator to achieve my goal?
Unfortunately, you'll have to first filter out the rows with non-numerical data somehow before you apply to_number. The conversion function itself is "not safe", if you will, it will crash the whole query on a single invalid input.

Oracle last_ddl_time format

I have to query all_objects table where last_ddl_time='01 jan 2010' but it refuses the date format...
Any body give me the exact format to query?
As AKF said, you should be using Trunc unless you know the exact time the DDL was modified. Your query you added in the comments is looking for any objects where the DDL changed at 1/1/2010 00:00:00. Try:
SELECT *
FROM all_objects
WHERE trunc(last_ddl_time) = to_date('01-01-2010','dd-mm-yyyy');
I suggest you to use de date literal:
where trunc(last_ddl_time) = date '2010-01-01'
You can use the to_date function to format your date. If you enter a literal string, Oracle will attempt to convert that string using to_date with a default format 'DD-MON-YY', so your date would look like "01-JAN-10". As Oracle will be using this same function, you might want to put it in yourself and enjoy the finer granularity that custom formatting can provide.
It would be good to note that the dates stored in that column most likely have more precise dates, including hours and minutes, etc. Though you will be taking a bit of a performance hit, you might be better served using trunc(last_ddl_time) if you are testing with =.
There is some good info on Dates in Oracle at this link.
SELECT *
FROM all_objects t
WHERE trunc(t.last_ddl_time, 'DD') = to_date('2010-JAN-01', 'YYYY-MON-DD');

What's the equivalent of Oracle's to_char in AS400 DB2 SQL syntax?

I'm trying to display a DATE field fetched from a DB2 instance.
In Oracle I'd use something like:
to_char(v_date, 'YYYY-MM-DD')
What's the equivalent in AS400 DB2?
In V5R3 or later, use the CHAR() function. To get the same results as your Oracle example, use this:
char(v_date, ISO)
When using the CHAR() function with date fields, you can choose from the following formats: ISO, USA, EUR, JIS, and local. When using "local" as the format, it will use the attributes of the ODBC connection job, which will probably be the system-level values of date format and date separator. The other date formats are as such:
ISO = 'yyyy-mm-dd'
USA = 'mm/dd/yyyy'
EUR = 'dd.mm.yyyy'
JIS = 'yyyy-mm-dd'
In V5R4, you can use the varchar_format function. The only valid formats for this function are 'YYYY-MM-DD HH24:MI:SS' and 'YYYY-MM-DD'.
In V6R1 you have better formatting options for the varchar_format function. As mentioned in another answer, to_char is an alternative to varchar_format.
This should help:
http://www.ibm.com/developerworks/db2/library/techarticle/0211yip/0211yip3.html
It turns out that the DB2 equivalent to "to_char" is... "to_char".
:)
http://publib.boulder.ibm.com/infocenter/db2luw/v9/topic/com.ibm.db2.udb.admin.doc/doc/r0007108.htm
The underlying function is varchar_format, for which to_char is a synonym.

How do you convert SYS_GUID() to varchar?

In oracle 10g, how do you convert SYS_GUID() to varchar? I am trying something like:
select USER_GUID from user where email = 'user#example.com'
Which returns the RAW byte[]. Is it possible to use a function to convert the RAW to VARCHAR2 in the SQL statement?
Don't forget to use HEXTORAW(varchar2) when comparing this value to the RAW columns.
There is no implicit convesion from VARCHAR2 to RAW. That means that this clause:
WHERE raw_column = :varchar_value
will be impicitly converted into:
WHERE RAWTOHEX(raw_column) = :varchar_value
, thus making indices on raw_column unusable.
Use:
WHERE raw_column = HEXTORAW(:varchar_value)
instead.
Use RAWTOHEX(USER_GUID).
select RAWTOHEX(USER_GUID) from user where email = 'user#example.com'
Please don't mod-1 if I'm wrong. I'm going from memory so this a disclaimer to verify.
TO_CHAR is actually different between SQL and PL/SQL.
In SQL TO_CHAR does not take a raw as you have found out.
In PL/SQL To_CHAR will take a raw value.
So if you're in a procedure anyways, sometimes it easier to use a variable, but if you're just using SQL, go with the other answers here.
select CAST (USER_GUID AS VARCHAR2(100)) from user where email = 'user#example.com'

Resources