SUBSTR (to_char (Field))
You will need to find the age of the employee when joined the company. An employee may come and go a couple of times, for the last time that we just need to age the last time they join.Year joined is a numeric field.
DOB is a field DATE DD/MM/YYYY
Since I just need to know the year, or the last 4, I thought that I can use this calculation, but it does not work.
MAX (applied." "" 'Year')-substr (TO_CHAR (Emp.Dob),-4).
COURSES (PARTITION BY EMP. Emp_id)
Got a ' inconsistent or invalid data types used in the arithmetic operation.
Any ideas?
Thank you
Andy
Hello
Try using:
MAX (applied." Year') OVER (PARTITION BY EMP. Emp_id) - substr (TO_CHAR (Emp.Dob),-4)
or
(TO_DATE ('01 - JAN-' |)) To_char (MAX (applied." Year') OVER (PARTITION BY EMP. (Emp_id), 'fm9999') - Emp.Dob) / 356
Rod West
Tags: Business Intelligence
Similar Questions
-
Question about the Date and TO_CHAR fields
I ran into a date format today I need to replicate but I don't default with. I work with a based REST webservice that wants its dates and hours of formatting to ' 2009 - 09-29T 17: 00:00 - 04:00 '. When is 2009-09-29 17:00 et. Is there an easy way to reproduce this output in oracle, so I can feed him in the web service?You are looking for:
with my_tab as (select to_timestamp_tz('2009-09-29T17:00:00-04:00', 'yyyy-mm-dd"T"hh24:mi:ssTZH:TZM') col from dual) select to_char(col, 'yyyy-mm-dd"T"hh24:mi:ssTZH:TZM') ts_col from my_tab; TS_COL ------------------------- 2009-09-29T17:00:00-04:00
Published by: Boneist on October 6, 2009 16:59
Realized it's timestamp-> tank you were after, not the reverse. Fixed! -
ORA-01843 extraction time timestamp in a datetime field
Hello...
I have a field with mask of type datetime and format as HH24 data in the form. Now, I want to go for the only time in the table whose column with the timestamp data type in the field.
For example:
My domain is worktime (datetime) and my column in the table is working_dt1 (timestamp).
I tried following query
substr (to_char (working_dt1, 'DD-MM-AA HH24'), 10, 15);
but got error ora-01843...
could you please help me.
Thank you.909825 wrote:
Hello...
I have a field with mask of type datetime and format as HH24 data in the form. Now, I want to go for the only time in the table whose column with the timestamp data type in the field.For example:
My domain is worktime (datetime) and my column in the table is working_dt1 (timestamp).
I tried following querysubstr (to_char (working_dt1, 'DD-MM-AA HH24'), 10, 15);
but got error ora-01843...
could you please help me.
Thank you.
Try this...
to_date(to_char(working_dt1,'DD-MM-YY HH24:MI'),'DD-MM-YY HH24:MI')
Hope this will help you
If someone useful or appropriate, please mark accordingly.
-
Hi I have the following problem:
I have field: 10/10/2014, I need to turn in 2014.
I tried to use the substring like: substring ("field". "field" of 4 to 4) but I give the error message: ""
The formula syntax is not valid.
[nQSError: 10058] A general error occurred. [nQSError: 43113] The message returned by OBIS. [nQSError: 22020] Locate function does not support the types of non-text. (HY000)
How can I turn this type of text? I tried to use the cast function, but it does not work, just on hold.
Please let the front casting apply to string functions because you directly applying the string function under the date column.
Substring (cast ("field". "field" as varchar (20)) of 4 of 4) "
Try this...
Thank you
Prasanna
-
Missing expression error when cases is used as field
I tried to write an expression that calculates how many days ago a request and return a value defined by the user if the calculation falls under the criteria in the case statement. The SQL view for the query I use is shown below:
When I try to execute the query I get Message = ORA-00936: lack of expression (50 380)SELECT A.F_POSN_REQUEST_ID, A.F_REQ_ECP_STATUS, TO_CHAR(A.REQUEST_DTTM,'YYYY-MM-DD-HH24.MI.SS."000000"'), TO_CHAR(A.F_REQ_ST_DT,'YYYY-MM-DD-HH24.MI.SS."000000"'), TO_CHAR(A.F_REQ_ECP_ST_DT,'YYYY-MM-DD-HH24.MI.SS."000000"'), TO_CHAR(A.F_REQ_ECP_PROC_DT,'YYYY-MM-DD-HH24.MI.SS."000000"'), CASE WHEN(sysdate - TO_DATE(SUBSTR( TO_CHAR(A.F_REQ_ST_DT,'YYYY-MM-DD-HH24.MI.SS."000000"'),1,16),'YYYY-MM-DD-HH24.MI'))>60 THEN '>60' ELSE(CASE WHEN(sysdate - TO_DATE(SUBSTR( TO_CHAR(A.F_REQ_ST_DT,'YYYY-MM-DD-HH24.MI.SS."000000"'),1,16),'YYYY-MM-DD-HH24.MI')) >30 AND <=60 THEN '30 - 60' ELSE(CASE WHEN(sysdate - TO_DATE(SUBSTR( TO_CHAR(A.F_REQ_ST_DT,'YYYY-MM-DD-HH24.MI.SS."000000"'),1,16),'YYYY-MM-DD-HH24.MI'))>=15 AND <=30 THEN '15 - 30' ELSE(CASE WHEN(sysdate - TO_DATE(SUBSTR( TO_CHAR(A.F_REQ_ST_DT,'YYYY-MM-DD-HH24.MI.SS."000000"'),1,16),'YYYY-MM-DD-HH24.MI'))<15 THEN 'Less Than 15' ELSE NULL END)END)END)END)) FROM PS_F_POSN_REQUEST A WHERE A.F_REQ_ECP_STATUS IN ('I','O','P') GROUP BY A.F_POSN_REQUEST_ID, A.F_REQ_ECP_STATUS, TO_CHAR(A.REQUEST_DTTM,'YYYY-MM-DD-HH24.MI.SS."000000"'), TO_CHAR(A.F_REQ_ST_DT,'YYYY-MM-DD-HH24.MI.SS."000000"'), TO_CHAR(A.F_REQ_ECP_ST_DT,'YYYY-MM-DD-HH24.MI.SS."000000"'), TO_CHAR(A.F_REQ_ECP_PROC_DT,'YYYY-MM-DD-HH24.MI.SS."000000"')
Any suggestions you could provide to help me clarify this error would be greatly appreciated.
Published by: 992737 on March 8, 2013 09:07Hi, Peter,.
Peter Gjelstrup wrote:
... ORselect something, case your_expression when > 60 then '>60' when > 30 then '>30' when > 10 then '>10' . etc. end something_else
It really works when try you it?
A CASE of Simple Expression (where you have an expression just after the CASE keyword and before the first WHEN) only check for equality. To use the inequality operators (such as >) you must use an Expression looked for CASES , such as
CASE WHEN exp > 60 THEN ... WHEN exp > 30 THEN ...
Repeat the expression exp each time.
-
RTF model - region conditional on the text field
Try to filter certain records based on a report by adding a conditional region. The filters are effective in many areas. All of the following work:
<? If: EVENT_CLASS_CODE! = 'SETTINGS '? >
<? If: SEGMENT2! = '6500'? >
<? If: number (EVENT_ID)! = 1985001? >
However, I'm trying to filter on a longer text field:
<? If: LINE_DESCRIPTION! =' adding offset depreciation reserve - 25-MAY-12'? >
It is not effective - the filter just doesn't work. I guess it has to do with the length of the field or the existence of spaces. In the end, I need substr this field, but I'm not sure of the syntax to achieve this. I think it should be something like:
<? If: xdofx:substr(LINE_DESCRIPTION,1,36)! = "Adding offset depreciation Reserve"? >
- but is not seemt to work.
Any help would be greatly appreciated...Use this:
---
Thank you
Bipuser -
How to upgrade to the substring of a string value?
tried that precedes a TOAD and I had ' ORA-00927: lack of equal sign. " Help, please!UPDATE table1 SET SUBSTR (TO_CHAR(field_value),3,2) = ' 50' and SUBSTR (TO_CHAR(field_value),5,2) = '50' where ( SUBSTR(TO_CHAR(field_value), 3, 2) = '100' ) or ( SUBSTR(TO_CHAR(field_value), 5, 2) = '100' )
data type for field_value's number. is version of Oracle 10 g
Thank youHere is an example of how you can do:
SQL> CREATE TABLE x 2 AS 3 SELECT 'SOME50HERE' AS field_x 4 FROM dual; Table created. SQL> SELECT * FROM x; FIELD_X ---------- SOME50HERE 1 row selected. SQL> UPDATE x 2 SET field_x = SUBSTR(field_x,1,4) 3 || '75' 4 || SUBSTR(field_x,7) 5 ; 1 row updated. SQL> SELECT * FROM x; FIELD_X ---------- SOME75HERE
Basically, it must break your string into three parts:
1. the foregoing text you want to change.
2. the text that you want to change.
3. the part after the text you want to change.Then you concatenate them all together.
If #1 is not a fixed number of characters, you can still use SUBSTR, by searching for the string you want to edit as follows:
UPDATE x SET field_x = SUBSTR(field_x,1,INSTR(field_x,'50') - 1) || '75' || SUBSTR(field_x,7) ;
-
Count the number of fields in a record of CSV file
Hello
Here's my problem. I need to open a CSV file on a directory and to count the number of fields in a record. I can easily read the first record using the package UTL_FILE, something like:
UTL_FILE.fopen (s_remote_dir, s_csv_file, 'R', 32767);
UTL_FILE.get_line (input_file, buffer_entree);
then I count the number of commas in the buffer in order to get none. fields:
IF buffer_entree IS NOT NULL THEN
n: = < function that counts the number of commas in a string, buffer_entree >
END IF;
However, this method will not work If a comma is present within a field, that is to say:
127763, account "TRA", 1001, 34, _ "1007 main St., apt. 798 "_"
(last field contains a comma)
Please notify.
Kind regards
M.R.Here is an example of regexp Etbins solution:
SQL> declare 2 line varchar2(1000) := '127763, "TRA account", 1001, 34, "1007 main St., apt. 798", 42, "This, and that, and more"'; 3 fields number; 4 begin 5 fields := regexp_count(regexp_replace(line,'".*?"'),',') + 1; 6 dbms_output.put_line('Number of fields: '||to_char(fields,'TM9')); 7 end; 8 / Number of fields: 7
Edit:
Added the '+ 1', because the number of commas is a less number of fields ;-)Published by: Kim Berg Hansen on November 2, 2011 08:53
-
xdofx:substr and xdofx:instr do not work for variable incontext G1
Hello
I have a RTF I used variable incontext G1 for a group.
I have to do the substring and instring in a field. When I use xdofx:substr ($G1/field, instr($G1/field,'#1-',0) + 3, instr($G1/field,'#2',1)), I get no value because xdofx:substr does not work for incontext field! I don't know why.
so I used substring(), it works instead of xdofx:substr, but for instring, I studied, can't find anything for this.
Field: "#1 - TEST 0123456789 #2.
If I use substring($G1/field,3,4) - the output will be 'TEST '.
The question is how can I use instring inside substring() to operate for a $G1/field of incontext my code.
Thank you.You can use xdoxslt:instr, as in the example
-
substr, digital clob or error value
I run the script below Oracle 10g and I get "digital error or value in line 7. How to fix this error?
Looks like the problem is that "substr" function does not take arguments of type Clob?declare stmt clob := 'select 1/*'; x varchar2(100); begin stmt := stmt || lpad(to_clob('*'),60000, '*') || '*/ dummy from dual'; dbms_output.put_line('Length of statement: ' || length(stmt)); dbms_output.put_line('substr: ' || to_char(substr(stmt,1,30000)));--error execute immediate to_char(substr(stmt,1,30000)) || to_char(substr(stmt, 30001)) into x; dbms_output.put_line('Result: ' || x); end;
Something like:
SQL> ed Wrote file afiedt.buf 1 declare 2 stmt clob := 'select 1/*'; 3 x varchar2(32767); 4 begin 5 stmt := stmt || lpad(to_clob('*'),60000, '*') || '*/ dummy from dual'; 6 dbms_output.put_line('Length of statement: ' || length(stmt)); 7 dbms_output.put_line('substr: ' || DBMS_LOB.SUBSTR(stmt,200,1));--error 8 execute immediate DBMS_LOB.SUBSTR(stmt,200,1) || DBMS_LOB.SUBSTR(stmt,200,20)|| '*/ from dual' 9 into x; 10 dbms_output.put_line('Result: ' || x); 11* end; SQL> / Length of statement: 60028 substr: select 1/*********************************************************************************** Result: 1 PL/SQL procedure successfully completed. SQL>
Published by: AP on August 11, 2010 01:46
-
How to convert the timestamp in varchar2
How to convert
-timestamp
TO_TIMESTAMP (' 29.01.2015 08:36:41 ','fmDDfm.fmMMfm.YYYY fmHH24fm:MI:SS') of double
in
-varchar2
20150129083641
Hello
Maybe something like this:
select to_char(to_date(substr(to_char(TO_TIMESTAMP('29.01.2015 08:36:41','fmDDfm.fmMMfm.YYYY fmHH24fm:MI:SS')),1,17), 'dd.mm.yy hh24:mi:ss'), 'yyyymmddhh24miss') from dual;
But the question is: what do you do? Sorting? Or you have a (very) old data model with varchars or numbers to organize the date fields?
concerning
Kay
-
Arrondissement of time up to 15 min locations
guys, I would appreciate help on a question that I'm struggling with. I have a field time with, as you might expect, time in format HH24. What I want to do, is to break a time down in 15 minutes sections. IE 4 sections at the time.
These sections run A (take for example the time 15:00)) 15:00 - 15:14) 15:15-15:29, C) 15-30-15:44, D) 15:45 - 15:59
Basically if the current time falls into the section, I want it to be rounded to 15:00, if it falls in the b section, I want it to be rounded to 15:15, grave in round c until 15:30 and D round down at 15:45.
Is it possible, is there a way of nvl or decode to do such a thing?
Any help would be greatly appreciated.
Thank you.select substr(to_char(sysdate,'HH24MI'),3,4), case when substr(to_char(sysdate,'HH24MI'), 3,4) between 0 and 14 then substr(to_char(sysdate,'HH24MI'), 1,2) || ':00' when substr(to_char(sysdate,'HH24MI'), 3,4) between 15 and 29 then substr(to_char(sysdate,'HH24MI'), 1,2) || ':15' when substr(to_char(sysdate,'HH24MI'), 3,4) between 30 and 44 then substr(to_char(sysdate,'HH24MI'), 1,2) || ':30' else substr(to_char(sysdate,'HH24MI'), 1,2) || ':45' end from dual
François
-
Missing columns in an IR after re - build the Source of the region
Hello guys,.
I've added two new fields in a Source region (query) of an international registration, but they don't display, if I go on the button "Actions"-> "Select columns", and then hide side columns there, but I need them to appear as a default, the configuration of all of the fields are the same.
Here's the before code:
Then go to:SELECT PESS.ID, NVL(PESS.NOME_FANTASIA, PESS.DESCRICAO) DESCRICAO, CIDA.DESCRICAO||' - '||UFED.SIGLA CIDADE, DECODE(PESS.CNPJ, NULL, NULL, SUBSTR(TO_CHAR(PESS.CNPJ, 'FM00000000000000'), 1, 2) || '.' ||SUBSTR(TO_CHAR(PESS.CNPJ, 'FM00000000000000'), 3, 3) || '.' ||SUBSTR(TO_CHAR(PESS.CNPJ, 'FM00000000000000'), 6, 3) || '/' ||SUBSTR(TO_CHAR(PESS.CNPJ, 'FM00000000000000'), 9, 4) || '-' ||SUBSTR(TO_CHAR(PESS.CNPJ, 'FM00000000000000'), 13, 2)) AS CNPJ FROM (table) (JOIN's here) WHERE (conditions)
What should I change?SELECT PESS.ID, PESS.NRO_FONE TELEFONE, PESS.EMAIL EMAIL, NVL(PESS.NOME_FANTASIA, PESS.DESCRICAO) DESCRICAO, CIDA.DESCRICAO||' - '||UFED.SIGLA CIDADE, DECODE(PESS.CNPJ, NULL, NULL, SUBSTR(TO_CHAR(PESS.CNPJ, 'FM00000000000000'), 1, 2) || '.' ||SUBSTR(TO_CHAR(PESS.CNPJ, 'FM00000000000000'), 3, 3) || '.' ||SUBSTR(TO_CHAR(PESS.CNPJ, 'FM00000000000000'), 6, 3) || '/' ||SUBSTR(TO_CHAR(PESS.CNPJ, 'FM00000000000000'), 9, 4) || '-' ||SUBSTR(TO_CHAR(PESS.CNPJ, 'FM00000000000000'), 13, 2)) AS CNPJ FROM (table pess) (JOIN's here) WHERE (conditions)
Thank you
Alan.Actions, select columns (select the columns you want for all users to see..)
Save, save the report, actions like the default report parametersThank you
Tony Miller
Webster, TXTime passes fast like the wind, but the flies from fruits such as bananas.
If you answer this question, please mark the thread as closed and give points where won...
-
Table of functions and direct requests for NUMBER data types database
Hello. I call a number of functions table of our Enterprise BI server, and I chose to do this by using direct database requests (I believe you can also call functions table in the physical layer of the repository, but is not what I do). The problem is that whenever I go back any number of the table function which is not a whole number (1.23, for example), BI assigns the INTEGER data type to the field rather than the data type DOUBLE, rounded so my number to the nearest integer. Here is a short example:
Create these 3 database objects:
CREATE or REPLACE TYPE my_row AS OBJECT (my_num NUMBER);
CREATE or REPLACE TYPE my_tab AS TABLE OF THE my_row;
FUNCTION to CREATE or REPLACE my_table_function RETURN my_tab
PIPELINED IS
BEGIN
PIPE ROW (my_row (1.23));
END;
/
Make this your request at your request Direct to database:
SELECT my_num FROM table (my_table_function);
This query returns correctly '1.23' when it is called from the database. In BI, on the other hand, it returns a value of '1' (and the field of labels an INTEGER rather than data type DOUBLE). If at the request of data Direct you change column properties-> data-> decimal from 0 to 2 Format, then it displays is not surprising "1.00". I then tried to change MY_ROW. Data type of MY_NUM by explicitly specifying the precision and no luck. BI still labels this field as an INTEGER. Then I started to try to deceive BI massaging the SQL statement itself. None of the following worked:
SELECT to_number (my_num) as my_num2 FROM table (my_table_function);
SELECT my_num2 + 0.01 as my_num3 FROM (SELECT my_num - 0.01 AS my_num2 FROM table (my_table_function));
SELECT to_number (to_char (my_num)) as my_num2 FROM table (my_table_function);
SELECT to_number (substr (to_char ('x' | my_num), 2)) as my_num2 FROM table (my_table_function);
Now, I found a solution, but I'm surprised that I have to resort to that:
SELECT * FROM (SELECT / * + NO_MERGE * / table my_num (my_table_function));
Is anyone out there knows a better way to do it? The above is a hack in my opinion. :)
Thanks in advance for any input.
-JimYes, it's really amazing.
But I got it.CREATE OR REPLACE TYPE my_row AS OBJECT (my_num NUMBER(10,2));
and in your SQL:
SELECT cast(my_num as double precision) as my_num2 FROM table(my_table_function);
I have the good result and I see the numbers after the decimal point.
Very delicate!Published by: gerardnico on July 7, 2009 14:55 change number (10.2) in double precision... pffff
-
How to generalize the statement below box?
I have below logical case that I need to remove the coding hard of the year field based on the ranges of the year below. Perhaps using another function and make more generic?
insp_dt = Date
po_id = Varchar2 (5)
Expected result for season_year is:SELECT DISTINCT DECODE(SUBSTR(UPPER(a.PO_ID),1,1),'S','SP','U','SU','F','FA','H','HO')|| CASE WHEN TO_CHAR (a.insp_dt,'YYYY') < 1999 THEN '9' WHEN TO_CHAR (a.insp_dt,'YYYY') between 1999 and 2008 THEN '0' WHEN TO_CHAR (a.insp_dt,'YYYY') between 2009 and 2018 THEN '1' WHEN TO_CHAR (a.insp_dt,'YYYY') between 2019 and 2028 THEN '2' WHEN TO_CHAR (a.insp_dt,'YYYY') > 2028 THEN 'x' END ||substr(a.po_id,2,1) AS season_year FROM MAP.finished_goods_audit a
SP06 (SP + 0 + 6 obtained from the instruction box for spring 2006)
SU10 (SU + 1 + 0 obtained in the instruction box for summer 2010)
HO99 (HO + 9 + 9 from the instruction box for holiday 1999)What picking the third character in the string of the YEAR?
SUBSTR(TO_CHAR(a.insp_dt,'YYYY'),3,1)
Maybe you are looking for
-
How can I do for recovery Satellite Pro S300
Hello... I'm Frman of Kurdistan of Iraq Thank you for this forum to take all the outfit.I want to help me to recover my laptop. How can I make recovery my computer toshiba laptop satellite pro s300 with all the driver but I the depletion of my data i
-
iTunes organization: how to fix several "Various Artists".
Hello When I click on the 'Artists' view, everything is very well organized with the exception of three entries of Various Artists. I want all the albums with 'Various Artists' under the terms of the same artist section. Various Artists - main entry
-
When I go to opne phtos I stored in my pictures and documents they open to the word m ii in gobledegookThis has not happened before what has gone wrong.
-
How to buy a genuine replacement battery Motorola Atrix
I would like to have another, anyone know how to get one? Website of ATT, Motorola, don't list one. Of course, I could get Chinese knock-off batteries by the cargo, but those who are not reliable and could explode and aren't just worth the hassle. An
-
Cannot use double-click to open programs. Cannot use Microsoft Office.
The problem just started yesterday. My computer had a virus, one of those messages false antivirus and it took longer than normal to Norton to fix it, but he said that the problem had been resolved. Well, I have no more fake antivirus message, but