Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Parse Dynamic Nested Json in Oracle APEX

Rithu RajJul 21 2022

Hi All,
I need to parse a dynamic JSON in Apex . I have to include checkboxes in the nested Json so that the user can select some child nodes and they have to be stored back again in DB.
Eg,.
Sample Json below, (the json nodes may different)
{"Description": "Sample", "Item": "SampleItem", "Samples": "XXX", "Number": {"ItemA (s)": {"ValA": 2, "ValB": 1}, "ItemB (s)": {"ValA": 3, "ValB": 1}}, "SampleRun": ["RunA (s)", "RunB (s)"]}
I have to include checkboxes in all the nodes that ends with (s) and when user selects I have to store the value with the node details in DB table.
Either I can add checkbox while rendering Json in Apex enabling user to select checkbox and store the value back to DB
Or I can parse the Json data, create a table with key value details along with path and later construct a region with checkbox in required places.

Not sure if my approaches are right. Please assist me further.

Comments

285751
Try adding a parameter 0 before your oraParmSessionID parameter. That will give the function someplace to return its result.

OraParameter oraReturn = new OraParameter();
oraReturn.ParameterName = "justaboutanything";
oraReturn.OraDbType = OraDbType.Date;
oraReturn.Direction = ParameterDirection.ReturnValue;
oraCommand.Parameters.Add(oraReturn );




Any ideas as to what's causing the following error:
---
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Oracle.DataAccess.Client.OraException:
/---
I'm simply calling an Oracle function which returns a date. Code snippet:
---
FUNCTION func_get_session_date(v_session_id VARCHAR2, v_session_key VARCHAR2) RETURN DATE IS
...etc
/---
...employing the OraDataReader to extract the value (unnecessary code extracted for clarity):
---
DateTime returnDateTime;
string commandText = "SELECT pkg_css_session_state.func_get_session_date(:v_session_id, :v_session_key) FROM dual";
//string commandText = "SELECT pkg_css_session_state.func_get_session_date('" + this.AspxSessionID + "', '" + sessionKey + "') FROM dual";
OraConnection oraConnection = new OraConnection(connectionString);
OraCommand oraCommand = new OraCommand();
oraCommand.Connection = oraConnection;
oraCommand.CommandText = commandText;
OraParameter oraParmSessionID = new OraParameter();
oraParmSessionID.ParameterName = "v_session_id";
oraParmSessionID.OraDbType = OraDbType.Varchar2;
oraParmSessionID.Value = this.AspxSessionID;
oraParmSessionID.Direction = ParameterDirection.Input;
oraCommand.Parameters.Add(oraParmSessionID);
OraParameter oraParmSessionKey = new OraParameter();
oraParmSessionKey.ParameterName = "v_session_key";
oraParmSessionKey.OraDbType = OraDbType.Varchar2;
oraParmSessionKey.Value = sessionKey;
oraParmSessionKey.Direction = ParameterDirection.Input;
oraCommand.Parameters.Add(oraParmSessionKey);
oraConnection.Open();
OraDataReader oraDataReader = oraCommand.ExecuteReader(CommandBehavior.CloseConnection);
if (oraDataReader.Read())
{
if (! oraDataReader.IsDBNull(0))
{
returnDateTime = oraDataReader.GetDateTime(0);
}
}
/--
Interestingly, it works fine when I don't use input parameters (see commented-out commandText string).
Thanks ahead o' time!
1 - 1

Post Details

Added on Jul 21 2022
0 comments
208 views