How to use + between TIME_SPAN - ada

The question is about using the operator + between TIME_SPAN , for example:
T1 : ADA.REAL_TIME.MICROSECONDS(10);
T2 : ADA.REAL_TIME.MICROSECONDS(20);
T3 := T1 + T2
But the error that I get is:
Binary operator "+" between Time_Span and Time_Span not directly visible, use clause or conversion might be needed"
Thanks in advance.

The message means that you need a "use clause" to make the + operator for Ada.Real_Time.Time_Span directly visible:
Example :
declare
use type Ada.Real_Time.Time_Span;
begin
T3 := T1 + T2;
end Example;

Related

Extract specific matching text from a string column

[The picture contains error message column(input) and err codes column (which i want the output)
I have some error codes (like 40000097,40000083 , 40000109 etc), if the error codes are there in the input text(error message) then that error code should reflect as output , if more than one error codes present then those should reflect in the output seperated by comma(,).
Please help me .. Thanks in advance ]1
create or replace function split(i_str in varchar2)
return sys.odcivarchar2list pipelined is
begin
for i in 1..length(' '||regexp_replace(i_str, '[^ ]+')) loop
pipe row (regexp_substr(i_str, '[^ ]+', 1, i));
end loop;
end;`
--using below code trying to fetch, but in the error_message if there is no space before the error_code(ie, error_message like 'lkjkkjlkjl40000097 ' then it is not identifying, if the error_message like 'lkjkkjlkjl 40000097 ') then it is identifying... please suggest me the necessary changes to be done in the below code or in the function)
select chk.*,Error_codes
from CHECK_ chk
join
(select CLAIM_NO,
listagg(t2.column_value, ',') within group (order by rn, c1, c2) Error_codes
from (select rownum rn, c1,c2,CLAIM_NO from (select CLAIM_NO,Error_Message c1,'40000109 40000083 40000098 40000101 40000076 40000097 40000088 40000081' c2 from CHECK_)) t
cross join table(split(c1)) t1
left join table(split(c2)) t2 on t2.column_value = t1.column_value
group by rn,CLAIM_NO)ss on chk.CLAIM_NO=ss.CLAIM_NO`

R, ClickHouse: Expected: FixedString(34). Got: UInt64: While processing

I am trying to query data from ClickHouse database from R with subset.
Here is the example
library(data.table)
library(RClickhouse)
library(DBI)
subset <- paste(traffic[,unique(IDs)][1:30], collapse = ',')
conClickHouse <- DBI::dbConnect('here is the connection')
DataX <- dbgetdbGetQuery(conClickHouse, paste0("select * from database
and IDs in (", subset ,") ", sep = "") )
As a result I get error:
DB::Exception: Type mismatch in IN or VALUES section. Expected: FixedString(34).
Got: UInt64: While processing (IDs IN ....
Any help is appreciated
Thanks to the comment of #DennyCrane,
"select * from database where toFixedString(IDs,34) in
(toFixedString(ID1, 34), toFixedString(ID2,34 ))"
This query subset properly
https://clickhouse.tech/docs/en/sql-reference/functions/#strong-typing
Strong Typing
In contrast to standard SQL, ClickHouse has strong typing. In other words, it doesn’t make implicit conversions between types. Each function works for a specific set of types. This means that sometimes you need to use type conversion functions.
https://clickhouse.tech/docs/en/sql-reference/functions/type-conversion-functions/#tofixedstrings-n
select * from (select 'x' B ) where B in (select toFixedString('x',1))
DB::Exception: Types of column 1 in section IN don't match: String on the left, FixedString(1) on the right.
use casting toString or toFixedString
select * from (select 'x' B ) where toFixedString(B,1) in (select toFixedString('x',1))

PLSQL Encountered the symbol "YES" when expecting one of the following

Hi I am trying to create aa table of summary stats using PLSQL. I am new to PLSQL. I keep getting this error.
Encountered the symbol "YES" when expecting one of the following
Below is my code.
DECLARE
AGE NUMBER;
CAMPAIGN NUMBER;
PDAYS NUMBER;
PREVIOUS NUMBER;
POUTCOME NUMBER;
EMP_VAR_RATE NUMBER;
CONS_PRICE_IDX NUMBER;
CONS_CONF_IDX NUMBER;
EURIBOR3M NUMBER;
Y VARCHAR;
BEGIN
EXECUTE IMMEDIATE ('
CREATE TABLE SUMMARY_STAT
AS
SELECT
ROUND(AVG(AGE)) AS AVERAGE_AGE
,ROUND(AVG(CAMPAIGN)) AS AVERAGE_CONTACTS_MADE
,ROUND(AVG(PDAYS)) AS NO_DAYS_PASSED
,ROUND(AVG(PREVIOUS)) AS AVERAGE_PREVIOUS_CONTACTS_MADE
,ROUND(AVG(EMP_VAR_RATE)) AS AVERAGE_EMPLOYEE_VARIATION
,ROUND(AVG(CONS_PRICE_IDX)) AS AVERAGE_CONSUMER_PRICE_INDEX
,ROUND(AVG(CONS_CONF_IDX)) AS AVERAGE_CONSUMER_CONFIDENCE_INDEX
,ROUND(AVG(EURIBOR3M)) AS AVERAGE_EURIBOR
,COUNT(CASE WHEN Y = 'yes' THEN 1 end) AS NUMBER_CUSTOMERS_TOOK_DEPOSIT
,COUNT(CASE WHEN Y = 'no' THEN 1 end) AS NUMBER_CUSTOMERS_DIDNT_TAKE_DEPOSIT
FROM BANK_DATA
');
END;
The problem is you have single quotes within a larger string. Unfortunately from the interpreter's view point your string in 'Create ... when Y = ' is one string and the next token is the word "yes" which the interpreter does not understand.
You have 2 options:
double the quotes needed inside the larger string.
use the alternative quote delimiter.
Using quote delimiter you get:
BEGIN
EXECUTE IMMEDIATE (q'[
CREATE TABLE SUMMARY_STAT
AS
SELECT
ROUND(AVG(AGE)) AS AVERAGE_AGE
,ROUND(AVG(CAMPAIGN)) AS AVERAGE_CONTACTS_MADE
,ROUND(AVG(PDAYS)) AS NO_DAYS_PASSED
,ROUND(AVG(PREVIOUS)) AS AVERAGE_PREVIOUS_CONTACTS_MADE
,ROUND(AVG(EMP_VAR_RATE)) AS AVERAGE_EMPLOYEE_VARIATION
,ROUND(AVG(CONS_PRICE_IDX)) AS AVERAGE_CONSUMER_PRICE_INDEX
,ROUND(AVG(CONS_CONF_IDX)) AS AVERAGE_CONSUMER_CONFIDENCE_INDEX
,ROUND(AVG(EURIBOR3M)) AS AVERAGE_EURIBOR
,COUNT(CASE WHEN Y = 'yes' THEN 1 end) AS NUMBER_CUSTOMERS_TOOK_DEPOSIT
,COUNT(CASE WHEN Y = 'no' THEN 1 end) AS NUMBER_CUSTOMERS_DIDNT_TAKE_DEPOSIT
FROM BANK_DATA
]');
END;

Evaluating string/combination of variables as logical expression in oracle pl/sql

In my Pl/Sql code , I have three variables v_var1 , v_operand , v_var2 whose values are populated based on some logic (v_var1 & v_var2 can be date , number , varchar. Associated Operand will be according to data type only). A sample would be
v_var1 = 10 , v_operand = '=' , v_var2 = 20.
Based on these value , I have to evaluate whether the condition "v_var1 -v_operand- v_var2"is true or false.
Ex :- with above values, I have to evaluate whether 10 equals 20 or not.
How can I achieve this ? Can I pass the whole string as '10 = 20' to some function and get the result as false?
One way I can think of is to write CASE statements for evaluating but can there be a better way ?
You could use dynamic SQL to do the evaluation as a filter on the dual table:
declare
v_var1 varchar2(10) := '10';
v_operand varchar2(10) := '=';
v_var2 varchar2(10) := '20';
l_result number;
begin
execute immediate 'select count(*) from dual where :var1 ' || v_operand || ' :var2'
into l_result using v_var1, v_var2;
if l_result = 1 then
dbms_output.put_line('True');
else
dbms_output.put_line('False');
end if;
end;
/
PL/SQL procedure successfully completed.
False
If the condition is true the count will get 1, otherwise it will get 0, and you can then test that via the local variable you select the count into.
Holding dates and numbers as strings isn't ideal, even temporarily, but might be OK as long as you convert to/from the real data types consistently, e.g. always explicitly converting dates with to_date and to_char and specifying the format masks.

Simple Procedure raise ORA-06502

There's the simplified version of my code who keep raise me ORA-06502:
declare
p_filter varchar2(300) := '2012';
p_value varchar2(300) := '12345.000';
w_new_value number(13,3) := null ;
w_count number(4) := null ;
BEGIN
SELECT count(*)
INTO w_count
FROM dual
where p_filter = p_filter;
--- more filters
if w_count != 0 then
w_new_value := p_value / w_count;
else
w_new_value := p_value;
end if;
-- do something
end;
/
Someone can give me a help?
DataBase Details
nls_language = italian
nls_territory = italy
nls_currency = �
nls_iso_currency = italy
nls_numeric_characters = ,.
nls_calendar = gregorian
nls_date_format = dd-mon-rr
nls_date_language = italian
nls_characterset = we8iso8859p15
nls_sort = west_european
nls_time_format = hh24:mi:ssxff
nls_timestamp_format = dd-mon-rr hh24:mi:ssxff
nls_time_tz_format = hh24:mi:ssxff tzr
nls_timestamp_tz_format = dd-mon-rr hh24:mi:ssxff tzr
nls_dual_currency = �
nls_nchar_characterset = al16utf16
nls_comp = binary
nls_length_semantics = byte
nls_nchar_conv_excp = false
First, this is always going return a value of 1.
SELECT count(*)
INTO w_count
FROM dual
It doesn't matter what the qualifier is.
Lastly, I just ran your simplified code example in Oracle 11R2 and it didn't throw an exception.
I added the following statement in place of your "do something" comment:
dbms_output.put_line('w_new_value: ' || w_new_value || '. w_count: ' || w_count);
The result was:
w_new_value: 12345. w_count: 1
So, I think you've simplified your example into oblivion. You need to provide something that actually shows the error.
Good luck.
I found myself the ansewer and i think is useful for other know.
The real problem of the script for my DB is the language.
The italian "version" of Oracle accept , instead of the . for translate the VARCHAR2 into NUMBER unlike the most of other country.
For make the code running well the solution is
w_new_value := replace(p_value,'.',',') / w_count;
This trick finally allows the DB use my VARCHAR2 param like a NUMBER

Resources