How to parse this JSON where name has ',' - oracle

I run next example
declare
obj json := json('{"TR,A" : "OK" }');
begin
dbms_output.put_line(JSON_EXT.GET_STRING (obj, 'TR,A'));
end;
and receive a message
ORA-20110: JSON Path parse error: expected . or [ found , at position 4
ORA-06512: at "SCOTT.JSON_EXT", line 193
ORA-06512: at "SCOTT.JSON_EXT", line 201
What is the work around?

The following code works for me:
declare
my_json json := json('{"TR,A" : "OK" }');
begin
dbms_output.put_line(my_json.get('TR,A').to_char);
end;
You should work directly with the JSON type. You should only have to resort to using packages like JSON_EXT if the type methods are insufficient for your use case.

Related

how the 'tmpdata' and 'Get_Parameter_List' works in OracleForm?

I am new in OracleForms and Plsql, i found this code in a proyect:
PROCEDURE grabar IS
...
Pl_id paramlist;
...
BEGIN
pl_id := Get_Parameter_List ('tmpdata');
IF NOT Id_Null(pl_id) THEN
Destroy_Parameter_List( pl_id );
END IF;
pl_id := Create_Parameter_List('tmpdata');
i want to konw that if 'tmpdata' does not exist i will get an error?
whit the line:
pl_id := Get_Parameter_List ('tmpdata');
am i inserting the data of 'tmpdata' in 'PL_id'
it is the 'tmpdata' a default variable of Oracleforms or something?
it is not OracleForms but it is a tool based in it so is so similar
I proved to change to:
pl_id := Get_Parameter_List ('tmpdata_HELLO');
enter code hereand the program passed to of this
the console show me this:
may 25, 2018 4:46:30 PM org.apache.tomcat.util.http.Parameters processParameters
INFORMACIÓN: Character decoding failed. Parameter [value] with value [%null] has been ignored. Note that the name and value quoted here may be corrupted due to the failed decoding. Use debug level logging to see the original, non-corrupted values.
Note: further occurrences of Parameter errors will be logged at DEBUG level.
In this example, "tmpdata" is the name of a parameter list that may or may not exist. The "ID_NULL" is checking for the existence of the parameter list by checking of the ID returned has a value or not. If it has a value (ie, ID_NULL returns FALSE), then the parameter list is destroyed so that the "Create_Parameter_List" command will not get an error.
"Get_Parameter_List" will not throw an error if there is no parameter list by the given name ("tmpdata", in this case); it just returns null.

Can't remove Null terminator from byte array?

I'm using this library in Go (on OSX) to interact with a windows DNS server.
When running the below snippet, I get an error about a null terminator.
$ ~/go/bin/winrm-dns-client create -d domain.com -n node-0 -t A -v 10.90.61.30
2018/06/03 12:40:22 Error creating DNS record: Reading record: Reading record: Unmarshalling response: Unmarshalling json: invalid character '\x00' after array element
My suspicion is that there's a null terminator added here when the helper method calls sprintf to concat json responses into an array.
However, even after adding a bytes.Trim like shown below... I still get a null terminator error and it seems that the null terminator still exists...
func unmarshalResponse(resp string) ([]interface{}, error) {
var data interface{}
byteRespTrim := []byte(resp)
fmt.Print("found a null terminator at -- ")
fmt.Println(bytes.Index(byteRespTrim, []byte("\x00")))
fmt.Print("total length = ")
fmt.Println(len(byteRespTrim))
byteRespTrim = bytes.Trim(byteRespTrim, "\x00")
fmt.Print("after trim found a null terminator at -- ")
loc := bytes.Index(byteRespTrim, []byte("\x00"))
fmt.Print(loc)
When calling I get the below
(master)⚡ % ./windows-dns-test create -d domain.com -n openshift-node-0 -t A -v 10.90.61.30
found a null terminator at -- 2102
total length = 2615
after trim found a null terminator at -- 2102
From your logs, the offending character seems to be found at position 2102, while the whole array has 2615 elements.
So it looks Trim won't solve it since the problem is not necessarily the final character of the array.
Did you try removing all occurrences, using Replace for example?
byteRespTrim = bytes.Replace(byteRespTrim, []byte("\x00"), []byte{}, -1)

How to know what node is not valid with XMLTYPE

Here is the code to validate an xml file in PL_SQL using XMLTYPE
doc := dbms_xmldom.newdomdocument;
... xml file is build
v_xml:=DBMS_XMLDOM.GETXMLTYPE(doc);
v_schema:=v_xml.createSchemaBasedXML('xml.xsd');
BEGIN
v_schema.schemavalidate();
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('XML File is not valid');
END;
Is there way to know where the file is not valid, what node ?
Thank you
Note : the exception hidden that way is this one :
ORA-31154: invalid XML document
ORA-19202: Error occurred in XML processing
LSX-00333: literal "" is not valid with respect to the pattern
dbms_utility.format_error_stack is providing more error details, including LSX error messages, which gives you the type of validation error, like
dbms_output.put_line( dbms_utility.format_error_stack);
ORA-31154: invalid XML document
ORA-19202: Error occurred in XML processing
LSX-00220: "" is wrong length, should be 12
ORA-06512: at "SYS.XMLTYPE", line 354

How to show only error message oracle raise application error

I am writing oracle triggers and i have some error messages.
I use this code for handling error:
raise_application_error(-20001, 'error message, please do not this');
But this shows very lot info;
For example:
ora-20001: <<custom message>>.
ora-06512: at <<package.procedure_name>>, line 100
I want only show error message body: "error message, please do not this"
Is there a way to do this?
Since I found this question pretty high in my Google search, here is a simple method to just get the error message:
declare
procedure test is
begin
raise_application_error(-20222, 'This is an error');
end test;
begin
test;
exception
when others then
dbms_output.put_line(replace(sqlerrm, 'ORA' || sqlcode || ': ', ''));
end;
Will output:
This is an error
DBMS_OUTPUT.PUT_LINE(REGEXP_REPLACE(SQLERRM, '^ORA-[0-9]+: ', ''));
You can use the SQLERRM function, which will return the exception number and the message, without the lines. There's no function for returning only the text, but you can use SQLCODE function to do that like the second example in this article.
Just remember that this data is mainly intended to help you to cope with unexpected situations in debugging, logging, etc., so most of the time you should consider writing all of the exception info to your log.

How to create a user defined function in sybase?

I trying to define a function in sybase. I write this script:
CREATE FUNCTION GetUserGroup (userId int)
RETURNS int
BEGIN
RETURN (10)
END
but when I run this, I get this error:
>[Error] Script lines: 1-6 --------------------------
Incorrect syntax near the keyword 'BEGIN'.
Msg: 156, Level: 15, State: 2
Server: NEWSERVER, Procedure: GetUserGroup, Line: 3
>[Error] Script lines: 1-6 --------------------------
A RETURN statement with a return status may only be used in a SQL stored procedure.
Msg: 178, Level: 15, State: 1
Server: NEWSERVER, Procedure: GetUserGroup, Line: 4
[Executed: 10/13/09 11:01:29 AM IRST ] [Execution: 0/ms]
What can I do?
Thanks
I searched very much in web and other documents, I find that user-defined functions in Adaptive Server Enterprise 12 (ASE) must be implemented in Java.
I decided to use a StordProcedure. It usage is a little hard but it supported in all version of Sybase.
see: http://www.sypron.nl/udf.html
I doesn't find any thing wrong with the code. you can re-try with the code below-
CREATE FUNCTION GetUserGroup (userId int)
RETURNS int
As
BEGIN
RETURN (10)
END
Try This ....it will work
CREATE FUNCTION GetUserGroup (#userId int)
RETURNS int
As
BEGIN
declare #Result int
select #Result=10
RETURN #Result
END
this worked for me.
CREATE FUNCTION GetUserGroup (#userId int)
RETURNS int
AS
BEGIN
select #userId = 10
RETURN #userId
END

Resources