Testing a function in PL/SQL Developer - oracle

This is my function:
FUNCTION GET(V_IN IN NUMBER) RETURN VARCHAR2 AS
V_OUT VARCHAR2(1000);
BEGIN
function body
END;
When I right click the function and click on test, I am getting the following:
begin
-- Call the function
:result := pkg.get(V_IN => :V_IN);
end;
How do I substitute a value for this variable V_IN? I need to test it for a number, say 940.
When I try the code:
declare
r varchar2(2000);
begin
-- Call the function
r := pkg.get(940);
end;
I am getting an error:
ORA-01036: illegal variable name/number
Can you suggest various ways of calling this function?
PS:
Tool used: PL/SQL Developer Allround Automations. Version 8.0.1.1502
Oracle Database 11g Enterprise Edition

Once you've clicked on your function and clicked on Test in the context menu a Test window is brought up with the code you've shown. There are two panes in this window - the top pane shows the code which PL/SQL Developer generated to invoke the function, and the lower pane contains a list of the parameters to your function. In the lower pane of the Test window there's a list of the parameters to the function with three columns - Variable, Type, and Value. Type the value you want into the Value column in the row with your parameter's name, then click on the Start Debugger button (top left of the Test window, under the 'Test Script' tab's name), then click on the Run button (immediately to the right of the Start Debugger button).
Best of luck.

"How do I substitute a value for this variable V_IN? I "
When you run the test in PLSQL Developer the bottom pane of the test window is a property list for all the substitution variables. You define the datatype and the input values (when appropriate). Output values are available in this window after the test is run.
"ORA-01036: illegal variable name/number"
Not sure what causes this. It's probably not PLSQL Developer but a bug in your function code (which you have not posted).

I was able to run the function as follows:
declare
v varchar2(1000);
begin
select pkg.get(940) into v from dual;
dbms_output.put_line(v);
end;
Also, as per APC's comment, there is a property list(the small window appearing below the PL/SQL worksheet, having Variable, Type and Value fields). You need to enter the value which you wish to pass in the value field and click on Execute (shortcut-F8). The output will be shown and highlighted in yellow in the same property list window. Click below link to refer the screenshot:
Function Call with single parameter

I assume you are still in pl/sql "Test window", when you modified the original test code to your custom. Pl/sql sometimes is buggy. Open a new "SQL window" and try to run there with dbms_output.put_line() to see the result.

Related

Show only input from user at runtime with sql developer and not the whole code

This is an example and i know this post too:
How to get input from user at runtime
When i run this code in sql developer with pl/sql:
DECLARE
a NUMBER;
BEGIN
a:=&a;
DBMS_OUTPUT.PUT_LINE(a);
end;
I get a prompt for my user input value and i see my input value on the script output.
Ok this works.
But i see the whole code and my input value.
A solution for exactly this example, no sqlplus, prompt or accept and not this post:
Provide a message prompt for user input in SQL Developer 3.1.07
Is it possible to deactivate the whole code output and only see my input value, is there a sql developer setting?
I'm using:
Oracle SQL Developer
Version 21.4.1.349
Build 349.1822
On a Windows 10 PRO
Oracle Database
21c Express(21.0.0.0.0)
Manage your output panel in SQL Developer:
Turns on|off verification
The VERIFY setting controls whether or not SQL*Plus displays before and after images of each line that contains a substitution variable.
SET VER[IFY] {OFF | ON}
Turns on|off feedback completely
The FEEDBACK setting controls whether SQL*Plus displays the number of records returned.You can set a threshold, below which you don't get any feedback regardless of whether the setting is on.
SET FEED[BACK] {OFF | ON | row_threshold}
Some Links:
set feedback off
SET FEEDBACK
SET VERIFY
Substitution variables, like your &a, are exclusively an SQL*Plus concept. The only reason SQL Developer knows what to do with it is that SQL Developer supports most of the SQL*Plus scripting language. So your "no sqlplus" requirement (in your question) is nonsensical. Any solution must be a SQL*Plus solution in one way or another.
What you are asking for is very simple. SQL*Plus supports a feature called verify, which does exactly what you don't want it to do: showing you the before and after versions of your code. By default it is on - all you need to do is to turn it off before you run your code.
Another thing is the displaying of just your value in the output. By default the serveroutput feature is off; to see the output from dbms_output.put_line() you must turn it on. It is not clear if you have done that.
So, before you run your code, you must run these two SQL*Plus commands; the first one is the one you were asking about, the second one is to see the output from put_line(). Note that both are SQL*Plus commands; they are not terminated with semicolon (although SQL Developer will not throw an error if they are).
set verify off
set serveroutput on
As an aside, SQL*Plus tolerates some syntax errors, so your code will run as written (unless it's surrounded by other code); but technically, you are missing a forward slash on a line by itself at the end of your code, to indicate the end of a PL/SQL block.
In the editor window:
set verify off
set serveroutput on
DECLARE
a NUMBER;
BEGIN
a:=&a;
DBMS_OUTPUT.PUT_LINE(a);
end;
/
Pop-up window asks for value for a; I enter the value 5 and hit the OK button
Script output (lower pane):
5
PL/SQL procedure successfully completed.
If your next question is "how do I make it so that PL/SQL procedure successfully completed does not appear in the output window" - the answer is similar:
set feedback off
(also a SQL*Plus command, understood by SQL Developer, and not terminated with a semicolon).

select more than one checkbox to execute condition

I want a text file to show contents in memo1 once I have selected 2 checkboxes.
How would I do this?
I tried the code below but I can't seem to get it right.
if CheckBox1.Checked and CheckBox2.Checked then
begin
memo1.lines.LoadFromFile('files\RS.txt');
end;
I also want to be able to select the checkboxes individually Like:
(pointing this out in case combining them prevents checking them individually)
Checkbox1:
procedure TForm1.CheckBox1Change(Sender: TObject);
begin
memo1.lines.LoadFromFile('files\R.txt');
end;
Checkbox2:
procedure TForm1.CheckBox2Change(Sender: TObject);
begin
memo1.lines.LoadFromFile('files\S.txt');
end;
Any suggestions/Improvements will be appreciated.
Running Lazarus IDE v1.6.4
Windows 10 x64
I'm assuming your objective is to generate a filename which depends on the
particular combination of the boolean states of the two checkboxes -
see example code below. The point of doing this is that it helps separate
the definition of what you want the file name to be from what you want to do
with it.
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Lines.LoadFromFile(GetFileName);
end;
function TForm1.GetFileName: String;
begin
// Return empty string if neither checkbox is checked
Result := '';
if Checkbox1.Checked and Checkbox2.Checked then
Result := 'files\RS.txt'
else // if we reach here only one of the checkboxes, or neither, is checked
if Checkbox1.Checked then
Result := 'files\R.txt'
else
if Checkbox2.Checked then
Result := 'files\S.txt'
end;
I've assigned an empty string to the Result of the function at the outset to ensure that the Result is always defined.
Important You'll notice that the above does not use the Change events of the Checkboxes. The reason is that you may not get the result you need (or are expecting) if the Change events are never triggered - for example if one CheckBox is set to Checked in the IDE but the other isn't, and you want to get the right file name regardless of whether the user has actually clicked either one of them.
As far as I understood you want the following behaviour:
There are two check boxes
There is one memo field
Depending on the state of the two check boxes the text in the memo field shall change
If this understanding is correct:
I typically don't use Pascal but your problem seems to be independent of the programming language used. I would do it like this:
The two procedures TForm1.CheckBox1Change and TForm1.CheckBox2Change are called whenever the corresponding check box'es state changes.
I would write a third procedure and call this third procedure from both procedures. I would do nothing else than calling this third procedure in the other two procedures.
In the third procedure I would evaluate what to do - depending on the state of both check boxes.
A separate checkboxchange proocedure per event is automatically generated by the designer if you double click the event. However that is not a rigid decision.
If you have the initial codefragment in e.g. checkbox1change, you can simply point the onchange of checkbox2 to that existing checkbox1change by using the dropdown of the onchange of checkbox2

Very simple procedure statement from school slide. I want to know how it works

create or replace procedure HelloWorld(s varchar)
as
begin
dbms_output.put_line(s);
end;
-------- click execute button now
exec HelloWorld('Hello');
The codes above is from the school slide. The first code is shown as 'procedure created' which means good to go. When I execute it by using 'exec HelloWorld(‘Hello’);', it shows errors. May I ask some of question regarding this code please?
1) Why it does not work when I execute it?
2) I know that 's' is a parameter, and 'varchar' is the datatype for 's'. However, the code requires that print 's'. As I can see, there is nothing to assigned on 's'. Then, how can the code runs the value of 's' in 'dbms_output.put_line(s);'?
3)Can anybody just explain what is the basic function for each single word?

First program in PL/SQL

I'm trying to learn some PL/SQL but I'm having an issue with my first program:
declare
v_string_tx varchar2(256):='Hello World!';
begin
dbms_output.put_line(v_string_tx);
end;
When I run this in SQL Developer I just get a message saying 'anonymous block completed'. However I don't get the 'Hello World!' as expected. Anyone know what I'm missing?
I've tried placing the line 'set serveroutput on' before this code but when I do that and run it all, nothing happens(I don't even get the message telling me that the anonymous block has completed).
To see your output in SQL/Developer, you'll have to do this:
go to View -> DBMS Output (this will open a new tab called "DBMS Output")
click the green + sign
choose your connection from the drop-down box (this will add a new sub-tab to "DBMS Output")
run your script

Oracle SQL Developer - Help for debugging

I am trying to debug a package with in the SQL Developer. The method that i am trying to debug takes 2 parameters
PROCEDURE procedure_name (dblink IN CHAR, bDebug IN BOOLEAN DEFAULT FALSE)
When i click on "Debug" icon, it asks for inputs that i need to give to this procedure. I give
dblink:='linkname';
bDebug:=TRUE;
but when it starts debugging, I see the value of dblink as
'linkname
'
i.e. linkname, lots of spaces and then the ending quote. so when in code i try to do this
`strSrc VARCHAR(120) := 'tablename'||dblink;`
it gives me error that buffer is to small, which makes sense. but why SQL Developer is doing so? how to fix it?
I am guessing your padding is coming from how SQL Developer is defining its variable to bind with (it is probably defining it as a CHAR(4000)). For now, you should be able to get around this in your test code by putting trim() around the dblink variable:
strSrc VARCHAR(120) := 'tablename'||trim(dblink);
Note that this would normally not be needed if the procedure was passed a literal (or a correctly sized CHAR variable, a VARCHAR, etc), like the production code is probably doing.
For debugging purposes, create a wrapper procedure that accepts a VARCHAR2 parameter, then passes it to your procedure; then you debug it in SQL Developer by calling your wrapper.

Resources