DOT(.) after Ampersand (host variable)& considering as a part of variable name? - plsql

I know heading is not so clear.This is the picture
I am using &a it is considering it as $a. ,in the output &a and &a. is giving the same output. and why single .(DOT) after &a is giving no error but if we put any character, operator or wild characters after &a gives error.
This is the code.
BEGIN
FOr i in &&a...3 LOOP
DBMS_OUTPUT.PUT_LINE(i||' '||&a.||' '||&a);
END LOOP;
END;
Output Coming
1 1 1
2 1 1
3 1 1

The dot is a delimiter for the & define. In most cases you won't notice a difference, but if you for some reason didn't have whitespace or similar after the variable name it could cause confusion. For example, if you were concatenating something with your variable in a string, '&asomething', it would ask for a variable named 'asomething'. If you did it as '&a.something' then it would ask for a variable named 'a' and tack 'something' on the end of whatever value is supplied. Any other character after the &a would be treated as either part of the variable name or would cause an error if it isn't valid as part of the name.

Related

Ada.Strings.Fixed.Index unexpected results in loop

I have a simple procedure which splits a string and then searches substrings inside them. I'm getting weird results but I dont quite grasp why. I suspect it might be related to Ada evaluation strategy or something like that.
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with GNAT.String_Split; use GNAT;
procedure Split_Test is
Subs : String_Split.Slice_Set;
begin
String_Split.Create (Subs, "abcdSEPabcd", "SEP", String_Split.Multiple);
for Substring of Subs loop
declare
Idx : Integer := Index(Substring, "abc");
begin
Put_Line("index of abc is" & Integer'Image(Idx) & " within string " & Substring);
end;
end loop;
end;
When I run it, i get:
index of abc is 1 within string abcd
index of abc is 8 within string abcd
Clearly index of abc should be 1 on both iterations. What's the issue here?
Ada allows for strings to be indexed starting at any valid Positive value. What it appears is that the GNAT split function (Create) is simply ensuring that the substrings use the same indexes as their data had in the original combined string. Which is useful for finding the original index of the value you are looking for.
If you want the answer to always be 1 for the first index, you'll need to do the legwork of subtracting Substring'First and adding 1 to the index, but honestly there shouldn't be any need for that. Just make sure your code handling the substring always uses operations relative to Substring'First and it won't matter what the first index is.

How to print unique numbers dynamically with PLSQL

I would like to display Unique numbers dynamically. I have tried below code for the same but same number is displaying all the times.
DECLARE
a NUMBER;
BEGIN
FOR i IN 1 .. 3 LOOP
DBMS_OUTPUT.PUT_LINE(&a);
END LOOP;
END;
the above code will ask me for "a" value three times, if i pass 1,2,3 as parameters then it should display 1,2,3 but this code is displaying first(1) value three time as 1,1,1.
Could you please help me to get the required output like 1,2,3
You can't really create an interactive program in just PL/SQL. When you put &a in the PL/SQL and run it in a tool like SQL Developer, it prompts you once for a value for a before it runs the code, using the value you typed instead of the substitution variable a.
You want to print i and not a. Also the ampersand in front of the a means you will be prompted to enter a value for a.

urc_id_SEQ.nextval gives invalid identifier error?

I have created a sequence but it gives me invalid identifier error. I am running select urc_id_SEQ.nextval from dual;
Rebuild the sequence without using double quotes in the command. If you use double-quotes it makes the name case sensitive and then you must always use double quotes to reference the object. Eliminating the quotes keeps the object name case-insensitive.
CREATE SEQUENCE A.urc_id_SEQ MINVALUE 1 MAXVALUE 9999999999 INCREMENT BY 1 START WITH 1 NOCACHE ORDER NOCYCLE;

when the variable is set before array is used, it is not working.

i am new to unix. i am trying to dump out a few files based on the array that is set.
for example:
set my_n = Apple
arrayme="fruit name misc"
for x in $arrayme; do
echo "I am $my_n" > $my_n_$x.txt
done
where i would like the output files to be :
Apple_fruit.txt, Apple_name.txt, Apple_misc.txt
i want to set this $my_n so that i can reuse for other $my_n variable that could be set upon it. but i not able to get it working. need help to take alook on the syntax above.
Thank you.
On line 1, the use of set in not needed. Do not add spaces between the variable name & and equals, and equals & value.
On line 5 you must enclose the variable my_n in curly braces to distinguish it from the underscore separator you use.
1 my_n=Apple
2 arrayme="fruit name misc"
3
4 for x in $arrayme; do
5 echo "I am $my_n" > ${my_n}_$x.txt
6 done
This updated code should work as expected.

Removing grave accent (`) from the names of a list in R

I have list l which has grave accent "`" in output. Why am I getting this in some variable and not in others?
l
$`AMLM12PAH037A-B`
Left.Gene.Symbols Right.Gene.Symbols
PCMTD1 0 1
STK31 3 0
$AMLOT120AT
Left.Gene.Symbols Right.Gene.Symbols
ARHGEF3 2 0
CD96 2 0
RALYL 12 0
TRIO 0 1
You can't have invalid names, in this case it is the - inside it. If you do, you will either get them backticked, like yours, converted, or an error depending on how you made them.
You also cannot start a name with a number among other restrictions.
See the functions check.names and make.names
From the R FAQ:
A syntactic name is a string the parser interprets as this type of expression. It consists of letters, numbers, and the dot and (for
versions of R at least 1.9.0) underscore characters, and starts with
either a letter or a dot not followed by a number. Reserved words are
not syntactic names.
An object name is a string associated with an object that is assigned in an expression either by having the object name on the
left of an assignment operation or as an argument to the assign()
function. It is usually a syntactic name as well, but can be any
non-empty string if it is quoted (and it is always quoted in the
call to assign()).
An argument name is what appears to the left of the equals sign when supplying an argument in a function call (for example,
f(trim=.5)). Argument names are also usually syntactic names, but
again can be anything if they are quoted.
An element name is a string that identifies a piece of an object (a component of a list, for example.) When it is used on the right
of the ‘$’ operator, it must be a syntactic name, or quoted.
Otherwise, element names can be any strings. (When an object is
used as a database, as in a call to eval() or attach(), the element
names become object names.)

Resources