?Table_name as a procedure parameter
Hi, does anyone know how to accept table and column names as arguements. I created a view from user_tab_columns so I can see the table (parameter) in the procedure but I can't update or insert because Oracle can't see the table.
The code looks something like this so far!
CURSOR MYCURSOR IS
SELECT p_column_name, p_table_name| |'_REC' -- primary key
FROM my_view
WHERE table_name = p_table_name
AND column_name = p_column_name;
FOR record in cursor LOOP
pl/sql code to change all records
(Here's the problem)
UPDATE p_table_name set p_column_name = v_new_column
WHERE p_table_name| |'_REC' = record.p_table_name| |'_REC';
ERROR p_table_name must be declared!
Any help?
Thanks
Dave
You need to give explicit rights on the tables, that is not through roles. The table names will simply not show up in the select statement unless you have been granted direct rights on them. So your problem could be that you have rights on the tables through a role, but what you need is to log in as the owner and i.e.
grant select, insert, update on emp to developer
etc.
If it's not this I'm lost.
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by David Wilton ([email protected]):
Hi, does anyone know how to accept table and column names as arguements. I created a view from user_tab_columns so I can see the table (parameter) in the procedure but I can't update or insert because Oracle can't see the table.
The code looks something like this so far!
CURSOR MYCURSOR IS
SELECT p_column_name, p_table_name| |'_REC' -- primary key
FROM my_view
WHERE table_name = p_table_name
AND column_name = p_column_name;
FOR record in cursor LOOP
pl/sql code to change all records
(Here's the problem)
UPDATE p_table_name set p_column_name = v_new_column
WHERE p_table_name| |'_REC' = record.p_table_name| |'_REC';
ERROR p_table_name must be declared!
Any help?
Thanks
Dave<HR></BLOCKQUOTE>
null
Similar Messages
-
Stored Procedure parameter (@Carrier) used in report and can't be set via code
I have a report that has regular Crystal parameters that I am setting correctly via code. However, one report actually uses one of the database parameters from the stored procedure that the report was created from. It is the only report like this and I'm using the same code in an attempt to set it's value. Although no error is thown, if I look at the parameter value in the IDE it is set correctly, but the field on the report just shows up blank. I have changed the way the report is created. Previously, I used the report.export method to create the actual file via a stored procedure. Now, I'm running the stored procedure first and creating a datatable. This allows me to execute the SP only once to see if it has data, because only then do I want to create the actual report. I'm using the SetDataSource method to pass the datatable into Crystal and then using the report.export method to create the report with data. Everything seems to work, except this stored procedure parameter (@Carrier) is not actually being populated to display on the report.
Not sure what to look at. Any suggestions?
Thanks.crpe32.dll is version 13.0.5.891. This was developed in VS2012 and VB.NET. I'm using ADO.Net to connect to a MS SQL Server database.
MainReport.SetDataSource(DTbl)
bRC = PopulateAllSubReports(MainReport)
If Not bRC Then Throw New Exception("Received an error in PopulateAllSubReports.")
bRC = PopulateCrystalParameters(MainReport, SP)
If Not bRC Then Throw New Exception("Received an error in PopulateCrystalParameters.")
'Actually create the output file.
bRC = ExportData(MainReport)
Private Function PopulateCrystalParameters(myReportDocument As ReportDocument, SP As ReportStoredProcedureCrystal) As Boolean
Dim myParameterFieldDefinitions As ParameterFieldDefinitions = Nothing
Dim myParameterFieldDefinition As ParameterFieldDefinition = Nothing, ParamValue As String = ""
Dim bRC As Boolean, Param As SqlParameter = Nothing
Try
myParameterFieldDefinitions = myReportDocument.DataDefinition.ParameterFields
'*********************Report Parameters***************************
For Each myParameterFieldDefinition In myParameterFieldDefinitions
myParameterFieldDefinition.CurrentValues.Clear()
Select Case myParameterFieldDefinition.ParameterFieldName.Trim.ToUpper
Case "@CARRIER"
If SP.DBParameters.ContainsKey("@CARRIER") Then
Param = SP.DBParameters("@CARRIER")
ParamValue = NullS(Param.Value).Trim
bRC = SetCurrentValueForParameterField(myParameterFieldDefinition, ParamValue)
If Not bRC Then Return False
End If
End Select
Next
Return True
Catch ex As Exception
GmcLog.Error("ReportKey = " & Me.ReportKey.ToString & ", " & ex.Message, ex)
Return False
End Try
End Function
Private Function SetCurrentValueForParameterField(myParameterFieldDefinition As ParameterFieldDefinition, submittedValue As Object) As Boolean
Dim currentParameterValues As ParameterValues = Nothing
Dim myParameterDiscreteValue As ParameterDiscreteValue = Nothing
Try
myParameterDiscreteValue = New ParameterDiscreteValue
myParameterDiscreteValue.Value = NullS(submittedValue).Trim
currentParameterValues = New ParameterValues
currentParameterValues.Add(myParameterDiscreteValue)
myParameterFieldDefinition.ApplyCurrentValues(currentParameterValues)
Return True
Catch ex As Exception
GmcLog.Error("ReportKey = " & Me.ReportKey.ToString & ", " & ex.Message, ex)
Return False
Finally
myParameterDiscreteValue = Nothing
currentParameterValues = Nothing
End Try
End Function
Private Function SetDBSourceForSubReport(mySubReport As ReportDocument) As Boolean
Dim myTables As Tables = Nothing, myTable As Table = Nothing, DTbl As DataTable, SP As StoredProcedure = Nothing
Try
myTables = mySubReport.Database.Tables
For Each myTable In myTables
Dim SPName As String = myTable.Location.Substring(0, myTable.Location.IndexOf(";"c))
SP = New StoredProcedure(ConnectionString, SPName, CommandType.StoredProcedure)
DTbl = SP.FillTable
mySubReport.SetDataSource(DTbl)
SP = Nothing
Next
Return True
Catch ex As Exception
GmcLog.Error("ReportKey = " & Me.ReportKey.ToString & ", " & ex.Message, ex)
Return False
Finally
If Not SP Is Nothing Then SP = Nothing
If Not myTable Is Nothing Then myTable = Nothing
If Not myTables Is Nothing Then myTables = Nothing
End Try
End Function
Private Function PopulateAllSubReports(myReportDocument As ReportDocument) As Boolean
Try
Dim mySections As Sections = myReportDocument.ReportDefinition.Sections
For Each mySection As Section In mySections
Dim myReportObjects As ReportObjects = mySection.ReportObjects
For Each myReportObject As ReportObject In myReportObjects
If myReportObject.Kind = ReportObjectKind.SubreportObject Then
Dim mySubreportObject As SubreportObject = CType(myReportObject, SubreportObject)
Dim subReportDocument As ReportDocument = mySubreportObject.OpenSubreport(mySubreportObject.SubreportName)
Dim bRC = SetDBSourceForSubReport(subReportDocument)
If Not bRC Then Return False
End If
Next
Next
Return True
Catch ex As Exception
GmcLog.Error("ReportKey = " & Me.ReportKey.ToString & ", " & ex.Message, ex)
Return False
End Try
End Function -
Passing a table as a procedure parameter
I'm trying to pass a table_name as a parameter but it is not working. Any idea ???
CREATE OR REPLACE PROCEDURE SIMM.populate_field
( field_name IN all_tab_columns.column_name%TYPE)
IS
v_a part_index_temp.no_dossier%TYPE;
CURSOR c_temp IS
SELECT no_dossier FROM part_index_temp FOR UPDATE;
BEGIN
OPEN c_temp;
LOOP
FETCH c_temp INTO v_a;
EXIT WHEN c_temp%NOTFOUND;
UPDATE part_index_temp a
SET
a.nouv_nom = (
SELECT field_name
FROM part_index_temp
WHERE rnum= (SELECT (1+ABS(MOD(dbms_random.random,10)))
FROM dual)
WHERE CURRENT OF c_temp;
END LOOP;
CLOSE c_temp;
END;What are you trying to accomplish?
Describe the business requirement and we can help you.
The way you are trying to pass in a Column name (not the table name) requires dynamic sql... -
Passing the database name as a PL/SQL procedure parameter
How do I pass the name of the database as a parameter to a procedure?
If dbs is the variable name to which I pass the database name as shown in the example,
CREATE OR REPLACE PROCEDURE Extract_gl_acct_Tbl(dbs varchar2)
and I use dbs in the code as follows,
SELECT ACCOUNT,
SETID
FROM SYSADM.PS_GL_ACCOUNT_TBL@dbs
It gives me an error saying 'ORA-04054: database link DBS does not exist'.You will need to use dynamic SQL to handle this:
create or replace ...
is
type rc is ref cursor;
v_rc rc;
begin
open v_rc for 'select ... from sysadm.ps_gl_account_tbl@' || dbs;
fetch v_rc into ... -- some variables
-- if multiple rows, you'll need to do the fetch in a loop and exit when v_rc%notfound.
close v_rc;
end; -
Pivot table that uses a Stored Procedure parameter and filters the data based on it
Hello, my 1st post. I am lost. Please help.
I am trying to create an Excel Pivot Table that has data that comes from an ODC but needs to be filtered based on a parameter from a Stored Procedure. This involves Project Server. I need to filter the results based on the RBS value of the logged
in user. My Stored Procedure can return the RBS as long as the ResourceNTAccount value is given. I cant figure out how to tie this all together.Hi,
Based on your description,I think this issue should be more related to Programming/coding, you can sumbit a new case to MSDN forum.
As I'm not quite formular with Project Server, all I can tell you is that it is easy to running a Stored Procedure within Excel, however, if you have to pass dynamic parameters you’ll have to turn to VBA.For detailed information,please refer
to:
http://blogs.office.com/2010/06/07/running-a-sql-stored-procedure-from-excel-no-vba/
Wind Zhang
TechNet Community Support -
How to pass record set as procedure parameter.
Hi All,
I have a requirement, I want to pass the records that are fetched from a cursor to a procedure as a parameter.
I dont want to use it inside the loop as we do it normally, as i might get huge volume of records using cursor, as a result the procedure also will be called number of times inside the loop.
Can you suggest me the logic along with sample code?
Thanks
SureshGSKumar wrote:
I have a requirement, I want to pass the records that are fetched from a cursor to a procedure as a parameter.A cursor outputs rows - not "records".
I dont want to use it inside the loop as we do it normally, as i might get huge volume of records using cursor, as a result the procedure also will be called number of times inside the loop.
Can you suggest me the logic along with sample code?How else do you want to do it? If there are a million rows returned by the cursor, it means a million executions of that procedure - once for every row.
This will be slow. And the primary reason is that executing a PL/SQL procedure (or any other code unit) for a million times, will be slow. Changing the cursor interface (from an implicit cursor to a ref cursor for example) does not change the fact there needs to be a million PL/SQL procedure executions - and does not make anything faster. To fetch rows from a cursor needs to a loop. Period.
There are two basic ways to address this issue at hand.
Use SQL and not PL/SQL. Instead of using PL/SQL code and logic, use SQL code and logic. This will be faster as the PL/SQL engine no longer plays a role and a million rows do not have to be send from the SQL engine to the PL/SQL engine. Instead that million rows are processed internally in the SQL engine - which will be faster. And which will provide scalable options such as using parallel query.
Use "multi-threaded" PL/SQL. Assuming the PL/SQL code and logic are too complex to be done in SQL, the next best choice is PL/SQL. However, a single serialised PL/SQL process going through a million rows will be slow and will not scale. If parallel PL/SQL can be used, then 20 PL/SQL processes can each do 50,000 rows - as oppose to having to do a million rows.
There are two options to "multi-thread" PL/SQL code. You can use DBMS_PARALLEL_EXECUTE (11g). You can use a parallel pipelined table function (10g and higher). -
How to call a script with procedure parameter
I have a script my_script.sql in sqlplus and that script calls a procedure with one in parameter my_procedure (my_parameter IN VARCHAR2).
I need to pass the parameter in the script call.
sqlplus>@my_script my_parameter
How can I do that?SQL> set serveroutput on
SQL> create or replace procedure testpass (par1 in varchar2)
2 is
3 begin
4 dbms_output.put_line(par1);
5* end;
SQL> get my_script
1* exec testpass ('&1');
SQL> @my_script 'This is the parameter'
This is the parameter
PL/SQL procedure successfully completed.
SQL> -
Procedure parameter of type returned by function
Hi there
I want to know if it's possible to pass a parameter to procedure of type returned by function
Something like that
pocedure test(x in varchar2
,y in my_function(param)
)Definitely don't fullish yourself ;-)
AFAIK you cannot declare a variable based on the return type of a function.
Perhaps though you are looking for SUBTYPEs.
SQL> SET SERVEROUTPUT ON;
SQL> DECLARE
2 SUBTYPE subtype_name IS VARCHAR2 (30) NOT NULL;
3
4 PROCEDURE procedure_name (
5 parameter_name IN subtype_name)
6 IS
7 BEGIN
8 DBMS_OUTPUT.PUT_LINE (parameter_name);
9 END;
10
11 FUNCTION function_name (
12 parameter_name IN DATE)
13 RETURN subtype_name
14 IS
15 BEGIN
16 RETURN TO_CHAR (parameter_name, 'DAY');
17 END;
18
19 BEGIN
20 procedure_name (function_name (SYSDATE));
21 END;
22 /
THURSDAY
PL/SQL procedure successfully completed.
SQL> -
Procedure Parameter - Size of Varchar2
Hi,
I have a doubt regarding the procedure/Function parameter.
We can pass varchar2 as parameter in Procedure and function. What is it default size since in table it has 4000 bytes but in procedure/function what is it size?
Please advise.
Thanks in advance.I think there is no restriction.
I think it is a best practise that ,instead of passing many arguments in procedure pass an object or record that holds many fields. It is more maintable
Regards... -
A query as procedure parameter
Dear members,
(Forms 6i c/s)
I'd like to send a query through a parameter to a procedure.
The query has to be in a cursor.
How can I do ?
Can I send the text of the query, and tell Forms to use it as a query when declaring the cursor ?
Can I send the cursor through a parameter ?
Thanks for your help.Can you, sure. Should you? At most, rarely.
You can use dynamic SQL (EXECUTE IMMEDIATE or DBMS_SQL) to execute an arbitrary string as a SQL statement. There are serious security issues if someone figures out how to pass a dangerous SQL statement in (i.e. update the USERS table, delete all the data from some important table, etc). If you are passing in a SELECT statement and you don't know the structure of the result set, you have to use DBMS_SQL rather than the simpler EXECUTE IMMEDIATE and use a more complicated API to describe the result set.
Justin -
Trace logs don't show the value of a procedure parameter.
Hi;
I am Facing a deadlock situation daily.
I checked the alert.log and it look like this:
ORA-00060: Deadlock detected. More info in file /oracle/admin/TEXP/udump/texp_ora_28966970.trc.Then i read the trace log, but it doesn´t show the value of procedure parameters.
insert into estq_300 (data_movimento, codigo_transacao, nivel_estrutura, grupo_estrutura, subgrupo_estrutura,
item_estrutura, quantidade, valor_movimento_unitario, valor_contabil_unitario, codigo_deposito, numero_lote,
centro_custo, usuario_systextil, processo_systextil, tabela_origem, entrada_saida, numero_documento) VALUES
(:v1, :v2, :v3, :v4, :v5, :v6, 1.00, :v7, :v8, :v9, 0, 0, :v10, :v11, 'ESTQ_300', 'E', :v12)
End of information on OTHER waiting sessions.
Current SQL statement for this session:
UPDATE TB_Y SET QTDE_ESTOQUE_ATU = QTDE_ESTOQUE_ATU + :B11 , QTDE_ESTOQUE_MES =
QTDE_ESTOQUE_MES + :B10 , DATA_ULT_ENTRADA = :B9 , DATA_ULT_SAIDA = :B8 , QTDE_ESTOQUE_F =
QTDE_ESTOQUE_F + :B7 WHERE CDITEM_NIVEL99 = :B6 AND CDITEM_GRUPO = :B5 AND CDITEM_SUBGRUPO =
:B4 AND CDITEM_ITEM = :B3 AND LOTE_ACOMP = :B2 AND DEPOSITO = :B1I sent the trace logs to the software supplier, but they want the parameter values.
I'm reading the documentation and searching on the forum, but until now i can't find anything to help me. Is there any way to see the parameter value?
This is a large database with a lot of users, so I can't trace all of them and wait the deadlock occurs.
DATABASE:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
OS:
AIX Version 6.1! Regards,sb92075,
thanks for reply,
This VW's helped a lot, but i have one doubt:
Why some SQLs don´t show the value of it´s binds?
The last captured is null too, why?
Example:
SELECT name, position, last_captured, value_string FROM v$sql_bind_capture WHERE sql_id LIKE '%ahfqand46px43%';
NAME POSITION LAST_CAPTURED VALUE_STRING
:V1 1
:V2 2
:V3 3
:V4 4
:V5 5
:V6 6Thank's -
Hello all.
I'm writing class which will generate code of OracleCommand automatically.
Something like this:
OracleCommand cmd = GenerateCommand("MyStoredProcName");
I need to get list of parameters and its types too.
How can do it with Oracle? Is there special packages or views where i can find it?
PS. In PL/SQL Developer this info can be found by clicking "Describe" on stored proc.
PPS. I'm working with .Net, but I think that it is unimportant.You can go to the data dictionary and use:
all_procedures
all_arguments (Oracle don't know difference between argument and parameter...)
Be careful because those view definitions change between 10.1 and 10.2 versions of Oracle. Which trip up some versions of IDE such as TOAD.
Or you can use DBMS_METADATA in v10 onward.
I don't know about .net but OCI and OCCI have the ability to describe the target you have a handle to and give back list of table columns and types, or procedure parameters, so I guess maybe that Oracle provider for .net supply this ability too. Maybe go ask on the .net provider forum.
I don't really see the point of what you're trying to do though. -
SSL Shutdown procedure parameter
When issuing the 'show ssl-proxy-list <name>' command there is a parameter called 'SSL Shutdown procedure' which is set to NORMAL.
Does this refer to the fact the CSS reboots when the SSL module fails ? If so, can this parameter be changed ?
Thanks, Mikeno, this parameter refers to how the ssl module terminates an SSL connection.
openssl calls this operation "shutdown".
The CSS by default uses the default shutdown mode, but you can change it with the command 'ssl-server 10 unclean-shutdown'.
Some version of internet explorer do not like the normal shutdown which is why we have this unclean shutdown.
Regards,
Gilles. -
Hi
i would like to know if using varchar parameter in sql queries with number column can result in performance degrade.
Ex: Procedure testa ( myparam varchar) is
begin
select col1 into var1 from table where colno = myparam;
end;
Here colno is a number column and myparam is varchar. I feel its better to change the parameter to number. But i would like to get some advise before considering to change such occurences across my backend codes.In all versions of Oracle, including the version you are using and which you didn't bother to mention, implicit type conversion is always on the left hand side of the comparison.
Your statement will be transformed into
select col1
into var1
from table
where to_char(colno)= myparam;
If colno is indexed, the index will NOT be used, and Oracle will use a Full Table Scan.
The best, most robust solution is to use
myparam table.colno%type
Doing so, you can alter the column without having to change the procedure.
Sybrand Bakker
Senior Oracle DBA -
Pass unicode data in SQL Server 2008 stored procedure parameter
Hi,
I want to pass unicode data in a SQL stored procedure. But I am not sure that how to append N with NVarchar datatype.
For example I Create a table LocalizationTest and wants to insert a few records.
Create table LocalizationTest
Field1 NVarchar(255)
INSERT INTO LocalizationTest
VALUES(N'123 Illini Dr, 東皮奧里亞, 8989')
the above given statement works.
To explain it more , script A works but script B does not work.
DECLARE @X NVARCHAR(255)
[A]
SET @X=N '123 Illini Dr, 東皮奧里亞, 8989'
INSERT INTO LocalizationTest
VALUES(@X)
[B]
SET @X= '123 Illini Dr, 東皮奧里亞, 8989'
INSERT INTO LocalizationTest
VALUES(@X)
What is the correct way to execute script B because @X will be passed in a SQL Stored Procedure?
Thanks
Sharma M.If you do not pass the value as a Unicode value there is nothing left of the Unicode characters but question marks. Once this has happened, AFAIK there is no way to undo it (other than resetting the value as Unicode characters again).
Affirmative.
Demo - This is what happens if you convert UNICODE (nvarchar) to varchar with implicit conversion (try to force 2 bytes into one byte).
3F hex is '?'.
CREATE TABLE #LocalizationTest (Field1 VARCHAR(255))
INSERT INTO #LocalizationTest
VALUES(N'123 Illini Dr, 東皮奧里亞, 8989')
DECLARE @X NVARCHAR(255), @dSQL NVARCHAR(MAX)
SET @X=N'123 Illini Dr, 東皮奧里亞, 8989'
INSERT INTO #LocalizationTest VALUES(CONVERT(NVARCHAR(255),@X))
SET @dSQL = N'INSERT INTO #LocalizationTest VALUES(N'''+@X+''')'
PRINT @dSQL
EXEC sp_ExecuteSQL @dSQL
SELECT *, Field1Bin=convert(binary(30), Field1) FROM #LocalizationTest
DROP TABLE #LocalizationTest
123 Illini Dr, ?????, 8989 0x31323320496C6C696E692044722C203F3F3F3F3F2C203839383900000000
123 Illini Dr, ?????, 8989 0x31323320496C6C696E692044722C203F3F3F3F3F2C203839383900000000
123 Illini Dr, ?????, 8989 0x31323320496C6C696E692044722C203F3F3F3F3F2C203839383900000000
Kalman Toth Database & OLAP Architect
SQL Server 2014 Design & Programming
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012
Maybe you are looking for
-
My touch screen fell victim to the same issue many people have with this phone - the touch screen has become only effective for very limited items - mostly just Contacts. I've tried bluetooth and plugging in the phone, shutting it down and repowering
-
Which video cameras w/HD have a Fire Wire connectivity?
Recently, I bought a Sony video camera w/HD that had a USB cable to transfer data from a video camera HD to IMac. However, when I've attempted to do that, an application IMovie informed me that I must have a Fire Wire cable which video camera didn't
-
Does not having windows xp keep your pc from communication with an apple airport base station?
-
I have been trying to update my software in my macbook pro, but every time I go through the motions of updating/restarting my computer nothing happens and it still shows I need a software update. Anyone know why this is happening?
-
Annoying customer service issues...
Verizon customer service is super >Profanity removed< To make a long story short, this idiot at one of the verizon stores ordered the wrong replacement device and I had to deal with a long list of people that do not put proper notes in your account t