Declare a varray in a function
hello,
i wanna know how declare a varray of number(13,3) in a function, without declaring it as a new type
regards
Elyes
Just declare type in your function. E.g.:
CREATE OR REPLACE
FUNCTION F1
RETURN NUMBER
IS
TYPE varray_numbers IS VARRAY(35) OF NUMBER(13,3);
v_varray varray_numbers := varray_numbers();
BEGIN
v_varray.extend(5);
v_varray(5) := 5;
RETURN 1;
END;
/SY.
Similar Messages
-
Why do I have to declare my int outside the function?
`Hi!
I've writen the very simple class get_results with one methode test:
public class Get_results {
protected int nb=0;
public int test(int numb) {
//int nb=0;
nb=numb;
return nb;
}//End test
}//End classthis methode will be called from a jsp file:
<jsp:useBean id="results" scope="session" class="mypackage.Get_results" />
<%= results.test(3) %>I don't understand why I have to declare int nb outside the function test. If I declare int nb at the beginning of the function and not right at the beginning of the class
public class Get_results {
public int test(int numb) {
int nb=0;
nb=numb;
return nb;
}//End test
}//End classthe it doesn't work. I don't understand why since I only need the int nb in the test methode and nowhere else in the class.
can anyone explane this to me?
thanks.
Message was edited by:
ChristopheD
Message was edited by:
ChristopheDI get this message:
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: 2
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.ArrayIndexOutOfBoundsException: 2
org.apache.jsp.grammaire_002dresults_jsp._jspService(grammaire_002dresults_jsp.java:219)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
Message was edited by:
ChristopheD -
HOWTO: Declare a variable within a function.
I'm having a hard time declaring a variable within a function. This is my code:
CREATE OR REPLACE FUNCTION schemaName.functionName (inParam VARCHAR2(20))
RETURN VARCHAR2 IS VARCHAR2(10)
BEGIN
DECLARE paramLength NUMBER; --This is not working. The docs do not state what the size of the number returned by LENGTH is.
SELECT LENGTH(inParam) INTO paramLength FROM DUAL;
IF paramLength < 10 THEN
RETURN '';
ELSE
/* Clean up the value */
RETURN inParam
END IF;
END;In relation to your own code...
CREATE OR REPLACE FUNCTION schemaName.functionName (inParam VARCHAR2(20)) RETURN VARCHAR2 IS
paramLength NUMBER;
BEGIN
/* Clean up the value */
paramLength = LENGTH(inParam);
IF paramLength < 10 THEN
RETURN NULL;
ELSE
RETURN inParam
END IF;
END; You don't need to use SQL to determine the length of a string. -
Custome BAPI - declare ITAB and define the Function Module and Subroutine
Hello Experts
I want to create a Custom BAPI and it has the following scenario:
1) a Function Module which collects some records into it internal table, say ITAB
2) a Subroutine which moved the records from ITAB to BAPI table
Now, I want to declare ITAB and define the Function Module and Subroutine.
Where and How can I do this?
Plz suggest.
Regards
BDHi,
1) Got to SE37 and create an RFC .
2) Declare the ITAB directly in the TABLES tab of the FM.
3) Inside the FM source Code tab, collect all the data using SELECT query and directly or by using logic, put the data into the
ITAB.
4) Since the data collected is directly put into the itab you dont need a subroutine to be written.
5) If subroutine is a necessity, then just write PERFORM SUB ROUTINE NAME.
AND DEFINE THE FORM ENDFORM OF THE SUBROUTINE AFTER THE ENDFUNCTION OF THE FM
Let me know if any issues....
Regards,
Vimal. -
Constant declaration of VARRAY index by varchar2 within package header
Hi there
I'm looking for the correct syntax to declare a constant
of a varray type which is indexed by varchar2. I've tried
the following:
create or replace package nl_types
is
TYPE nt_assoc_small IS TABLE OF INTEGER INDEX BY VARCHAR2(32);
nl_bindcnt constant nt_assoc_small ('xml_gkregnl') := 3;
end;
I know this array hat just one element, but there will
be even more when I got this example case to work. As
I tried to compile this package, the compiler said:
13/16 PL/SQL: Declaration ignored
13/25 PLS-00566: type name "NT_ASSOC_SMALL" cannot be constrained
13/70 PLS-00320: the declaration of the type of this expression is
incomplete or malformed
O.K. then: Does anybody know the "wellformed" declaration
for this kind of varray?
Thanx in advance,
Martin.That's not a VARRAY declaration, it's a PL/SQL table / associative array.
There is no syntax to declare the contents of an associative array in-line.
They can either be assigned to directly or populated by BULK COLLECT (except for associative arrays indexed by VARCHAR2). Perhaps you could assign the return value of a function?
Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> CREATE OR REPLACE PACKAGE types AS
2
3 TYPE associative_array_type IS TABLE OF INTEGER
4 INDEX BY VARCHAR2 (32);
5
6 FUNCTION default_associative_array_type
7 RETURN associative_array_type;
8
9 END;
10 /
Package created.
SQL> CREATE OR REPLACE PACKAGE BODY types AS
2
3 FUNCTION default_associative_array_type
4 RETURN associative_array_type
5 IS
6 associative_array associative_array_type;
7 BEGIN
8 associative_array ('xml_gkregnl') := 3;
9 RETURN associative_array;
10 END;
11
12 END;
13 /
Package body created.
SQL> CREATE OR REPLACE PACKAGE constants AS
2
3 associative_array CONSTANT types.associative_array_type :=
4 types.default_associative_array_type;
5
6 END;
7 /
Package created.
SQL> SET SERVEROUTPUT ON;
SQL> BEGIN
2 DBMS_OUTPUT.PUT_LINE (
3 'constants.associative_array (''xml_gkregnl'') => ' ||
4 constants.associative_array ('xml_gkregnl'));
5 END;
6 /
constants.associative_array ('xml_gkregnl') => 3
PL/SQL procedure successfully completed.
SQL> -
How to declare variable in table valued function
hello.
i have the following code to define a inline table valued function
but the use of cmn.ReshteId('Lf_WL') as a function in where clause is not good performance.
Alter function lf.fn_WholeLifeBn_GetForm(@ViewKind tinyint, @CurrentLocation int) returns table
as
return
select B.*
from lf.fn_LifeBN_GetForm(@ViewKind, @CurrentLocation) B
where Reshte = cmn.ReshteId('Lf_WL')
for better performance following code is good:
declare @Reshte smallint
set @Reshte = cmn.ReshteId('Lf_TS')
select B.*
from lf.fn_LifeBN_GetForm(@ViewKind, @CurrentLocation) B
where Reshte = @Reshte
but can not use it as the first code block in inline function.
please help for define a good function.What do you think about Multi-Statement Table-Valued UDFs?
create function Func(@Var int)
returns @T table(ColName int)
as
begin
insert into @T(ColName) values (@Var)
return
end
select * from Func(10)
select * from Func(20)
---or
alter function Func()
returns @T table(ColName int)
as
begin
declare @Var int
set @Var = 10
insert into @T(ColName) values (@Var)
return
end
select * from Func()
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Can anyone help me with this?
I have a set of Cue Points in an FLV I'm playing. It's an interactive quiz, so the idea is that flash will change a variable, theAnswer, to a different letter depending on which question it is. The answer to question 1 is B, question 2 is D, etc.
Either the cue point event listener isn't working, or else it is working and Flash isn't declaring the variables. Can someone help?
The error message I get is:
1120: Access of undefined property theAnswer.
I literally can't find a single problem with my code. I have an almost identical Event Listener further down which works.
var theAnswer;
vid.addEventListener(MetadataEvent.CUE_POINT, cueAnswers);
function cueAnswers(e:MetadataEvent):void{
var cuePointNames = e.info.name;
if (cuePointNames =="start")
theAnswer = "C";
else if (cuePointNames =="q2")
theAnswer = "A";
else if (cuePointNames =="q3")
theAnswer = "C";
else if (cuePointNames =="q4")
theAnswer = "A";
else if (cuePointNames =="q5")
theAnswer = "D";
else if (cuePointNames =="q6")
theAnswer = "C";
else if (cuePointNames =="q7")
theAnswer = "A";
else if (cuePointNames =="q8")
theAnswer = "D";
else if (cuePointNames =="q9")
theAnswer ="B"
else if (cuePointNames =="q10")
theAnswer ="B";
The function is called by this later:
function nkAinfo(e:MouseEvent):void {
if (theAnswer=="C")
trace("You clicked right");
else
trace("You clicked wrong");
What's going on? Is the function not being called or are my variable declarations wrong?Probably not the answer to your question, but it could help anyways....
First there is another command that, to me at least, is much easier to read that a bunch of nested if/if elses. And that is the switch.
switch (e.info.name){
case "start":
theAnswer="C";
break;
case "q2":
theAnswer="A"
break;
//and so on
To me that is easier to maintain and read. But I don't think that is really what you need here. So just file that one away for the future.
In this case, what I think you need is an array.
var currentAnswer:String;
var correctAnswers:Array=new Array();
correctAnswers["start"]="C"
correctAnswers["q2"]="A"
// and so on.
Then your cuepoint handler function becomes something like this:
function cueAnswers(e:MetadataEvent):void{
currentAnswer=correctAnswers[e.info.name];
And I'm a little confused by your mouse click handler. It would seem to suggest that the answer is always "C"? But I"m guessing that it is supposed to compare what the user clicked on to what the cuePoint has told it is the correct answer? Well if that is the case then it would probably look something like:
function nkAinfo(e:MouseEvent):void {
if(e.currentTarget.clickedProperty==currentAnswer){
trace("Correct");
} else {
trace("Incorrect");
With the way you are currently doing this I'm guessing that you have a bunch of repeated functions for each time there is a mouse click and that your code is a lot more complicated that it needs to be. And that somewhere hiding in all those lines there is an error that would be simple to fix if you could see it.
What the error is telling you is that somewhere your are trying to assign or retrieve theAnswer and it hasn't been defined yet. -
I still have some problems in relation to my earlier post:
http://forum.java.sun.com/thread.jspa?threadID=5164571&tstart=0
Help is still warmely appreciated! Thanks already to you Franzis.
So I try to add several JScrollPanes into on Container variable allComponents.
I don't understand why in my program
allComponents = jspane;works but
allComponents.add(jspane);does not.
Same is true for Jpanel objects. In my program
allComponents = panel;works but
allComponents.add(panel);does not. Why is this?
Still I necessarily need to work with a add() function.
So where is the problem?
The whole source code is at:
http://forum.java.sun.com/thread.jspa?threadID=5164571&tstart=0
Message was edited by:
wonderful123
nullI added a response in your original message:
http://forum.java.sun.com/thread.jspa?messageID=9629812
Let's keep to it since splitting things across two posts might be confusing. -
How to declare class for library like function
Hey guys I want to declare class Math and define method subtrction so that i can use it in other class like
package p1
public class Math
Math( ){}
int Subtration ( int a, int b)
return (a-b)
package p2
import p1.*;
Public Class Test
Test()
int somenumber=Math.Subtration(3,4);
For some reason I cannot see any methods inside Math class. when i type
somenumber = Math. it show me only one option and that is 'class' instead of mathods inside Math. any thoughts?
thxYes I am aware of Math class in java. The question is
how do i declare a class and call it's method in some
other class with out declaring an object of that
class.
Like I can just call Math.sqrt(4) with out
specifically declaring Math as an object. I want to
declare my own class which has some methods I wish to
call in some other class.MyClass.someMethod(). Just make sure that the methos is actually declared static. I suggest looking up the static keyword to find out what it means. -
How to declare synonym for a package function with a DBLink
Hi,
I have a PL/SQL package 'pkg'
and a function in the package 'func'
at another db using a dblink.
How to I create the correct syntax to create the synonym for this package and function.
create synonym --- for ---@dblink
Thanks.CREATE SYNONYM <name> FOR <OWNER>.<OBJECT>@<DB_LINK>
{code}
the object in this case would be pkg.func
Edited by: Tyson Jouglet on Sep 25, 2008 5:12 PM -
Oci oracle8i - how do oci to pass a varray parameter to a function
How do oci to pass a varray parameter to a function?
don't declare a variable inside a function body unless you want it to be local to that function/function call. ie, use:
var cont:int;
function whatever(){
cont=whatever; -
[Bash] How to `declare` a global variable inside a function?
#!/bin/bash
# Not using declare -A, array will be treated as indexed array rather than an associative array
seta()
for ((n=0;n<$1;n++)); do
printf -v a_$n[k] %s k$n
printf -v a_$n[j] %s j$n
eval echo inside seta: a_$n[k] = \$\{a_$n\[k\]\}
done
seta 3
echo outside: a_0[k] = ${a_0[k]}
echo outside: a_0[j] = ${a_0[j]}
echo
# Use declare -A inside function, array will be undefined outside
setb()
for ((n=0;n<$1;n++)); do
declare -A b_$n # Note here
printf -v b_$n[k] %s k$n
printf -v b_$n[j] %s j$n
eval echo inside setb: b_$n[k] = \$\{b_$n\[k\]\}
done
setb 3
echo outside: b_0[k] = ${b_0[k]}
echo outside: b_0[j] = ${b_0[j]}
echo
# The bad solution, only works if we know beforehand how many c_? arrays will be assigned inside setc()
for ((n=0;n<3;n++)); do
declare -A c_$n
done
setc()
for ((n=0;n<$1;n++)); do
printf -v c_$n[k] %s k$n
printf -v c_$n[j] %s j$n
eval echo inside setc: c_$n[k] = \$\{c_$n\[k\]\}
done
setc 3
echo outside: c_0[k] = ${c_0[k]}
echo outside: c_0[j] = ${c_0[j]}
My original code does the declare -A as in setb(). I was surprised when I saw all blank output... Now the problem is illustrated clearly by the setb() example.
The setc() example works, but a bit ugly: look at the two 3's...
My ideal solution would be, something like `declare_global -A b_$n` in setb()
Any ideas?with current bash versions, i don't think it is possible to declare global associative arrays in functions.
what you are after is the "-g" option of typeset which is available in zsh.
i think i read somewhere that something similar may be planned for bash 4.2. -
Global declaration in function group.
I have a function group within which i have 6 function modules. I want to declare global data in the function group which can be used in all the function modules. Is it possible? If yes then please give me the details..
Thanks,
AbhishekEach function module is nothing but INCLUDE program. So, if you see the list of includes, there will be a TOP include which is common and will be accessible to all other function modules.
You can declare variables there.
Regards,
Ravi
Note - Please mark all the helpful answers -
Varray of Objects: Initializing, Instantiation, Constructors, ORA-06531
This is supposed to fill a varray with ten objects, calling methods in those objects and populating the objects from queries, then display fields from the objects via methods. Error message is in comment at bottom. Any ideas?
-- Enable screen I/O
SET SERVEROUTPUT ON SIZE 1000000
SET VERIFY OFF
-- object spec
CREATE OR REPLACE TYPE employee4 AS OBJECT
o_ename CHAR (20 char),
o_empno NUMBER (4),
o_sal NUMBER (10),
o_thisno NUMBER (4),
MEMBER FUNCTION get_o_ename RETURN CHAR, MEMBER PROCEDURE set_o_ename (o_thisno IN number),
MEMBER FUNCTION get_o_empno RETURN NUMBER, MEMBER PROCEDURE set_o_empno (o_thisno IN number),
MEMBER FUNCTION get_o_sal RETURN NUMBER, MEMBER PROCEDURE set_o_sal (o_thisno IN number),
CONSTRUCTOR FUNCTION employee4 (o_ename CHAR,o_empno NUMBER,o_sal NUMBER,o_thisno NUMBER) RETURN SELF AS RESULT
-- object body
CREATE OR REPLACE TYPE BODY employee4 AS
CONSTRUCTOR FUNCTION employee4 (o_ename IN CHAR,
o_empno IN NUMBER,
o_sal IN NUMBER,
o_thisno IN NUMBER)
RETURN SELF AS RESULT IS
BEGIN
SELF.o_ename := o_ename;
SELF.o_empno := o_empno;
SELF.o_sal := o_sal;
SELF.o_thisno := o_thisno;
RETURN;
END;
-- gets
MEMBER FUNCTION get_o_ename RETURN CHAR IS
BEGIN
RETURN self.o_ename;
END;
MEMBER FUNCTION get_o_empno RETURN NUMBER IS
BEGIN
RETURN self.o_empno;
END;
MEMBER FUNCTION get_o_sal RETURN NUMBER IS
BEGIN
RETURN self.o_ename;
END;
-- sets
MEMBER PROCEDURE set_o_ename(o_thisno IN number) IS
BEGIN
SELECT ename INTO SELF.o_ename FROM emp WHERE empno = SELF.o_thisno;
END;
MEMBER PROCEDURE set_o_empno(o_thisno IN number) IS
BEGIN
SELECT empno INTO SELF.o_empno FROM emp WHERE empno = SELF.o_thisno;
END;
MEMBER PROCEDURE set_o_sal(o_thisno IN number) IS
BEGIN
SELECT sal INTO SELF.o_sal FROM emp WHERE empno = SELF.o_thisno;
END;
END;
DECLARE
-- a varray of employees
TYPE emp_varray1 IS VARRAY(10) OF employee4;
varray_of_emps EMP_VARRAY1;
-- List of EMPNO's in order of appearance in EMP table (for cross-referencing, single-line retrieval)
TYPE MYCREF_VARRAY IS VARRAY(10) OF NUMBER(4);
varray_mycref MYCREF_VARRAY := MYCREF_VARRAY(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
-- make a variable to store one empno
thisno NUMBER(4);
-- make a counter
counter INT;
-- query variables for the set calls
q_ename CHAR(20 CHAR);
q_empno NUMBER(4);
q_sal NUMBER(10);
BEGIN
-- Put the first 10 EMPNO's in my cref array
SELECT empno BULK COLLECT INTO varray_mycref FROM emp WHERE ROWNUM < 11;
-- Use a loop to retrieve the first 10 objects in the "emp" table and put them in the varray of objects
FOR counter IN 1..10 LOOP
thisno := varray_mycref(counter);
varray_of_emps(counter).set_o_ename(thisno);
varray_of_emps(counter).set_o_empno(thisno);
varray_of_emps(counter).set_o_sal(thisno);
END LOOP;
-- Use another loop to display the information in the reverse order.
FOR counter in REVERSE 1..10 LOOP
dbms_output.put_line((varray_of_emps(counter).get_o_ename()) || CHR(9) || (varray_of_emps(counter).get_o_empno()) || CHR(9) || (varray_of_emps(counter).get_o_sal()));
END LOOP;
END;
This results in the following response in SQL*PLUS:
Type created.
Type body created.
DECLARE
ERROR at line 1:
ORA-06531: Reference to uninitialized collection
ORA-06512: at line 33Hi,
From metalink:
Cause: An element or member function of a nested table or varray was
referenced (where an initialized collection is needed) without the
collection having been initialized.
Action: Initialize the collection with an appropriate constructor or
whole-object assignment.
ORA 6531 Reference to uninitialized collection (Doc ID 48912.1) -
Supply function in webdynpro for abap
Hi ,
I have tree structure as below.
1. Node A
1.a Node B
1.a.i Node C
I have declared method 'Method_A' as supply function for Node A.similarly
I have declared method 'Method_B' as supply function for Node B.similary
I have declared method 'Method_C' as supply function for Node C.
When I am executing in debugging mode both 'Method_A' and 'Method_B' is triggering for initial display of tree. Without expanding Node A ,we are already getting the Node B data and storing in corresponding nodes. This is becoming performance issue as I am hitting database in those 3 methods. My problem is without expanding why that 'Method_B' supply function is
triggering. Please let me know if you have any idea.
Thanks,
SumaThe supply function is always get triggered even if you do not expand the parent node in tree.
Reason: It fills the value to the child node based on parent's value.
To avoid this, you can set teh condition as follows:
In node B supply function, method_B:
check the instance of parent node A here, and if that is not initial, then only hit the database for filling node B.
In node C supply function, method_C:
Check the instance of parent node B here, and if that is not initial, then only hit the database for filling node C.
This is the only possible solution one can think of.
Maybe you are looking for
-
BPM CBS - Exception during process compilation
Hi Experts, I am developing a BPM process using SAP NWDS 7.2 and a remote NWDI track. I have the following issue: When I edit my process, I create an activity for submit this changes. Later I try to check-in the activity and everything is okay, but w
-
Siri can not read text messages
When asked to "read my texts" Siri will respond with something to the tune of "new text message from ....." then it goes quiet for bit until saying, "would you like to reply or should I read it again". This happens while in my car connected to Blueto
-
Transter of wav files, converted to mp3, to iPod
I have transfered vinyl to my computer, as a wav file. I have encoded this wav file to mp3 format. I attempt to transfer to iPod mini, and the message reads: "the target can not handle this type of document" What does this mean? Can iPod accept such
-
IWeb keeps crashing when using Media Browser
Does anyone else experience constant crashes in iWeb while trying to work with images in the Media Browser (from iPhoto)? This application totally crashed EVERY time I worked with trying to drag and drop, review images in the Media Browser, and even
-
My 2008 Mac Pro suddenly crashed twice. In both cases, the screen went dark, then was replaced by a grey screen with the message, "Your computer was restarted because of an error..." or something like that. I need help interpreting the crash log, to