Error in PL/SQL function [closed] - plsql

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to create a function that divides min by 60, but when I compile, I received the error:
Compilation failed,line 8 (14:53:49) PLS-00103: Encountered the symbol "/" when expecting one of the following: (
Here's the code:
create or replace function "HORAS"
(min in NUMBER)
return NUMBER
is
hr NUMBER;
begin
hr:= (min) /(60);
return hr;
end;​

MIN is a built-in aggregate/analytic function, so the compiler is expecting it to be followed by arguments, hence the message saying it's expecting (.
Just change the argument name; you also don't really need to define an intermediate variable:
create or replace function HORAS (p_min in NUMBER)
return NUMBER
is
begin
return p_min / 60;
end;
/
select horas(345) from dual;
HORAS(345)
----------
5.75

Related

For loop includes zero [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I have fixed my problem by telling my loop to ignore instances of 0. But I don't know why it wants to include them in the first place.
P <- function(n) {
if (n <= 1) {
return (1)
}
s = 0
for (i in 1 : n - 1) {
if (i != 0) {
s <- s + P(i) * P(n - i)
}
}
return (s)
}
print (P(2))
It seems weird to include that in my loop, but without it I simply haven't been able to get the program to work. Not until I started putting in a trace to see what I was did I discover that i = 0. Did I write something wrong? I'm too new at R to even consider blaming this on the RGui that I'm using to run this, but I'm too old at programming to think anything else.
It is a precedent problem. ":" takes precedent over "-"
Compare:
n<-5
c(1: n -1)
c(1:(n-1))
This is because you forgot a parenthesis, see operator syntax & precedence :
n <- 2
1: n-1
[1] 0 1
1:(n-1)
[1] 1

(F# RProvider) mean giving a weird result - in some cases [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am starting to use the RProvider. For starters, I have just tried to evaluate functions in different ways. It seems I have already run into problems (perhaps a problem with my understanding of how the RProvider works). I have run the same function in four different ways, which I thought to be equivalent. However, the four example provides me with two different results.
R.sapply(R.c(1,2,3,4,5), R.eval(R.parse(text="mean"))).GetValue<float[]>()
// val it : float [] = [|1.0; 2.0; 3.0; 4.0; 5.0|]
R.sapply(R.c(1,2,3,4,5),"mean").GetValue<float[]>()
// val it : float [] = [|1.0; 2.0; 3.0; 4.0; 5.0|]
R.mean(R.c(1,2,3,4,5)).GetValue<float[]>()
// val it : float [] = [|3.0|]
R.eval(R.parse(text="mean(c(1,2,3,4,5))")).GetValue<float[]>()
// val it : float [] = [|3.0|]
Can anyone tell me why this is? My own guess is that R.sapply applies the given function element-wise. But how do I get around this?
do.call() is the function in R for "applying" a function to a list of parameters (a slightly different meaning from applying or mapping a function over a vector or list of values, which is what the *apply family does).
The R function for what you want would be
do.call("mean",list(c(1,2,3,4,5)))
According to the comments (I don't speak F# myself), the F# analogue would be:
R.do_call("mean", R.list(R.c(1,2,3,4,5)))

Why do Clojure vector function results exclude the stop value? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Forgive me for the newb question and potentially incorrect terminology.
Clojure vector functions produce values that do not include the stop value. For example:
=> (subvec [:peanut :butter :and :jelly] 1 3)
[:butter :and]
=> (range 1 5)
(1 2 3 4)
The doc for range explicitly states this but doesn't give a rational: "...Returns a lazy seq of nums from start (inclusive) to end (exclusive)...".
In Ruby these operations are inclusive:
(1..5).to_a
=> [1, 2, 3, 4, 5]
[:peanut, :butter, :and, :jelly][1,3]
=> [:butter, :and, :jelly]
Obviously these are very different languages, but I'm wondering if there was some underlying reason, beyond a personal preference by the language designers?
Making the end exclusive allows you to do things like specify (count collection) as the endpoint without getting an NPE. That's about the biggest difference between the two approaches.
It might be that the indexing was chosen in order to be consistent with Java libraries. java.lang.String.substring and java.util.List.subList both have exclusive-end indexes.

Is there a way to generate a unique random 6 digit number? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Is there a way using vb.net to generate a random 6 digit number that is unique? So there are no duplicate random numbers?
I tried the following code but it says "Type Char has no contructors"
Dim chars As String = "0123456789"
Dim word As Char() = New Char(6)
Dim rnd As New Random()
For i As Integer = 0 To word.Length - 1
word(i) = chars.Chars(rnd.Next(chars.Length))
Next
TheTextBox.Text = New String(word)
Wouldn't this do? Meaning increment the number for each record or whatever it's used for. Guarantees unique.
Dim number as integer = 100000
'do stuff
number +=1
Try..
Dim randomNumber As Integer
Randomize()
randomNumber = Int((100000* Rnd()) + 1)
MsgBox(randomNumber)
Personally, I'd use a Linear Feedback Shift Register with 20 bits. That's 1,048,575 different values instead of exactly 1000000, but hopefully close enough.
Just remember to keep the current seed value around between runs if you want to maintain uniqueness!
See: https://en.wikipedia.org/wiki/Linear_feedback_shift_register

Why does my calculator return true for 2^34 == 2^34 - 1? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I'm asking this question here because I believe this is more of a programmatic issue than anything else.
I'm using a TI-84 Plus Sliver Edition calculator that contains logical operators that can test for less-than, greater-than, and equality. I find that when I input the expression:
2^34 == 2^34 - 1
it gives me a surprising 1 for true. It's worth mentioning that my calculator can't precisely output the result of 2^34. Rather, it uses the exponential notation for it and any other powers greater than 33. Is this a potential factor in the boolean output?
Furthermore, the equality test only returns true if the second expression is subtracting by 1 to 9. When the number is >= 10 it then correctly returns false.
Could it be a rounding error? Why is this expression returning true?
Your calculator cant keep track of numbers that large.
Every calculator has a set level of precision (lets say 10 digits). Every answer the calculator gives is rounded so that the answer has that many digits, then it shifts the decimal place as much as it needs to in order to make the number big or small (in your case very large).
Your number is so large that when you subtract 1, that causes a change after the 10th digit. This then gets rounded back to what you started with, and then compared. So naturally, it thinks they are the same number (to the precision it is capable of).

Resources