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!

Can I use a WITH() closure in a procedure?

I have a script that I run in Oracle Database 19c 19.0.0.0.0.0.0, and I use two date parameters from - to in a WITH() closure then depending on what it returns it does the INSERT to a table, then I wonder if it is possible to use my SQL statement in a procedure for this case, it is for an orchestrator that does not allow the SQL statement because of the number of lines, since it exceeds the maximum and I have to use a procedure.
It is the first time that I am going to use a procedure and I did not find information if I can use a with() closure and the parameters in a procedure, thank you.

I attach the SQL statement that I execute, thank you for your attention
SQL Insert F59INVEN.txt (11.26 KB)

This post has been answered by Frank Kulash on Oct 27 2021
Jump to Answer

Comments

mNem

Works fine for me.

public static void main(String[] args)

  { 

    String str = "asffass".replaceAll("", "");

    System.out.print(str);

  }

unknown-7404

but it did not work?

If you want help with code you have to POST THE CODE.

Standard Java exceptions NEVER say 'did not work' - they ALWAYS provide an exception number and message.

3513491

Exception :unmmaped charachter

private List<Card> ankiConvert(File ankiLesson) throws UnsupportedEncodingException{

        int i=1;

        List<Card> notes=new ArrayList();

         Connection conn = null;

         Statement query=null;

        try {

            // db parameters

            String url = "jdbc:sqlite:"+ankiLesson.getAbsolutePath();

            // create a connection to the database

            try{

            conn = DriverManager.getConnection(url);

            }catch(Exception e){

            System.out.println("Connection to SQLite has been established.");

            }

            query=conn.createStatement();

            String sql="SELECT flds,sfld FROM 'notes'";

            ResultSet rs=query.executeQuery(sql);

            while(rs.next()){

               

                org.jsoup.nodes.Document doc =  Jsoup.parse(rs.getString("flds"));

                org.jsoup.nodes.Document doc1 =  Jsoup.parse(rs.getString("sfld"));

                String front=doc1.text();

                String back=doc.text().replaceAll("&#31;","").replace(front,"");

                String image=doc.getElementsByTag("img").attr("src");

                Card card=new Card();

                card.setId(String.valueOf(i));

                card.setFrontside(front.trim().replaceAll("(\\[)(.*)|(\\()(.*)|(\\{)(.*)",""));

                card.setBackside(back.trim().replaceFirst("(/.*/)",""));

                card.setLevel("0");

                card.setTesthit("0");

                card.setChapter("All");

                if(image!=null){

                card.setImg(image);

                }

                notes.add(card);

                i++;

            }

            rs.close();

        } catch (SQLException e) {

            System.out.println(e.getMessage());

        } finally {

            try {

                if (conn != null) {

                    conn.close();

                }

            } catch (SQLException ex) {

                System.out.println(ex.getMessage());

            }

        }

        return notes;

    }

mNem

It is difficult to identify which line is throwing exception.... when we do not have access to your 3rd party libraries.

Exception :unmmaped charachter

May be it is useful to identify the issue, if you could paste the full exception trace.

One more thing, IMHO, it is always pays to write readable code when it comes to maintainable code.

Normally, I avoid chaining method calls.

String back=doc.text().replaceAll("&#31;","").replace(front,"");

instead,

String back = doc.text();

back = back.replaceAll(.....); // side note: this could throw NPE if back is null.

back = back.replace(....);

This allows me to step over line by line using the debugger and identify what is being returned when troubleshooting.

unknown-7404

I think you missed reading this part of what I said:

Standard Java exceptions NEVER say 'did not work' - they ALWAYS provide an exception number and message.

The code you posted pretty much says you do NOT care about what exceptions may occur - and that processing should just continue no matter what happens:

try{

            conn = DriverManager.getConnection(url);

            }catch(Exception e){

            System.out.println("Connection to SQLite has been established.");

            }

            query=conn.createStatement();

Really?

Even if 'getConnection' raises an exception you just want to go ahead and try to create a statement and continue processing the rest of the code?

You should ONLY capture exceptions if you plan to handle them.

You code has multiple exception blocks and NONE OF THEM actually handle an exception.

  } catch (SQLException e) {

            System.out.println(e.getMessage());

        } finally {

            try {

                if (conn != null) {

                    conn.close();

                }

            } catch (SQLException ex) {

                System.out.println(ex.getMessage());

            }

        }

Get rid of ALL of those exception handlers so you can see the actual exceptions that occur and get the information Java provides about exactly WHERE they occur.

Post the actual stack trace that Java provides - it will show the FULL list of events that are happening.

Then start troubleshooting your problem by examining EVERY STEP of the code so you can see what it does

Don't underestimate the importance of what mNem said:

String back=doc.text().replaceAll("&#31;","").replace(front,"");

That contains THREE different statements jammed together on one line. That makes it difficult to know which of them, if any, are causing an exception.

If that one line causes a problem it could be the '.replace', the 'replaceAll' or even the 'doc.text()'. Either the 'doc' or the 'front' could be null or problematic.

Write SIMPLE code so you know what the code does. Then you can worry about taking shortcuts and trying to write complex, single-line statements.

Then if you still have trouble identifying the actual line with a problem add a try .. except block around every line until you find the one throwing the exception.

Then examine EACH AND EVERY variable using a debugger (e.g. NetBeans) to make sure they have the value you expect.

Until you remove those garbage exception handlers and post the actual exception stack trace (printStackTrace) we can't really help.

1 - 5

Post Details

Added on Oct 27 2021
3 comments
238 views