Throwing error while printing record element string using put why please help me to understand?
with ada.text_io;
use ada.text_io;
procedure main is
type my_rec is record
name:string(1..5)of integer;
end record;
var:my_rec;
begin
var.name:="hello";
put(var.name); -- why error?
end main;
error message is below
cc -c hello.adb
hello.adb:7:27: missing ";"
gnatmake: "main.adb" compilation error
hello.adb:7:27 is the coordinates of the error, so take a look in "hello.adb" on line 7 at character position 27.
Related
I have a pl/sql procedure that that downloads a blob file in pdf format from Jasper Server. In this procedure I have the following code which prompts the browser to download the file to my local drive.
begin
v_param_val (1) := 1;
owa.init_cgi_env (v_param_val);
htp.flush;
-- clear the output buffer and reset response state
htp.init;
owa_util.mime_header ('application/pdf', false);--,'UTF-8'
htp.p('Content-length: ' || v_lob_length);
htp.p('Content-Disposition: attachement; filename="'||v_file||'"' );
owa_util.http_header_close;
htp.showpage ();
wpg_docload.download_file(v_blobref);
exception
when timeout_on_resource then
raise_application_error (-00051,'No response from the server.');
when others then
htp.p('other error : ' || sqlerrm);
end;
The problem is, I have an oracle apex page that I use to call my procedure. The page passes through the values to be used as parameters in the call of the procedure. I have a an apex process that makes this happen...
declare
v_report_name reports_data.report_name%type;
begin
v_report_name := s_reports_data.get_report_name(:P31_AVAILABLE_REPORTS);
s_reports_data.generate_jasper_report(v_report_name, :P31_DATE_TO,
:P31_RESEARCH_STATION, :P31_DATE_FROM);
end;
No the following error comes up when I try to call the procedure.
An unexpected error with the following message occurred: application/pdf
It seems like the following line is the cause of the error.
owa_util.mime_header ('application/pdf', false);--,'UTF-8'
Or the following line.
wpg_docload.download_file(v_blobref);
Looking in the docs, the function seems to need 3 parameters. Have you tried
owa_util.mime_header('application/pdf', false, 'UTF-8')
I finally got rid of the problem I had. This is how my code looks like now and it works perfectly fine.
begin
sys.htp.init;
sys.owa_util.mime_header (nvl(v_mime,'application/octet'), false, 'UTF-8');
sys.htp.p('Content-length: ' || v_lob_length);
sys.htp.p('Content-Disposition: attachement; filename="'||v_file||'"' );
sys.owa_util.http_header_close;
sys.wpg_docload.download_file(v_blobref);
apex_application.stop_apex_engine;
exception when others then
sys.htp.prn('error: '||sqlerrm);
apex_application.stop_apex_engine;
end;
HI everyone I wrote a kind of a simple procedure in Aginity(Netezza). The stored procedure basically has to load data from one db.table1 to db2.table2. Simple right? Then then the procedure - procedure 1 takes in an argument, which is the name of the database(db).
This is the error message I get whenever I try to run my procedure:
/*
ERROR [HY000] ERROR: syntax error, unexpected VARIABLE, expecting BEGIN at or near "db_arg"
*/
The procedure looks like something like this:
CREATE OR REPLACE PROCEDURE LOAD_data_proc(CHARACTER VARYING(15))
RETURNS INTEGER
LANGUAGE NZPLSQL AS
BEGIN_PROC
DECLARE
db_arg CHARACTER VARYING(15);
/* if I remove above declaration I get the following error message: ERROR [HY000] ERROR: ResolveCatalog: error retrieving database 'STG_DB_NAME' */
db_arg ALIAS FOR $1;
/* and bunch of other arguments and declarations */
BEGIN
/* logic here if then else statements */
END;
END_PROC;
Did anyone encounter this problem before?
It's not 100% clear from your description what the actual NZPLSQL code is, but I can reproduce your first error using:
CREATE OR REPLACE PROCEDURE LOAD_DATA_PROC(CHARACTER VARYING(15))
RETURNS INTEGER
LANGUAGE NZPLSQL AS
BEGIN_PROC
DECLARE
db_arg CHARACTER VARYING(15);
db_arg alias for $1;
BEGIN
db_arg := 'SYSTEM';
RAISE NOTICE '%', db_arg;
RETURN 0;
END;
END_PROC;
Note there is a double declaration of the same variable name in the DECLARE block. This is not allowed, and this causes:
ERROR [HY000] ERROR: syntax error, unexpected VARIABLE, expecting BEGIN at or near "db_arg"
Removing one of the declarations will allow the procedure to complete.
IBM docs on NZPLSQL regarding parameter passing to stored procedures is available here: https://www.ibm.com/support/knowledgecenter/SSULQD_7.2.0/com.ibm.nz.sproc.doc/c_sproc_parameter_passing.html
and here:
https://www.ibm.com/support/knowledgecenter/SSULQD_7.2.0/com.ibm.nz.sproc.doc/c_sproc_arg_list.html
As for:
ERROR [HY000] ERROR: ResolveCatalog: error retrieving database 'STG_DB_NAME'
This occurs when I attempt to call a non-existent stored procedure, in a non-existent schema of a non-existent database such as:
CREATE OR REPLACE PROCEDURE LOAD_DATA_PROC(CHARACTER VARYING(15))
RETURNS INTEGER
LANGUAGE NZPLSQL AS
BEGIN_PROC
DECLARE
db_arg alias for $1;
BEGIN
CALL UNKNOWNDB.UNKNOWN_SCHEMA.UNKNOWN_STORED_PROC(1234,5678,7890,123456,1234567);
END;
END_PROC;
which gives me:
ERROR [HY000] ERROR: ResolveCatalog: error retrieving database 'UNKNOWNDB'
Hopefully this helps to explain the errors and how to avoid them.
ok I figured it out... you can pass db_names as arguments to the netezza stored procedure but every time you use the argument inside the procedure, you have to use a dynamic query...
Hope this helps somebody, someday.
While executing scripts in SQLPlus I've encountered a problem:
script.sql contains the following lines
#some_pkg.pks
#some_pkg.pkb
drop package some_pkg;
/
After calling
> sqlplus user/password#dbname #script.sql
the following messages are in console:
Package created.
Package body created.
Package dropped.
drop package some_pkg;
*
ERROR at line 1:
ORA-04043: object SOME_PKG does not exist
Please, explain what's happening here. Looks like the package is being dropped twice. Is it possible to avoid the error?
The rules of SQLplus command execution basically are:
Execute the current text when you encounter a semi-colon. Thus if a line doesn't end with a semi-colon, the current text continues to be collected.
If you encounter DECLARE or BEGIN, collect all the text and do not execute on semi-colons
If you encounter a slash (/), execute the collected text.
So what happens in your cases is, that both the semi-colon and the slash execute the DROP statements.
To fix it, remove the slash.
You only need the slash if you have a block of PL/SQL, which always with an END statement. Use semicolons for everything else.
Note: the above rules are simplified. It's more complex in practice.
Some examples will help to understand rules:
Below code will be executed once
begin
dbms_output.put_line('executed');
end;
/
Below code will not execute (missing semicolon)
begin
dbms_output.put_line('executed')
end
/
Below code will be executed twice
begin
dbms_output.put_line('executed');
end;
/
/
Below code will be executed once
select 1 from dual
/
Below code will be executed once
select 1 from dual;
Below code will be executed twice
select 1 from dual;
/
I am having some trouble reading input in from a file. So what I have done is made a proof of concept program, which is a piece of my main program that does much more but I am only having trouble reading the input.
Here is my proof of concept program:
WITH Ada.Text_IO; USE Ada.Text_IO;
with ada.Integer_Text_IO; use ada.Integer_Text_IO;
PROCEDURE Open_File IS
subtype idnum is string(1 ..7);
-- Make short names so that we can show where things come from
My_File : File_Type; -- Name for file in this program
Os_Name : String := "My_Data.txt"; -- OS name for the file
N : idnum; -- Temporary for reading and printing file contents
EOL : boolean;
C : character;
BEGIN
-- Open will raise an ADA.IO_EXCEPTIONS.NAME_ERROR expection
-- if the file does not exist.
Open (File => My_File, Mode => In_File, Name => Os_Name);
LOOP
EXIT WHEN End_Of_File (My_File);
Look_Ahead(My_File, C, EOL);
IF EOL THEN
Skip_Line;
ELSE
IF C = ' ' THEN
Get(My_File, C);
ELSE
Get (My_File, N);
Put_Line(N);
END IF;
END IF;
END LOOP;
Close (My_File);
END open_file;
My data file looks like this: (including the spaces with no new lines after the last id)
1234567
456784a
6758abc
When I compile and run my program only the first id number gets printed to the screen. I have no clue where to check my code because it should continue to get id numbers until the end of the file.
Any help would be greatly appreciated. Thanks!
When you Get the second (and third, for that matter) line, Data_Error exception will be raised, because 456784a is not a number, 'a' is not a numeric character. If you want it to be a hexadecimal number, the input should be 16#456784a# (by default).
I've got a PL/SQL-Block which looks like this:
declare
L_Count number := 10;
begin
if L_Count > 0then
dbms_output.put_line('l_Count > 0');
else
dbms_output.put_line('l_Count <= 0');
end if;
exception
when others then
dbms_output.put_line('exception occurred');
end;
Note the fourth line containing 0then instead of 0 then.
Using PL/SQL-Developer, I can execute this block as an SQL statement, which actually outputs l_Count > 0. Using a "Program Window" and compiling this, PL/SQL-Developer says the following error:
Unable to perform operation due to errors in source code
How can this statement execute but not compile?
Thank you for your hints!
The behavior is not what I would expect either. However, both the PL/SQL Developer SQL Window and Command Window modes execute this consistently with how SQL*Plus behaves. So, this is either:
Not a bug, or
An Oracle bug but not an Allround Automations bug.
Execution and compilation are two separate things. The code block is an anonynous block and it cannot be compiled. However you can execute the block. Execution would show you l_Count > 0.
Thanks,
Aditya