Oracle: ISO Week, wrong answer - oracle

In Oracle 11 and Oracle 12, issuing the following select:
SELECT TO_CHAR((TO_DATE('19720101','YYYYMMDD')), 'YYYYIW') || ' ' || TO_CHAR((TO_DATE('19721230','YYYYMMDD')), 'YYYYIW') AS ERRATO FROM DUAL;
I get:
197252 197252
I expected something like:
197152 197252 or 197153 197252
Why do I get the same result 197252 197252?

You're currently formatting with 'YYYYIW' which is the 4 digit year, followed by the ISO week-of-year. I suspect you want the ISO week-year, followed by the ISO week-of-year.
The Oracle documentation is very unclear on this, but you should try 'IYYYIW' as the format string instead. That uses the "4-digit year based on the ISO standard" (IYYY).
(I'm trying to run that on sqlfiddle to see if it works, but it's hung at the moment...)

Related

Getting error in vertica:Function catalog.btrim(int) dose not exist, or permission is denied for catalog.btrim(int)

I am trying to execute below query in vertica:
select
case when count(*) = 0 then #{aaa} || #{bbb}
else
trim(cast(max(ccc)+1 as intger))
end
as ccc
from apple where aaa = #{aaa}
Query is getting expected results in tera but in Vertica Getting error.
How can I do this?
Check the Vertica docu:
https://www.vertica.com/docs/10.0.x/HTML/Content/Authoring/SQLReferenceManual/Functions/String/BTRIM.htm
BTRIM() removes the blank characters (by default, if not specified as the second parameter) from a passed string. You can't BTRIM() a number.
Why would you want to trim an integer, in trim(cast(max(ccc)+1 as int**e**ger)) ? It makes no sense at all!. Teradata should complain, too.

How to convert this date format

I have wierd date format:
ID, Time, Value 1 [mg/l]
9867, 43788.5946644, 5.266029
9851, 43788.5529745, 5.526279
9835, 43788.5113079, 6.008881
and I would like to convert it, but I can not even recognize this one. an anyone help me? It might be conversion to timestamp, simple date or anything else that is readable.
I know the outputs:
43788.5946644 - 19/11/2019 14:16
43788.5529745 - 19/11/2019 13:16
43788.5113079 - 19/11/2019 12:16
By accident I found an answer, this is a excell date. https://www.excel-exercise.com/date-format-in-excel/
can be converted using powershell command:
[DateTime]::FromOADate(43788.5946528) -> Tuesday, November 19 2019 14:16:18

finding date before 30 days in hive-0.10.0

I have 2 hadoop clusters, One has hive-0.10.0 installed and another has hive-1.1.0 version installed.
I am able to run below query in hive-1.1.0 which gives date before 30 days from present date
select date_sub(from_unixtime(floor(unix_timestamp()/(60*24*24))*60*24*24), 30)
But, the Same query is giving syntax error in hive-0.10.0
ok failed: parseexception line 1:79 mismatched input '' expecting from near ')' in from clause
1.
Way too complected.
This will get you the same result:
select date_sub(from_unixtime(unix_timestamp()),30)
2.
Queries without FROM clause are only supported from hive 0.13
https://issues.apache.org/jira/browse/HIVE-178
Create s table with a single row (similar to Oracle dual) and use it as source

Does Perl DBI Support Oracle Subquery Factoring?

I have searched online for several days and cannot find an answer.
Does Perl DBI support Oracle Subquery Factoring (i.e. WITH-clause)?
As an example, the simple Perl DBI application further below fails with the error:
DBD::Oracle::st fetchrow_array failed: ERROR no statement executing (perhaps you need to call execute first)
Simple Perl DBI Application:
#!/bin/perl
use DBI;
my $sql = <<END_SQL;
WITH w AS
(
SELECT wafer_seq
FROM wafer
WHERE load_time > sysdate - 1
)
SELECT v.*
FROM vwafer v, w
WHERE v.wafer_seq = w.wafer_seq
ORDER BY v.wafer_seq
END_SQL
my $dbh = DBI->connect('DBI:Oracle:<schema_id>', '<username>', '<password>');
my $sth = $dbh->prepare($sql) || die "ERROR PREP";
$sth->execute() || die "ERROR EXEC";
while (my #row = $sth->fetchrow_array())
{
print "#row\n";
}
$sth->finish();
$dbh->disconnect();
exit 0;
This same application will work if I simply change the SQL to:
SELECT v.*
FROM vwafer v,
(
SELECT wafer_seq
FROM wafer
WHERE load_time > sysdate - 1
) w
WHERE v.wafer_seq = w.wafer_seq
ORDER BY v.wafer_seq
Finally, I confirmed that both SQLs mentioned above work when executed directly in a database visualizer application (e.g. DBVisualizer).
It appears my version of Perl (5.8.8), DBI (1.58), and/or DBD::Oracle (1.19) do not support Oracle Subquery Factoring.
I was able to successfully execute the same Perl application through updated Perl (5.12.1), DBI (1.613), and DBD::Oracle (1.24) versions.
Unfortunately, even after reading change histories for Perl, DBI, and DBD::Oracle, I do not know exactly which component introduced support of Oracle Subquery Factoring. My suspicion is the DBI Oracle driver (DBD::Oracle).
Perl DBI correctly processed 'WITH' clause.
I just now check it and test your code
According to error there is may by only one case You forget to call
$sth->execute();
Double check please are it called, may be it was commented or something else.
But your code work correct.

Why isn't hextoraw() functioning, Am I misunderstanding it?

I'm running Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production, and I'm trying to convert a few hex characters to a string:
SQL> select hextoraw('414243') from dual;
HEXTOR
------
414243
But it seems nothing has been done here, am I miss understanding this macro?
Because the tools displays the result as string, so it seems nothing changed. Actually the datatypes are different, please use below SQL to check:
SQL> SELECT DUMP('414243'),DUMP(HEXTORAW('414243')) from dual
A B
-------------------------------- --------------------------------------
Typ=96 Len=6: 52,49,52,50,52,51 Typ=23 Len=3: 65,66,67
I believe SQL*Plus is just formatting the RAW to a format convenient for display.
HEXTORAW('414243') converts your string to the RAW(3) consisting of [0x41 0x42 0x43]. Then, when sqlplus tries to display that value back to the user, it converts it to something it can print to the terminal.
Here is a SQL Fiddle, but it looks like it displays the RAW value in base-10 format rather than hex. I'm not sure if there is a format command for sqlplus to change this behavior.
select hextoraw( '414243' ) as col1,
utl_raw.cast_to_varchar2( hextoraw( '414243' )) as col2
from dual;
| COL1 | COL2 |
|----------|------|
| 65,66,67 | ABC |

Resources