Column Function Return Type Number is forcing to cast to Decimal
Hi - I am using Oracle 11g Release 11.2.0.2.0 and ODP.NET 4.112.3.0.
Whenever I am trying to execute a package query with column function and return type is number, it is throwing cast exception whenever I am trying to cast it as GetInt32.
The workaround we have for now is to get it decimal and cast to Int32, this is going to be painful moving forward because it means that we have to check each of our packages and need to know if each package has column function and do this special casting.
Is this a known bug?
Oracle Number is 6.
Run the below script to your machine and the sample code below so you can see what I am talking about.
--drop table aninalfarm;
--drop table birdfarm;
--drop public synonym animalfarm;
--drop public synonym birdfarm;
--drop public synonym birdfarm_Pkg;
--drop public synonym animalfarm_Pkg;
create table animalfarm
(code NUMBER(6),
description varchar2(10));
create table birdfarm
(code number(6),
description varchar2(10));
create public synonym animalfarm for db.animalfarm;
create public synonym birdfarm for db.birdfarm;
grant select, delete, insert, update on animalfarm to public;
grant select, delete, insert, update on birdfarm to public;
delete from animalfarm;
delete from birdfarm;
commit;
insert into animalfarm (code, description) values(111122, 'Horse');
insert into animalfarm (code, description) values(111133, 'Chicken');
insert into animalfarm (code, description) values(111144, 'Cow');
insert into animalfarm (code, description) values(111155, 'Pig');
insert into animalfarm (code, description) values(111166, 'Sheep');
insert into birdfarm (code, description) values(222, 'Pigeon');
insert into birdfarm (code, description) values(333, 'Sparrow');
insert into birdfarm (code, description) values(444, 'Chickadee');
insert into birdfarm (code, description) values(555, 'Blue Jay');
insert into birdfarm (code, description) values(666, 'Loon');
commit;
create or replace package birdfarm_Pkg is
function get_key_from_desc(bird_name_in in birdfarm.description%type) return number;
end birdfarm_Pkg;
create or replace package body birdfarm_Pkg is
function get_key_from_desc(bird_name_in in birdfarm.description%type) return number is
RETURN_VALUE birdfarm.code%TYPE;
BEGIN
select code into RETURN_VALUE from birdfarm where description = bird_name_in;
return RETURN_VALUE;
end get_key_from_desc;
END birdfarm_Pkg;
create or replace package animalfarm_Pkg is
--region Define Record Type for Strong Type REF CURSOR
TYPE AnimalFarmRecord is
RECORD(
code animalfarm.code%type,
description animalfarm.description%type,
birdfarm_code birdfarm.code%type
--endregion
TYPE animalfarmCur is REF CURSOR RETURN AnimalFarmRecord;
procedure get_code_two_ways(cur_OUT OUT animalfarmCur);
end animalfarm_Pkg;
create or replace package body animalfarm_Pkg is
procedure get_code_two_ways(cur_OUT OUT animalfarmCur) is
BEGIN
open cur_OUT for
select animalfarm.code,
animalfarm.description,
birdfarm_pkg.get_key_from_desc('Pigeon') birdfarm_code
from animalfarm
order by code;
end get_code_two_ways;
END animalfarm_Pkg;
create public synonym birdfarm_Pkg for db.birdfarm_Pkg;
grant execute on birdfarm_Pkg to public;
create public synonym animalfarm_Pkg for db.animalfarm_Pkg;
grant execute on animalfarm_Pkg to public;
See the sample code below:
var conn = new OracleConnection(OraDB);
conn.Open();
conn.ClientId = "Sample";
var command = new OracleCommand
Connection = conn,
CommandText = "DB.animalfarm_Pkg.get_code_two_ways",
CommandType = CommandType.StoredProcedure
command.Parameters.Add(new OracleParameter
ParameterName = "cur_OUT",
OracleDbType = OracleDbType.RefCursor,
Direction = ParameterDirection.Output
OracleDataReader dr = command.ExecuteReader(); // C#
dr.Read();
var code =dr.GetInt32(dr.GetOrdinal("Code")); //This is ok
var description = dr.GetString(dr.GetOrdinal("Description"));
var codeError = dr.GetInt32(dr.GetOrdinal("birdfarm_code"));//Throw invalid cast exception
//because it is column function
conn.Close();
conn.Dispose();
Similar Messages
-
Set attribute to a Jfield to return type number from Lov
in my lov , i need to return type number and put it in the Jfield . after doin some search , i found the method to set the attribute on that field. PLease and need to send me any URL of doing that method if there is one. (returning type number from LOV)
i have tried this method but it didn't work!!!
Return object from List of values page:
FacesContext fctx = FacesContext.getCurrentInstance();
Application app = fctx.getApplication();
ValueBinding vb = app.createValueBinding("#{bindings}");
DCBindingContainer dc = (DCBindingContainer) vb.getValue(fctx);
DCIteratorBinding dciter = (DCIteratorBinding)dc.get("PrcPartiesLawer1Iterator");
id = (Number)dciter.getCurrentRow().getAttribute("Id");
Name = (String)dciter.getCurrentRow().getAttribute("FullNameN");
setId(id);
setName(Name); AdfFacesContext.getCurrentInstance().returnFromDialog(this,null);
return listener to assign value to Number field:
LawyerReturnOject b = (LawyerReturnOject)returnEvent.getReturnValue();
if(b==null)return;
Number i = b.getId();
getIii().setSubmittedValue(null);
getIii().setValue(i);
String f = b.getName();
getInputText1().setSubmittedValue(null);
getInputText1().setValue(f);
AdfFacesContext af = AdfFacesContext.getCurrentInstance();
af.addPartialTarget(getLawyerLov());
af.addPartialTarget(getInputText1());
and the number type is oracle.jbo.domain.numberHi,
its easier to set the returned value on the ADF binding then on the component directly (at least this is less error prone)
FacesContext fctx = FacesContext.getCurrentInstance();
Application app = fctx.getApplication();
ValueBinding vb = app.createValueBinding("#{bindings}");
DCBindingContainer dc = (DCBindingContainer) vb.getValue(fctx);
FacesCtrlAttrsBinding the_attribute = (FacesCtrlAttrsBinding ) dc.get("nameOfAttributeToUpdate");
the_attribute.set...
Frank -
How to execute a function returning type in oracle
hi
i want to execute a function which is returning table from oracle prompt.
i have created type in order to return table from function.
/*creating type
CREATE OR REPLACE TYPE U_VOC.t_in_list_tab AS OBJECT (i_group NUMBER ,
i_company number,
i_estab number
NOT FINAL ;
CREATE OR REPLACE TYPE U_VOC.t_in_list_tab_type
AS TABLE OF U_VOC.t_in_list_tab;
/*function */
CREATE OR REPLACE FUNCTION FU_VOC_S_VEHICLES(pi_group number,
pi_company number,
pi_estab number
RETURN t_in_list_tab
AS
v_nb_idvehicle U_REF.V_REF_VEHICLES.NB_IDVEHICLE%type ;
v_vc_reference U_REF.V_REF_VEHICLES.VC_REFERENCE%type ;
v_vc_licenceplate U_REF.V_REF_VEHICLES.VC_LICENCEPLATE%type ;
l_tab t_in_list_tab := t_in_list_tab( pi_group ,pi_company, pi_estab );
BEGIN
SELECT V_REF_VEHICLES.NB_IDVEHICLE,
V_REF_VEHICLES.VC_REFERENCE,
V_REF_VEHICLES.VC_LICENCEPLATE
INTO V_NB_IDVEHICLE,
V_VC_REFERENCE,
V_VC_LICENCEPLATE
FROM U_REF.V_REF_VEHICLES
WHERE V_REF_VEHICLES.NB_IDGROUP = pi_group
AND V_REF_VEHICLES.NB_IDCOMPANY = pi_company
AND V_REF_VEHICLES.NB_ESTABL = pi_estab;
RETURN l_tab;
END;
please help
Thank in advance
SandySandy,
I have a series of examples on this issue in my demo application. See this one:
http://htmldb.oracle.com/pls/otn/f?p=31517:146
You will basicaly need to write it like this:
CREATE OR REPLACE TYPE u_voc.t_in_list_tab AS OBJECT (
i_group NUMBER,
i_company NUMBER,
i_estab NUMBER
CREATE OR REPLACE TYPE u_voc.t_in_list_tab_type AS TABLE OF u_voc.t_in_list_tab;
CREATE OR REPLACE FUNCTION fu_voc_s_vehicles (
pi_group NUMBER,
pi_company NUMBER,
pi_estab NUMBER
RETURN t_in_list_tab PIPELINED
AS
l_tab t_in_list_tab := t_in_list_tab (NULL, NULL, NULL);
BEGIN
FOR c IN (SELECT v_ref_vehicles.nb_idvehicle, v_ref_vehicles.vc_reference,
v_ref_vehicles.vc_licenceplate
FROM u_ref.v_ref_vehicles
WHERE v_ref_vehicles.nb_idgroup = pi_group
AND v_ref_vehicles.nb_idcompany = pi_company
AND v_ref_vehicles.nb_establ = pi_estab)
LOOP
l_tab.i_group := c.nb_idvehicle;
l_tab.i_company_number := c.vc_reference;
l_tab.estab_number := vc_licenceplate;
END LOOP;
RETURN l_tab;
END;
SELECT *
FROM TABLE (fu_voc_s_vehicles (value1, value2, value3))But looking at your code, your function will return only one record.
Denes Kubicek
http://deneskubicek.blogspot.com/
http://www.opal-consulting.de/apex/f?p=107:7
http://htmldb.oracle.com/pls/otn/f?p=31517:1
------------------------------------------------------------------- -
Prior, Next, Shift functions return type?
I can not point out what is the return type of these functions? numeric value or member?
And if they return a member would this fomula be valid (i need to take avg value of march and june):
avgppl = @avgrange("HRsummary" -> "territory",@list(@currmbr("YearTotal"),@shift(@currmbr("YearTotal"),-3)))
Thanks in advance!just use simple arithmetic combined with other functions
e.g.
If you want sum of base time periods underneath a summary time period, and make the formula generic to work on base time periods:
@SUMRANGE(@CURRMBR(Account),@Relative(@CURRMBR(Period),0))/@COUNT(SKIPNONE,@Relative(@CURRMBR(Period),0))
or, instead if you want the quarter averages at base time periods...
@SUMRANGE(@CURRMBR(Account),@Relative(@Relative(@CURRMBR(Period),-1),0))/@COUNT(SKIPNONE,@Relative(@Relative(@CURRMBR(Period),-1),0)) -
Function return type could be sequence?
I tried to write a function return a sequence, but netbeans don't allow it. is it possible? if not, how can I solve it?
Here is an example of a function and a var as a function.
function foo():Integer[] {
[0..9]
var bar:function():Integer[] = foo;
for ( i in bar() ) println("{i}"); -
How to PL/SQL Function returns type
Hello,
I need to create a function, which is returning a list of ID's, which is stored in a type T_IDs, something like:
function search(searchstring in varchar2) return T_IDs
I have a little problem with filling the type inside the function body using a select statement like
select id from table where text like searchstring;
which is selecting a list of ids matching the where-clause. Is it possible to use select into or should I go for another mechanism?
Thanks for any ideas.CoBy wrote:
Yes, no problem, this is the code I am testing on
create table texttabelle(
id number(10),
dokument clob
+)+
+/+
create sequence seq_texttabelle
+/+
insert into texttabelle values (seq_texttabelle.nextval, 'A-Partei gewinnt Wahl in Hansestadt');
insert into texttabelle values (seq_texttabelle.nextval, 'Terror in Nahost: Kriminalität steigt immer weiter an');
insert into texttabelle values (seq_texttabelle.nextval, 'Wirtschaft: Erneuter Gewinnzuwachs in diesem Jahr');
insert into texttabelle values (seq_texttabelle.nextval, 'Olympia rückt näher: Der Fackellauf ist in vollem Gange');
insert into texttabelle values (seq_texttabelle.nextval, 'Wer wird US-Präsident? Obama und Clinton machen Wahlkampf');
insert into texttabelle values (seq_texttabelle.nextval, 'Papst bestürzt über jüngsten Skandal!');
insert into texttabelle values (seq_texttabelle.nextval, 'Wahlkampf in den USA geht weiter: Clinton und Obama LIVE zu sehen');
insert into texttabelle values (seq_texttabelle.nextval, 'Software-Kenntnisse werden immer wichtiger');
insert into texttabelle values (seq_texttabelle.nextval, 'Umfrage: Alle wollen mehr Geld!');
insert into texttabelle values (seq_texttabelle.nextval, 'Der Papst liest seine erste Messe in den USA!');
commit
+/+
create index idx_text on texttabelle (dokument)
indextype is ctxsys.context
+/+
CREATE OR REPLACE type T1 as object (
numero number(2)
+);+
+/+
The desired function has following specification:
CREATE OR REPLACE FUNCTION fkt_search (search_str IN VARCHAR2) RETURN T1;
The select statement I would like to use is:
SELECT id
FROM texttabelle
WHERE contains (dokument, search_str) > 0;
As I said, I cannot construct the correct select into - statement to fill the T1 with the result ID's from above.
ThanksYour problem is that you are returning a single object from your function, not a collection of them. -
To_number function return Invalid number
Dear All,
We have problem recently regarding one of our query that using to_number function. It worked smoothly for 4-5 years until recently our client complaints that the query is returning error ORA-01722: invalid number.
This is the SQL Script -> SELECT * FROM <table_name> WHERE to_number(b) between :param1 and :param2;
* Column b is defined as VARCHAR2(20)
First thing that come to my mind is this error is due to invalid value entered by user. Using the solutions provided by users in this forum and internet, I created SQL a function that checks whether the value is numeric or not.
So, when I run the query (+SELECT b from <table_name> WHERE is_numeric(b) = 0 AND ROWNUM < 20+) this is the result that I get.
b
251567
251568
251569
251570
251571
(Up to 11 record; value from 251567 - 251577)
Is there any limitation on the maximum value that can be converted using to_number* function?*
I have search the solutions over the internet and I accept the solution/recommendation that we should not store numeric value on varchar/char column; but I hope somebody can explain why I can't use to_number to convert the above figures to numeric, because when I execute SELECT to_number('251567') FROM DUAL it doesn't returned any error)
Thank you in advance for any help or clarification on this issue.
Edited by: user5535734 on Apr 16, 2012 10:46 PMFunny answer, Billy!
Sounds like: The world is evil, so you have 3 choices:
1. Implement a good world
2. Be a bad guy, too
3. Live with that bad world and its consequences
I guess, 930427 only asked for some protection...
If one has to deal with two external system to move data from one to another - you can't change either of these systems (1 or 2) and you can't afford to fail (3).
Sometimes blanks inside the numeric values are the reason for INVALID NUMBER, i.e. "123 456".
as simple
to_number(replace(VALUE_CHAR, ' ', NULL))
may help... -
I have a return string from function contains more than 4000 bytes.
But VARCHAR2(4000) is only 4000 bytes.
Is there ay way we can return more than 4000
Thanks a lot for the help
PrasadYou could create a nested table within this function...this nested table can be of type varchar2(4000).
Cut your string into various pieces as elements of this nested table..and you can reconcat yuor string when this function is returned.
Sameer -
OracleDbType for function OBJECT return type
Hi all,
I inherited an oracle function that has an object as a return type:
create or replace TYPE OBJECTPATH IS OBJECT (OBJECTID NUMBER);
create or replace TYPE OBJECTPATH_TAB AS TABLE OF OBJECTPATH;
create or replace FUNCTION GETOBJECTINPATH ( pobjectid in NUMBER, role1 varchar2, role2 varchar2 ) RETURN OBJECTPATH_TAB
IS
v_tmp_tab OBJECTPATH_TAB:=OBJECTPATH_TAB();
parentid NUMBER;
rowno INTEGER;
BEGIN
rowno:=0;
parentid:=pobjectid;
loop
select objectid into parentid from dual left join (select ro2.objectid from relationshipobject ro1, relationshipobject ro2
where ro1.role=role1 and ro2.role=role2 and ro1.relationshipid=ro2.relationshipid and ro1.objectid=parentid)
on 1=1;
if parentid is null then
exit;
end if;
v_tmp_tab.extend;
rowno:=rowno1;+
v_tmp_tab(rowno) := OBJECTPATH(parentid);
end loop;
RETURN v_tmp_tab;
END;
On my application side, I am trying to run this function and retrieve the return value with ODP.NET as below. However, I am stumped when I need to supply an OracleDbType for the function return type.
1. What is the OracleDbType I should use for the return type? I read that there used to be support for OracleDbType.Object, but it seems like it is now not supported. I am using ODP.NET 11g. Am I getting the situation correct?
2. If retrieving an object return type is not as straightforward as setting the parameters (as what I have done below), what is the workaround to achieve it?
OracleCommand runGetPObjectInPathCmd = new OracleCommand("GETOBJECTINPATH", conn);
runGetPObjectInPathCmd.CommandType = CommandType.StoredProcedure;
runGetPObjectInPathCmd.Parameters.Add(new OracleParameter("pobjectid", OracleDbType.Decimal)).Value = pobjectId;
runGetPObjectInPathCmd.Parameters["pobjectid"].Direction = ParameterDirection.Input;
runGetPObjectInPathCmd.Parameters.Add(new OracleParameter("role1", OracleDbType.Varchar2, 255)).Value = role1;
runGetPObjectInPathCmd.Parameters["role1"].Direction = ParameterDirection.Input;
runGetPObjectInPathCmd.Parameters.Add(new OracleParameter("role2", OracleDbType.Varchar2, 255)).Value = role2;
runGetPObjectInPathCmd.Parameters["role2"].Direction = ParameterDirection.Input;
runGetPObjectInPathCmd.Parameters.Add("OBJECTPATH_TAB", OracleDbType.Decimal); // this is not correct as the return type is not a NUMBER
runGetPObjectInPathCmd.Parameters["OBJECTPATH_TAB"].Direction = ParameterDirection.ReturnValue;
runGetPObjectInPathCmd.ExecuteNonQuery();
Thanks in advance for any help and would greatly appreciate it.Hi Greg,
Thanks for your reply. I am not exactly sure whether I am using 11.1.0.6.21. The Oracle.DataAccess.dll I see under my \ODP.NET\bin\2.x directory is of Assembly/Product Version 2.111.6.0 - is this version 11.1.0.6.21? I also do not have the samples directory. Am I working on a wrong version? Thanks for your patience as I am really new to this and appreciate your guidance. -
Same functions with different return types in C++
Normally the following two functions would be considered the same:
int getdata ( char *s, int i )
long getdata ( char *s, int i )
Every other compiler we use would resolve both of these to the same function. In fact, it is not valid C++ code otherwise.
We include some 3rd party source in our build which sometimes messes with our typedefs causing this to happen. We have accounted for all of the function input types but never had a problem with the return types. I just installed Sun ONE Studio 8, Compiler Collection and it is generating two symbols in our libraries every time this occurs.
Is there a compiler flag I can use to stop it from doing this? I've got over 100 unresolved symbols and I'd rather not go and fix all of them if there is an easier way.Normally the following two functions would be
considered the same:
int getdata ( char *s, int i )
long getdata ( char *s, int i )Not at all. Types int and long are different types, even if they are implemented the same way.
Reference: C++ Standard, section 3.9.1 paragraph 10.
For example, you can define two functions
void foo(int);
void foo(long);
and they are distinct functions. The function that gets called depends on function overload resolution at the point of the call.
Overloaded functions must differ in the number or the type of at least one parameter. They cannot differ only in the return type. A program that declares or defines two functions that differ only in their return types is invalid and has undefined behavior. Reference: C++ Standard section 13.1, paragraph 2.
The usual way to implement overloaded functions is to encode the scope and the parameter types, and maybe the return type, and attach the encoding to the function name. This technique is known as "name mangling". The compiler generates the same mangled name for the declaration and definition of a given function, and different mangled names for different functions. The linker matches up the mangled names, and can tell you when no definition matches a reference.
Some compilers choose not to include the return type in the mangled name of a function. In that case, the declaration
int foo(char*);
will match the definition
long foo(char*) { ... }
But it will also match the definitions
myClass foo(char*) { ... }
double foo(char*) { ... }
You are unlikely to get good results from such a mismatch. For that reason, and because a pointer-to-function must encode the function return type, Sun C++ always encodes the function return type in the mangled name. (That is, we simplify things by not using different encodings for the same function type.)
If you built your code for a 64-bit platform, it would presumably link using your other compilers, but would fail in mysterious ways at run time. With the Sun compiler, you can't get into that mess.
To make your program valid, you will have to ensure your function declarations match their definitions. -
Managed ODP: InvalidCastException when returning large number
I get an InvalidCastException "Specified cast is not valid" when trying to get a value bigger than Decimal.MaxValue as a scalar result from a select.
From the stack trace and inspection of the Oracle.ManagedDataAccess.dll code I would expect OracleDataReader to cast to OracleDecimal (or System.Numerics.BigInteger) instead of System.Decimal for large numbers.
Is this a bug?
Stack trace:
at Oracle.ManagedDataAccess.Client.OracleDataReader.GetDecimal(Int32 i)
at Oracle.ManagedDataAccess.Client.OracleDataReader.GetValue(Int32 i)
at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteScalar()
at Cora.Data.DBProvider.Tests.CoraParameterTest.BigIntegerOracleTest() in D:\svnroot\tech\lib\Cora.Data.DBProvider\Cora.Data.DBProvider.Tests\CoraParameterTest.cs:line 98
How to reproduce:
- create a table NUNITTEST_PARAM_SIMPLE with a column BIG of type NUMBER(38)
- run sample code
using ( OracleConnection conn = new OracleConnection(ORACONN) )
conn.Open();
using ( OracleCommand cmd = conn.CreateCommand() )
cmd.CommandText = "insert into NUNITTEST_PARAM_SIMPLE (BIG) values (1234567890123456789012345678901234567)";
cmd.ExecuteNonQuery();
using ( OracleCommand cmd = conn.CreateCommand() )
cmd.CommandText = "select BIG from NUNITTEST_PARAM_SIMPLE";
object result = cmd.ExecuteScalar(); // Exception
conn.Close();There is no safe type mapping for ExecuteScalar. It's an uncommon use case.
Even if there was, making the correct conversion implicitly would lead to more work for the application developer. Let's assume ODP.NET performs the "right" conversion. Now, the app needs to manipulate the data. What data type does it treat the returned value as: string or decimal? It could be either. That means twice as much code. One set deals with the data if a decimal was returned. The second deals with the data if a string is returned.
It would be much easier to write code for one scenario, rather than two. That is why ODP.NET safe type mapping is an explicit conversion the developer makes. -
I must access a DLL developped by VC++ via LV6i with the 'Call Library function'. Everythimg is fine, but the DLL function return type is bool, and I don't find the bool data type in the 'Call library parameter'.
Secondly, I must pass parameters to this DLL function. Parameters type are : std::vector and GUID. How can I pass this type of parameters ??
Function is : bool MyFunction (const GUID &guidMyGuid, std::vector &MyVector).
Thanks in advance.You can't, you have to create a CIN that reshapes this parameters to something LabView understand.
-
Db function returning three db number columns...
Hi ,
Is it possible a db function to return three number columns fetched from a table...??
If for example , there is a db function such as...:
function x
return number
is
begin
select number_col_1 , number_col_2 , number_col_3
into var1 , var2 , var3
from table_a
where <a_condition>;
return <the_three_columns_selected>;
end;
so as in a select statement should write:
select a , b , x from a_table
many thanks ,
SimonAlternatively you can return a SQL collection:
SQL> create or replace function x (empno integer)
2 return sys.dbms_debug_vc2coll
3 is
4 var1 emp.job%type;
5 var2 emp.sal%type;
6 var3 emp.deptno%type;
7 begin
8 select job, sal, deptno
9 into var1, var2, var3
10 from emp
11 where empno = x.empno;
12
13 return sys.dbms_debug_vc2coll (var1, var2, var3);
14 end;
15 /
Function created.
SQL>
SQL> select empno, ename, x(empno) x from emp
2 where empno in (7788,7900)
3 /
EMPNO ENAME X
7788 SCOTT DBMS_DEBUG_VC2COLL('ANALYST', '3000', '20')
7900 JAMES DBMS_DEBUG_VC2COLL('CLERK', '950', '30') -
How to make a function return number(10,0) data type (ORACLE 10g)?
With 10g, how to make a function return number(10,0) data type?
here is the function, it returns a number type :
create or replace FUNCTION Get_portfolio_Id3 (p_HistObjTable In Varchar2,p_LHISTOBJID IN NUMBER) RETURN view_cpu_STD_Asset.LPORTFOLIOITEMID%Type IS
v_Id view_cpu_STD_Asset.LPORTFOLIOITEMID%Type;
BEGIN
If p_HistObjTable ='amPortfolio'
then v_Id:=p_LHISTOBJID ;
elsIf p_HistObjTable = 'amComputer' then
select litemid into v_Id from smcdba.amComputer c where c.LCOMPUTERID=p_LHISTOBJID ;
else v_Id:=-99;
End If;
RETURN v_Id;
END Get_portfolio_Id3;
Thanks.
Message was edited by:
user631701create or replace FUNCTION Get_portfolio_Id3 (p_HistObjTable In Varchar2,p_LHISTOBJID IN NUMBER) RETURN view_cpu_STD_Asset.LPORTFOLIOITEMID%Type IS
v_Id view_cpu_STD_Asset.LPORTFOLIOITEMID%Type;
BEGIN
If p_HistObjTable ='amPortfolio'
then v_Id:=p_LHISTOBJID ;
elsIf p_HistObjTable = 'amComputer' then
select litemid into v_Id from smcdba.amComputer c where c.LCOMPUTERID=p_LHISTOBJID ;
else v_Id:=-99;
End If;
RETURN round(v_Id);
END Get_portfolio_Id3; -
Using Column Name returned by function in SELECT statement
Hi
Output from my function (RETURN data type is VARCHAR2) is column name. I want to use it directly in my SELECT statement. Below is simplified example of this:
--- Function
CREATE OR REPLACE FUNCTION simple RETURN varchar2 IS
BEGIN
RETURN ‘my_column’;
END simple;
--- Select
SELECT simple FROM my_table;
This does not work. It seems that output from function is passed in quotation i.e.
SELECT ‘my_column’ FROM my_table;
So the output from SELECT is a list of rows populated with values my_table:
COLUMN simple
ROW1 my_column
ROW2 my_column
ROW3 my_column
Can please someone help me with this?I'm not sure I got you right.
In standard SQL everything must be known at compile time. If not dynamic SQL is required, but is a costly operation (usually requires parsing before each execution) so it should better not be used when standard SQL can do it.
I provided a design time example where a function returns the column name from the given the table name and column id for a varchar2 column data type to make things simple. Then a query string is constructed and executed dynymically to return all column values of the chosen table_name.column_name.
SELECT simple FROM my_tableAt compile time the simple function return value is unknown (any varchar2 value would do) you already find out you get the (same) return value (i.e column name) for each table row => dynamic SQL needed to get the column values
The purpose of function would be to rename all columns for provided table.The table name would be provided, right? If yes => dynamic SQL
What is the function supposed to return the column name (where would the new name come from?), the column alias (which table column would be renamed to the new name?)
The user could use the new_column name as the column alias name submitting the query.
Is it possible to do this?Maybe () using a pipelined function (different data types - number,date, ... not cosidered yet) but your simple query;
<tt>SELECT simple FROM my_table</tt>
might look like:
<tt>select my_column_value new_column_name from table(get_column_value(table_name,column_name))</tt>
Sorry, no Database at hand to provide a specific example.
Regards
Etbin
Maybe you are looking for
-
Hi, I am unable to sign in to my iCloud account. When i sign in, it says Your apple ID has been disabled due to security reasons. Kindly reset your password to log in. I have already reset my password thrice but am unable to access into my account ev
-
Hi, I am a newbie here. Just started using Labview for my project. Currently having some difficulties over here. Hopefully someone could enlighten me. I wanted to create an array of 60 indicators, where the indicators value are measured from the PCI
-
Strange error in BAPI_BUSINESS_PARTNER_CHANGE
Hello, trying to use the function module BAPI_BUSINESS_PARTNER_CHANGE i get very strange error. I try to change the authorization group of the Business Partner, so no tables parameters except return are filled. All of obligatory fields are filled wit
-
Regarding process activities tab in GP
Hi all, Iam creating a GP process by using callable as portal iview when i am initiating the process iam able to call the respective object but in the iview it is showing the procees activities tab .Is there any way to customize it if so please help
-
Is there any discount on iPad's for teachers?
I was told that our Kindergartens can use an iPad next year for our entrance assessments. At the Apple store, I was told that teachers only receive a discount on MacBooks. I could be tax-exempt, but only if the district was buying it, which the dis