Can't execute a procedure [closed] - sql

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
this is the procedure name :
procedure misowner.proc_kr_text_niki(valdate in varchar2 default '20040101'
, v_table varchar2 default 'KR_TEMP')
and i what to EXEC it. What kind of variables i have to put?

Given that you have default values for the parameters you should be able to surround it with a block like this, and execute it as a script if you are using a GUI tool like SQL developer or Toad
DECLARE
valdate VARCHAR2(10);
v_table VARCHAR2(30);
BEGIN
misowner.proc_kr_text_niki;
END;
This works for testing, then, as suggested by BazzPsychoNut, initialize the variables, pass them in and test some more.

You call it by providing two parameters. The first parameter (= variable) "valdate" is in varchar2. It is apparently a date inputted as text in the form YYYYMMDD. The second parameter "v_table" is a varchar2, probably the name of the table to query on.

Related

What is a parametrised select? PL/SQL [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
We need to add a parameterised select in a pl/sql function. But I don't know what is a parameterised select. :(
You are probably talking about using bind variables in SQL statement in a PL/SQL code, like this:
declare
anumb number:=1;
.....
begin
select ....
into ....
from your_table
where a_column=anumb .....;
....
end;
In this sample code, the select can be called 'parameterised', as is uses a variable set before in the SQL. 'anumb' can also be a parameter passed to a function or procedure.
Finally, why do you tag your quest with sql-server when you have PL/SQL in the subject?

Stored Procedure PRINT each row value [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have a stored procedure where I like to display each Name in the table below
on a separate line with a PRINT so the user can see what has been retreived:
Select Name from Persons;
What is the best way to do this as I can use a cursor and then through each iteration display the Name with the PRINT. Is there a better way to do this?
I think the best way would be to select the output you want to show the user at the end of the procedure:
CREATE PROC dbo.test
AS
BEGIN
--do stuff
INSERT INTO foo (bar)
SELECT name
FROM persons
--select what to show user
SELECT name
FROM persons
END
PRINT doesn't work inside a stored procedure.
If you run the code without being wrapped in a SP, it will display what you want.

Why is this Stored Procedure Inserting NULL values into the table? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am trying to load data (2 columns) from XML_HOURS_LOAD (columns: code,product) to a table called STAGING (columns: code, product) and am getting null values inserted for both columns:
So I have the following stored procedure:
Create or Replace Procedure Cascade_Load (
p_code in XML_HOURS_LOAD.p_code%TYPE,
p_product in XML_HOURS_LOAD.p_product%TYPE
)
AS
BEGIN
INSERT INTO STAGING(code, product)
VALUES(p_code, p_product)
COMMIT;
END;
What am I doing wrong? Thanks in advance.
To answer your question of why it's inserting nulls, that is because you aren't providing any values to the procedure parameters when you execute it.
Based on what you stated in the question and your comment above, it seems you are missing some fundamental skills in working with Oracle. The code you wrote is a procedure, not a function, so you can't call it in a SELECT statement. A procedure is called inside of a plsql block. Your procedure as written takes two arguments, which you must pass to the procedure call via the calling code. The procedure code you wrote does not look for data from the XML_HOURS_LOAD table.
We've all been the new person learning Oracle. You'll want to look at some tutorials to get you started on the fundamentals of pl/sql coding to help clear up the differences between functions and stored procedures and how to use parameter arguments.
From what you wrote in your question, I believe this is the code you want:
DECLARE
p_code IS XML_HOURS_LOAD.code%TYPE,
p_product IS XML_HOURS_LOAD.product%TYPE;
CURSOR cXmlHoursLoadCursor IS (SELECT code, product FROM xml_hours_load); --You can add a WHERE condition to this cursor query
BEGIN
FOR v IN cXmlHoursLoadCursor LOOP
Cascade_Load(v.code, v.product);
COMMIT; --I recommend calling commit here instead of inside your stored procedure so that the calling code has control of the transaction state
END LOOP;
END;

We can go for transaction management in procedure but we can’t go in function? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
We can go for transaction management in procedure but we can’t go in function, I have seen this statement at multiple places, while we ask for difference between function & procedure, But I did below test in oracle and **I can see its working fine for function also**. Can anybody please let me know what thing am I missing about above statement, because this statement looks completely wrong to me?
select * from test; *(test table having single column "name varchar(2)")
create or replace function FUNTest
return number as result NUMBER(6,2);
BEGIN
SAVEPOINT fn_fntest;
insert into test(NAME) values('Dinesh');
ROLLBACK TO fn_fntest;
return 1;
END;
/
Begin
DBMS_OUTPUT.PUT_LINE(FUNTest());
end;
/
Purpose of function is different from procedure.
Function: Supposed to do some calculation and return some value(most
of the cases)
Procedure: Perform some operation based on data/column.It manages transaction as well, because you will definately be storing new data somewhere.
Now talking about transaction management in function, well it depends on calling mechanism of function.
If your function is having transactional statement like commit/rollback then it should be called from some other block which is capable of handling transaction like procedure or anonymous block(your case).
If you call that same function from select statement like "select funtest() from dual;" then you will get error as select statement is not capable of opening transaction.
If you still want to call any function having transactional statement from non-transactional body(select statement) then your function should be capable of opening separate independent transaction(PRAGMA AUTONOMOUS_TRANSACTION).
Please refer to http://www.datacoons.com/content/transaction.php for more information on transaction management.

Testing a procedure? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I'm new to PL/SQL and I think Ive created a procedure inside of my package body, when i run it in SQL commands it says it been successfully created, I am just not sure how to test it?
The procedure is to delete a customer based on their ID
Here is the code
PROCEDURE remove_customer (customer_id VARCHAR2) IS
BEGIN
DELETE FROM customer
WHERE customer.customer_id = remove_customer.customer_id;
END;
any idea on how to test it works?
Thanks
You can run it from an anonymous block:
begin
your_package.remove_customer('CUST_ID');
end;
/
If you're using SQL*Plus or SQL Developer there's a shorthand for this with the execute command:
exec your_package.remove_customer('CUST_ID');
And then check that the customer you tried to delete is no longer in the table...
you would just run it as:
begin
your_package_name.remove_customer('abc');
-- commit; -- optional if you want to commit it.
end;
/