How to write a function with table name as parameter
I created a function like this:
create or replace function "GETNAME"
(did in NUMBER, dtable in VARCHAR2)
return VARCHAR2
is
dname varchar2(200);
begin
select lastname || ' ' || firstname
into dname from dtable
where id = did;
return dname;
end;
i got an error: table or view does not exist.
Could somebody tell me how to fix it?
Thanks,
Jen
or by using a reference cursor: create or replace function dynamic_cursor (pTab varchar2)
return sys_refcursor as
c sys_refcursor;
begin
open c for 'select * from '|| pTab;
return c;
end;
SQL> exec :c := dnamic_cursor('emp');
SQL> exec :c := dynamic_cursor('emp');
PL/SQL procedure successfully completed.
SQL> print c;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7566 JONES MANAGER 7839 02-APR-81 2975 1000 20
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 12-JAN-83 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7934 MILLER CLERK 7782 23-JAN-82 1300 10
7945 CINDY SALESMAN 7698 16-JAN-83 1800 30
7950 TINA SALESMAN 7698 18-JAN-83 1850 30
16 rows selected.
SQL>
Similar Messages
-
How to Find Logical Database with table name
Shankar
Version 4.6x
If you need to find the logical database for a table name, you can used <b>SE36</b> - Logical Database Bulider.
Steps :-
Go to transaction <b>SE36</b>
Click <b>Extras -> Table usage</b>
Supply the Table name and hit enter.
A Display Logical Database will be shown on a pop-up windows.
Reward points if it is usefull ....
Girish -
How to define a function with table type parameter
Hello All,
Here is the requirement ..
cursor c is select first_name, last_name , ssn from employee ;
TYPE employee_type IS TABLE OF c%rowtype;
tbl_employee_type employee_type;
I want to pass the parameter to a function the ssn -: tbl_employee_type(1).ssn
how the formal parameter should be declared
===========================
function chk_notnull_blank ( ? ) return boolean is
BEGIN
if ( colname is NOT NULL and colname in ( -8E14, -7E14, -6E14, -5E14, -4E14, -3E14, -2E14, -1E14, -1E9 )) then
RETURN TRUE ;
else
RETURN FALSE ;
end if;
END chk_notnull_blank;
======================
pls advice
thanks/kumarYou cannot define a generic argument in a function,
but you can overload several funtions with the same name and different types of arguments in a package,
in this way (not tested):
create table employees as
select employee_id ssn, first_name, last_name from hr.employees;
create or replace
PACKAGE chk
IS
cursor c is select first_name, last_name , ssn from employees ;
TYPE employee_type IS TABLE OF c%rowtype;
TYPE employee_ssn_type IS TABLE OF employees.ssn%TYPE;
TYPE employee_num_type IS TABLE OF number;
FUNCTION chk_notnull_blank ( colname employees.ssn%TYPE) RETURN boolean;
FUNCTION chk_notnull_blank ( colnames employee_type) RETURN boolean;
FUNCTION chk_notnull_blank ( colnames employee_ssn_type) RETURN boolean;
FUNCTION chk_notnull_blank ( colnames employee_num_type) RETURN boolean;
END chk;
create or replace
PACKAGE BODY chk
IS
FUNCTION chk_notnull_blank ( colname employees.ssn%TYPE) RETURN boolean IS
BEGIN
if ( colname is NOT NULL and colname in ( -8E14, -7E14, -6E14, -5E14, -4E14, -3E14, -2E14, -1E14, -1E9 )) then
RETURN TRUE ;
else
RETURN FALSE ;
END IF;
END chk_notnull_blank;
FUNCTION chk_notnull_blank ( colnames employee_type) RETURN boolean IS
BEGIN
FOR i IN colnames.FIRST .. colnames.LAST LOOP
IF NOT chk_notnull_blank( colnames( i ).ssn )
THEN
RETURN FALSE;
END IF;
END LOOP;
RETURN true;
END chk_notnull_blank;
FUNCTION chk_notnull_blank ( colnames employee_ssn_type) RETURN boolean
IS
BEGIN
FOR i IN colnames.FIRST .. colnames.LAST LOOP
IF NOT chk_notnull_blank( colnames( i ) )
THEN
RETURN FALSE;
END IF;
END LOOP;
RETURN TRUE;
END chk_notnull_blank;
FUNCTION chk_notnull_blank ( colnames employee_num_type) RETURN boolean
IS
BEGIN
FOR i IN colnames.FIRST .. colnames.LAST LOOP
IF NOT chk_notnull_blank( colnames( i ) )
THEN
RETURN FALSE;
END IF;
END LOOP;
RETURN TRUE;
END chk_notnull_blank;
END chk;I assumed in this example that if the argument of the function chk_notnull_blank is of the table (collection) type,
then the function returns true if all table elements pass the check, otherwise it returns false. -
Dynamic SQL : passing table name as parameter
Hi
I have a SQL query (a store procedure ) that i want to convert to PLSQL
This is a part of my SQL query that i am trying to to find a solution for it, because i cant convert it to oracle :
DECLARE lookupTableRow CURSOR FOR
SELECT TableName FROM SYS_LookUpTable
OPEN lookupTableRow
FETCH NEXT FROM lookupTableRow INTO @tableName
WHILE @@FETCH_STATUS=0
BEGIN
SET @sql='SELECT * FROM '+@tableName
EXECUTE sp_executesql @sql
IF @counter=0
BEGIN
INSERT INTO T_TABLE_MAPPING VALUES('P_MAIN_METADATA', 'Table', @tableName)
END
ELSE
BEGIN
INSERT INTO T_TABLE_MAPPING VALUES('P_MAIN_METADATA', 'Table'+CONVERT(NVARCHAR(10),@counter), @tableName)
END
SET @counter=@counter+1
FETCH NEXT FROM lookupTableRow INTO @tableName
END
CLOSE lookupTableRow
DEALLOCATE lookupTableRow
As i understand i can't use ORACLE dynamic sql (execute immediate) when the table name is a parameter
Furthermore when i execute this dynamic query in my SQL store procedure each SELECT statement return me as a result the relevant table rows , those result are different in each loop .
So i cant do this too with ORACLE dynamic sql .
Please advice for any solution
* how can i use dynamic sql with table name as parameter ?
* how can i use a "dynamic" cursor, in order to be able to display the dynamic results ?
Thanks for the adviceHi,
b003cf5e-e55d-4ff1-bdd2-f088a662d9f7 wrote:
Hi
I have a SQL query (a store procedure ) that i want to convert to PLSQL
This is a part of my SQL query that i am trying to to find a solution for it, because i cant convert it to oracle :
DECLARE lookupTableRow CURSOR FOR
SELECT TableName FROM SYS_LookUpTable
OPEN lookupTableRow
FETCH NEXT FROM lookupTableRow INTO @tableName
WHILE @@FETCH_STATUS=0
BEGIN
SET @sql='SELECT * FROM '+@tableName
EXECUTE sp_executesql @sql
IF @counter=0
BEGIN
INSERT INTO T_TABLE_MAPPING VALUES('P_MAIN_METADATA', 'Table', @tableName)
END
ELSE
BEGIN
INSERT INTO T_TABLE_MAPPING VALUES('P_MAIN_METADATA', 'Table'+CONVERT(NVARCHAR(10),@counter), @tableName)
END
SET @counter=@counter+1
FETCH NEXT FROM lookupTableRow INTO @tableName
END
CLOSE lookupTableRow
DEALLOCATE lookupTableRow
As i understand i can't use ORACLE dynamic sql (execute immediate) when the table name is a parameter
Furthermore when i execute this dynamic query in my SQL store procedure each SELECT statement return me as a result the relevant table rows , those result are different in each loop .
So i cant do this too with ORACLE dynamic sql .
Please advice for any solution
* how can i use dynamic sql with table name as parameter ?
* how can i use a "dynamic" cursor, in order to be able to display the dynamic results ?
Thanks for the advice
I have a SQL query (a store procedure ) that i want to convert to PLSQL
I doesn't help when you use one term to mean another thing.
SQL is a language used in both Oracle and other products, such as Microsoft's SQL Server. I don't know much about SQL Server, but Oracle (at least) doesn't support stored procedures in SQL itself; they have to be coded in some other language, such as PL/SQL.
As i understand i can't use ORACLE dynamic sql (execute immediate) when the table name is a parameter
If the table name is a parameter (or only known at run-time for any reason), that's exactly the kind of situation where you MUST use dynamic SQL.
The number of columns that a query produces (and their datatypes) is fixed when you compile a query, whether that query is dynamic or not. If you have multiple queries, that produce result sets with different numbers of columns, then you can't combine them into a single query. The best you can do with one query is to add NULL columns to some of the queries so they all produce the same number of columns.
If you're just displaying the results, there might not be any reason to combine separate result sets. Just display one result set after another.
Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002 -
How-To Find the R/3 Table Name for a BW Data Source
Hi there,
Please advice how can I find the respective table name in R/3 for a particular BW DataSource ?
P/S : I would like a technical how-to instead of referring the table names at HELP.SAP.COM
For instance, for my Standard Business Content Info Cube 0CCA_C03(CO-OM-CCA: Statistical Key Figures) which extracts from BW Data Source: 0CO_OM_CCA_4
My question is, how can I find out which specific tables in SAP R/3 is this Data Source pulling the data from ?Hi Dinesh,
Data Source: 0CO_OM_CCA_4
1) In my R/3, I ran SE16 : Table -> ROOSOURCE
2) OLTPSOURCE -> 0CO_OM_CCA_4
3) EXMETHOD = F1
(Hence, I assume the Extraction Method is a Function Module)
4) So, Function Module = BWOM_RS_GET_CTRSTA
5) Run SE37 in R/3
How do I find out the specific tables in this Function Module ?
Would you please list them for me, so I can further refer to the individual tables ? -
How to create a function with ref_cursor as parameter in OWB 10.1
Hi,
Can any one help me how to create a function with ref_cursor as parameter in OWB 10.1.?
Its urgent. Please help me.
Thanks,
SivHi David,
Thanks for your reply.
Before going for this function, I need to create a package in transformation node in owb module.
My package is as follows,
Create or replace package 123
type xxx is RECORD ( parameters);
type yyy is RECORD (parameters);
type aaa is table of yyy;
type bbb is REF CURSOR return xxx;
type ccc is record (parameters);
type ddd is ref cursor return eee;
END;
How can I create the above kind of package manually in OWB 10.1 (Should not to import the package)
Please help me its urgent.
Thanks,
Siv -
How to write a function block?
Hi There,
Does anybody know how to write a function block with LabVIEW? Something like those in Real-Time VIs>>Function Blocks>>.
Thank you very much in advance?
Solved!
Go to Solution.I don't want to overwelm you but there is tons of free training material online. One of these is the one already mentioned.
NI Learning Center
NI Getting Started
-Hardware Basics
-LabVEW Basics
-DAQ Application Tutorials
3 Hour LabVIEW Introduction
6 Hour LabVIEW Introduction
Self Paced training for students
Self Paced training beginner to advanced, SSP Required
LabVIEW Wiki on Training
Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously. -
How to write a function generator
How to write a function generator from labview and using PCI-MIO-16
Hallo, [email protected],
Du (x) meintest am 27.07.01 zum Thema How to write a function generator:
> How to write a function generator from labview and using PCI-MIO-16
Look to the examples - there are many VIs with that function.
Viele Gruesse!
Helmut -
How Create procedure or function with ADO ?
Hello,
How Create procedure or function with ADO?It's my question.
Thanks.
HenriThis message if post by Taiwan-ChangHaw-Oracle-Stored-Procedure-For-Business-Rule-Club
public bool ConnectDatabase()
try
{ string strConnectionString =
"Provider=OraOLEDB.Oracle" +";"+
"Data Source=" + ConnectionParams.Datasource +";"+
"User Id =" + ConnectionParams.Username +";"+
"Password =" + ConnectionParams.Password;
m_conn=new ADODB.Connection();
m_conn.ConnectionString=strConnectionString;
m_conn.Open("","","",0); //i_"YYAOl Open the connection
catch(Exception e)
{ System.Windows.Forms.MessageBox.Show(e.Message);
return false;
return true; //YYAOl_B>3I9&connected successfully
public void InsertDescription(string p_product,string p_language,string p_tname,string p_tdescription)
{ string sql="{Call inserttranslateddescription(?,?,?,?,?)}";
try
{ ADODB._Command cmd=new ADODB.Command();//Create a command object
cmd.ActiveConnection=m_conn; //Set its active connection to open connection
ADODB.Properties properties=cmd.Properties;//Get the command properties into ADODB Properties object
IEnumerator ienum=properties.GetEnumerator();//Get an enumerator on above properties
ADODB.Property singleprop;
while(ienum.MoveNext()) //iterate through the enumerator
{singleprop=(ADODB.Property)ienum.Current;//Get the current property from enumerator
string propname= singleprop.Name; //Get the name of current property
if(propname.Equals("NDatatype")) //if the property is 'NDatatype' set its value to true
singleprop.Value=true;
cmd.CommandType=ADODB.CommandTypeEnum.adCmdText;
int pid=Int32.Parse(p_product);
ADODB._Parameter langid =cmd.CreateParameter("langid", ADODB.DataTypeEnum.adChar,ADODB.ParameterDirectionEnum.adParamInput, 100,p_language);
ADODB._Parameter productid =cmd.CreateParameter("productid", ADODB.DataTypeEnum.adNumeric,ADODB.ParameterDirectionEnum.adParamInput, 100,pid);
ADODB._Parameter tname =cmd.CreateParameter("tname", ADODB.DataTypeEnum.adBSTR,ADODB.ParameterDirectionEnum.adParamInput, 50,p_tname);
ADODB._Parameter tdescription=cmd.CreateParameter("tdescription",ADODB.DataTypeEnum.adBSTR,ADODB.ParameterDirectionEnum.adParamInput, 50,p_tdescription);
ADODB._Parameter check =cmd.CreateParameter("check", ADODB.DataTypeEnum.adNumeric,ADODB.ParameterDirectionEnum.adParamOutput,100,0);
cmd.Parameters.Append(langid);
cmd.Parameters.Append(productid);
cmd.Parameters.Append(tname);
cmd.Parameters.Append(tdescription);
cmd.Parameters.Append(check);
cmd.CommandText=sql;
//Execute the command to insert product details in database
object recs;
object param=p_language;
cmd.Execute(out recs,ref param,1);
ienum.Reset();
while(ienum.MoveNext()) //iterate through enumerator
{ singleprop=(ADODB.Property)ienum.Current;//Get the current property in to Property object
string propname= singleprop.Name; //Get the name of current property
if(propname.Equals("NDatatype")) //if it is 'NDatatype' set its value to true
singleprop.Value=false;
IEnumerator iprop=cmd.Parameters.GetEnumerator();//Get the enumerator for command parameters
while(iprop.MoveNext()) //loop through enumerator
{ //Get the current parameter in enumerator
ADODB._Parameter checkval=(ADODB._Parameter)iprop.Current;
if(checkval.Name.Equals("check")) //if the parameter is 'check'
if(checkval.Value.ToString().Equals("0")) //If check's value is zero data was inserted
System.Windows.Forms.MessageBox.Show("Product details Inserted successfully");
else
System.Windows.Forms.MessageBox.Show("Product Details Updated");//else data was updated
catch(Exception e)
System.Windows.Forms.MessageBox.Show(e.Message);//Display any error message
} -
How to write a messenger with using java?
May I know how to write a messenger with using java? The messenger need included two functions which are file transfer and add users to join the conversation.
Thank you.Ok, so you need to start from the beginning, the requirements, is it a swing (i.e. GUI) app, web app, console, etc...?
As stated by sprizor making an IM client is no easy task, you need to both implement the server side and the client side, which both communicate with each other, file transfers are also quite complex, and even maintaining a multi-user chat can be quite difficult.
If you are after a Web Based app, then you will need to look into Push technologies, like Grizzly Comet which is a nice wrapper for the NIO java stuff:
https://grizzly.dev.java.net/
Good luck... -
How to write a applet with multiple menu
Hi all,
How to write a applet with multiple menu or please tell me where can I get a examples
thanksi'm writing a project and it seem not work with browser. If anyone can help please leave me a e-mail so that i can send my source to you.
Thanks so much -
Problem with writing a procedure with table name as an input parameter
Hi all,
I am writing a procedure with table name as an input parameter:
below is the code
create or replace procedure prc(in_tbl in varchar2)
as
begin
execute immediate ' truncate table tlb ';
insert into tbl
select a,b,c from in_tbl;
end;user579585 wrote:
Hi all,
I am writing a procedure with table name as an input parameter:
below is the code
create or replace procedure prc(in_tbl in varchar2)
as
begin
execute immediate ' truncate table tlb ';
insert into tbl
select a,b,c from in_tbl;
end;You'll also need to use dynamic sql for the insert:
execute immediate 'begin insert into tbl select a,b,c from '||in_tbl||'; end'; -
How can I work lsmw with table control using mm01 appl?
Hi
How can I work lsmw with table control using mm01 appl?
Is it difefrent the way we handle table control in BDC?
Thank YouHi
How can I work lsmw with table control using mm01 appl?
Is it difefrent the way we handle table control in BDC?
Thank You -
How to write sql query with many parameter in ireport
hai,
i'm a new user in ireport.how to write sql query with many parameters in ireport's report query?i already know to create a parameter like(select * from payment where entity=$P{entity}.
but i don't know to create query if more than 1 parameter.i also have parameter such as
$P{entity},$P{id},$P{ic}.please help me for this.
thanksYou are in the wrong place. The ireport support forum may be found here
http://www.jasperforge.org/index.php?option=com_joomlaboard&Itemid=215&func=showcat&catid=9 -
How to use TRUNC function with dates in Expression Builder in OBIEE.
Hi There,
How to use TRUNC function with dates in Expression Builder in OBIEE.
TRUNC (SYSDATE, 'MM') returns '07/01/2010' where sysdate is '07/15/2010' in SQL. I need to use the same thing in expression builder in BMM layer logical column.
Thanks in advanceuse this instead:
TIMESTAMPADD(SQL_TSI_DAY, ( DAYOFMONTH(CURRENT_DATE) * -1) + 1, CURRENT_DATE)
Maybe you are looking for
-
SQL query with JSP and WML-parameters
Hey, Could you help me? I'm trying to do the following. WML deck card 1 send parameter to same WML deck's card help. I try to read the parameter with JSP in card help by putting the parameter to SQL query, but it doesn't work. I can read the paramete
-
Deployment Error in Web DynPro
Hi, I m getting the following error when i deploy any WD Application. J2EE engine is running and i changed the Visual Admin password from abcd1234 to new password. After this, I am getting this error. It says User authenitication failed. Aborted: dev
-
Hi there I have an E51 and am not sure what has happened but one minute all my contacts were visible and now they are not. If a person whose details I have stored in my phone memory calls me I can see their details however I cannot retrieve contact i
-
Strange tooltip behaviour in browsers
Recently I notice that while I am using some internet browser like Safari or Firefox, some strange yellow tooltip-like boxes appear under the mouse pointer. The yellow tooltip box usually shows some very obsure web links, absolutely unrelated to the
-
When emailing I get two messages Unable to initalize Applet and Unable to get HTML message.
When writing the message these two messages pop up in error windows making it unable to type the message.