pljson_util_pkg sql_to_json doesn't work if values are less than 1 - pljson

I have a problem with pljson_util_pkg.sql_to_json
declare
-- Local variables here
tstjson_list pljson_list;
l_Result_json_clob clob;
begin
-- Test statements here
tstjson_list := pljson_list();
dbms_lob.createtemporary(l_Result_json_clob, true);
tstjson_list := pljson_util_pkg.sql_to_json('SELECT 0.1 as tmp from dual');
tstjson_list.to_clob(l_Result_json_clob);
end;
When I execute this code I am getting error message:
Scanner problem with the following input: {"ROWSET":{"ROW":{"TMP":.1}}}
It looks like that if value is less than 1, then this error occurs because instead of 0.1 the result is .1!
Any idea why?
Thank you,
Zoran

Already closed, sorry
I think the reason is how oracle handle numbers in xml...
If you try this:
select xmlelement("tmp",0.1) from dual
you're going to receive the same result...
So, in order to achieve your gol just format the number via to_char function:
select xmlelement("tmp",to_char(0.1,'FM0.00')) from dual
Bye
Nicola

Related

SQR - how to use FROM [dynamic table name} within BEGIN-SELECT?

I have to create an SQR that generates a list of EEIDs, if there were any changes to the Pension data in the past day. The SQR compiles and works perfectly when I hardcode in the table names.
However, when I tried using variables for the table names, I get a compile error
I've pasted the portion of SQR that I'm trying to fix
When I start using $tableName and $auditTableName as table variables, that's when I get the error and I'm not sure what is going wrong
Can anyone help?
Please and Thank You
!***************************
begin-procedure Process-Main
!***************************
let $tableName = 'PS_PENSION_PLAN'
let $auditTableName = 'PS_AUDIT_PENSION_PLN'
let $dummy-dyn-variable = ''
begin-SELECT DISTINCT
L.EMPLID
L.EMPL_RCD
do someProcName(&L.EMPLID, &L.EMPL_RCD)
FROM [$dummy-dyn-variable]
(
SELECT DISTINCT
PP.EMPLID,
PP.EMPL_RCD,
PP.EFFDT,
'1901-01-01 12:00:00' AS AUDIT_STAMP
FROM [$dummy-dyn-variable] [$tableName] PP
UNION
SELECT DISTINCT
A.EMPLID,
A.EMPL_RCD,
A.EFFDT,
A.AUDIT_STAMP
FROM [$dummy-dyn-variable] [$auditTableName] A
)L
WHERE DATEDIFF(DAY,CAST(L.AUDIT_STAMP AS DATE),SYSDATE) = 1
ORDER BY 1,2
end-SELECT
end-procedure
Edit:
does the UNION have anything to do with this?
I keep receiving is this error:
(SQR 5528) ODBC SQL dbdesc: SQLNumResultCols error 102 in cursor 1:
[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'FROM'.
(SQR 5528) ODBC SQL dbdesc: SQLNumResultCols error 8180 in cursor 1:
[Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.
Edit2:
Ok, initial problem solved with [$dummy-dyn-variable], which led to the next problem with the DO command. I've updated the code above with DO someProcName(param_a, param_b)
I am now getting an error saying:
(SQR 2002) DO arguments do not match procedure's
Weird part, if I remove the dynamic table variables and hardcode the table names in the FROM section, then it compiles properly without errors. This makes me believe that the error is not related to my someProcName (maybe?)
am I missing something here?

What is causing the syntax error in my sql stored procedure?

I'm pretty new at stored procedures and I get the following syntax error in my code:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DELIMITER //CREATE PROCEDURE sp_create_probe(IN matrix_id INT, IN oligo_id IN...' at line 2
Here's the code for my procedure:
DELIMITER //
CREATE PROCEDURE sp_create_probe(IN matrix_id INT, IN oligo_id INT)
BEGIN
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO Probes (oligo, microarray) VALUES (oligo_id, matrix_id);
SET FOREIGN_KEY_CHECKS=1;
END //
DELIMITER ;
Hope someone can help me out
EDIT:
Well I ended up fixing it. Classic noob mistake.
I had this line before the code you see above:
DROP PROCEDURE IF EXISTS sp_create_probe
Didn't copy that line into the post for some reason but it's missing the ";" at the end. That fixed it.

How to write a program to print the wishes based on the sys time?

In PL/SQL Block, I would like to print the 'Good Morning','Good Noon','Good Eve' based on the system time that I have given as input.
If the time is 6 AM to 12 PM then it has to print GOOD MORNING
else if
it lies between 12 PM to 2 PM
it has to print GOOD NOON
else if it has to print GOOD EVE. So anybody can give me the Idea?
Advance Thanks for everyone who gives me the guidance.
I think, you know how the anonymous block looks like (reminder below):
DECLARE
-- variables' / constants' / types' / etc. declarations
BEGIN
-- logic
END;
/
You can create DATE variables or constants as follows:
l_in_date <CONSTANT> DATE := TO_DATE(<date>,<date_mask>);
Then you can use IF..THEN statement and print out the result according to the conditions (http://www.techonthenet.com/oracle/loops/if_then.php):
IF <condition> THEN
-- logic
ELSIF <condition> THEN
-- logic
ELSE
-- logic
END IF;
I believe, you should be able to create your anonymous block easily using the information above.
You could make a procedure or function that looks what time it is from the 24 hour format.
SELECT TO_CHAR(SYSDATE, HH24:MI:SS') INTO sysDate FROM dual;
Here sysDate is the current time in 24 hour format.
Then look if a time is within a certain timespan.

Im getting an Warning: Procedure created with compilation errors

I'm beginner of pl/sql and I'm learning.
This is my table.
select * from s;
SLNO ENAME SAL
------ -------------------- ----------
1 Shiv 8000
2 Pankaj 9000
3 Prasath 10000
This is my procedure:
set serveroutput on
create or replace procedure p1(n number)
is wname varchar(20);
begin
select ename into wname from s where eid=n;
dbms_output.put_line('------');
dbms_output.put_line('employee name:='||wname);
dbms_output.put_line('------');
end;
I'm getting a warning:
Procedure created with compilation errors.
If I execute the above query. Can anyone please suggest where I'm going wrong please..
You can use the following command.
show errors procedure procedure_name;
to get the list of errors and check that.
There is no column named EID on your table S.
put parameter type IN.
Give procedure like create or replace procedure p1(n IN s.eid%TYPE)
It will work.
I think there's a typo in your program,
try
SET SETVEROUTPUT ON
all in capitals.

Accessing Bind Variable in PL/SQL

I am trying to run a program in the Oracle express edition editor. When I execute the program, I get an error
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
Can anyone help me understand why I am getting an error and how to fix the code?
VARIABLE gvn_total_salary NUMBER;
DECLARE
vn_base_salary NUMBER := 3000;
vn_bonus NUMBER := 1000;
BEGIN
:gvn_total_salary := vn_base_salary + vn_bonus;
END;
The output I'm getting
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
Run By SYSTEM
Parsing Schema SYSTEM
Script Started Thursday, April 26, 2012
3 seconds ago
Elapsed time 0.01 seconds
Statements Processed 1
Successful 0
With Errors 1
With the declaration of the bind variable, that code works fine for me in SQL*Plus
SQL> VARIABLE gvn_total_salary NUMBER;
SQL> DECLARE
2 vn_base_salary NUMBER := 3000;
3 vn_bonus NUMBER := 1000;
4 BEGIN
5 :gvn_total_salary := vn_base_salary + vn_bonus;
6 END;
7 /
PL/SQL procedure successfully completed.
SQL> print gvn_total_salary
GVN_TOTAL_SALARY
----------------
4000
Can you connect to the database using SQL*Plus and run the same thing?
What are you actually trying to accomplish? This script won't execute in sqlplus or Oracle Developer or any PL/SQL execution environment I can think of. In fact, I don't understand how you are passing the bind variable :gvn_total_salary and how you can get the error you are describing. You should get something like "bind variable gvn_total_salary" not declared.

Resources