1. <small id='gzi7t'></small><noframes id='gzi7t'>

      <i id='gzi7t'><tr id='gzi7t'><dt id='gzi7t'><q id='gzi7t'><span id='gzi7t'><b id='gzi7t'><form id='gzi7t'><ins id='gzi7t'></ins><ul id='gzi7t'></ul><sub id='gzi7t'></sub></form><legend id='gzi7t'></legend><bdo id='gzi7t'><pre id='gzi7t'><center id='gzi7t'></center></pre></bdo></b><th id='gzi7t'></th></span></q></dt></tr></i><div id='gzi7t'><tfoot id='gzi7t'></tfoot><dl id='gzi7t'><fieldset id='gzi7t'></fieldset></dl></div>
    2. <legend id='gzi7t'><style id='gzi7t'><dir id='gzi7t'><q id='gzi7t'></q></dir></style></legend>

        <bdo id='gzi7t'></bdo><ul id='gzi7t'></ul>
    3. <tfoot id='gzi7t'></tfoot>
    4. 如何加载大量字符串与oracle数据库匹配?

      How to load a large number of strings to match with oracle database?(如何加载大量字符串与oracle数据库匹配?)
      • <bdo id='QYESR'></bdo><ul id='QYESR'></ul>

        <small id='QYESR'></small><noframes id='QYESR'>

        <tfoot id='QYESR'></tfoot>

        • <i id='QYESR'><tr id='QYESR'><dt id='QYESR'><q id='QYESR'><span id='QYESR'><b id='QYESR'><form id='QYESR'><ins id='QYESR'></ins><ul id='QYESR'></ul><sub id='QYESR'></sub></form><legend id='QYESR'></legend><bdo id='QYESR'><pre id='QYESR'><center id='QYESR'></center></pre></bdo></b><th id='QYESR'></th></span></q></dt></tr></i><div id='QYESR'><tfoot id='QYESR'></tfoot><dl id='QYESR'><fieldset id='QYESR'></fieldset></dl></div>

              <legend id='QYESR'><style id='QYESR'><dir id='QYESR'><q id='QYESR'></q></dir></style></legend>
                  <tbody id='QYESR'></tbody>
                本文介绍了如何加载大量字符串与oracle数据库匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我目前正在学习 PL/SQL,所以我还是一个新手.假设您有一个生产数据库,您使用 Oracle SQL Developer 连接到该数据库.您只有对该数据库的读取权限.因此您不能创建或编辑任何表.

                I am currently learning PL/SQL so i am still a newbie. Assume that you have a production database, which you connect to using Oracle SQL developer. You have ONLY READ privilges to that databases. Therefore you cannot create or edit any tables.

                我的问题是,如果我有一个很大的 ID 列表,我必须将这些 ID 与该数据库中的一个表连接起来,我该怎么做?

                My question is, if i have a big list of IDs, which i have to join with a table in that database, how can i do that?

                显然,我可以将 ID 加载到临时表上,然后进行连接,但这会非常乏味,因为我只有 READ 权限.硬编码 ID 也不是一种选择,因为列表太大.

                Obviously, I can load the IDs onto a temporary table and then do a join, but that would be really tedious as i have only READ privileges. Hardcoding the IDs is not an option also, because the list is too big.

                还要注意的是,我知道临时表的概念.但不幸的是,我也没有创建这些的权限.

                And also note that, i know the concept of TEMPORARY tables. But unfortunately, i also don't have privileges to create those.

                SQL 开发人员是否有任何解决方案可以加载 ID 列表以与数据库中的表匹配?

                Is there any solution in SQL developer where i can load the list of IDs, to match with the table in the database?

                推荐答案

                使用集合

                VARIABLE cursor REFCURSOR;
                
                DECLARE
                  your_collection SYS.ODCIVARCHAR2LIST := SYS.ODCIVARCHAR2LIST();
                BEGIN
                  your_collection.EXTEND( 10000 );
                
                  FOR i IN 1 .. 10000 LOOP
                    -- Populate the collection.
                    your_collection(i) := DBMS_RANDOM.STRING( 'x', 20 );
                  END LOOP;
                
                  OPEN :cursor FOR
                  SELECT t.*
                  FROM   your_table t
                         INNER JOIN
                         TABLE( your_collection ) c
                         ON t.id = c.COLUMN_VALUE;
                END;
                /
                
                PRINT cursor;
                

                或者通过java做同样的事情:

                Or doing the same thing via java:

                import java.sql.Connection;
                import java.sql.DriverManager;
                import java.sql.PreparedStatement;
                import java.sql.ResultSet;
                import java.sql.SQLException;
                import oracle.jdbc.OraclePreparedStatement;
                import oracle.sql.ARRAY;
                import oracle.sql.ArrayDescriptor;
                
                public class TestDatabase2 {
                    public static void main(String args[]){
                        try{
                            Class.forName("oracle.jdbc.OracleDriver");
                
                            Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","username","password");
                
                            String[] ids = { "1", "2", "3" };
                
                            ArrayDescriptor des = ArrayDescriptor.createDescriptor("SYS.ODCIVARCHAR2LIST", con);
                
                            PreparedStatement st = con.prepareStatement("SELECT t.* FROM your_table t INNER JOIN TABLE( :your_collection ) c ON t.id = c.COLUMN_VALUE");
                
                            // Passing an array to the procedure - 
                            ((OraclePreparedStatement) st).setARRAYAtName( "your_collection", new ARRAY( des, con, ids ) );
                            ResultSet cursor = st.executeQuery();
                
                            while ( cursor.next() )
                            {
                                int id = cursor.getInt(1);
                                double column1 = cursor.getDouble(2);
                                double column2 = cursor.getDouble(3);
                
                                System.out.println( String.format( "Id: %5d", id ) );
                                System.out.println( String.format( "  Column1: %s", column1 ) );
                                System.out.println( String.format( "  Column2: %s", column2 ) );
                            }
                        } catch(ClassNotFoundException | SQLException e) {
                            System.out.println(e);
                        }
                    }
                }
                

                这篇关于如何加载大量字符串与oracle数据库匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Select n random rows from SQL Server table(从 SQL Server 表中随机选择 n 行)
                SQL query to select dates between two dates(用于选择两个日期之间的日期的 SQL 查询)
                How can I delete using INNER JOIN with SQL Server?(如何在 SQL Server 中使用 INNER JOIN 进行删除?)
                Table Naming Dilemma: Singular vs. Plural Names(表命名困境:单数与复数名称)
                INSERT statement conflicted with the FOREIGN KEY constraint - SQL Server(INSERT 语句与 FOREIGN KEY 约束冲突 - SQL Server)
                How ROWNUM works in pagination query?(ROWNUM 如何在分页查询中工作?)

                • <tfoot id='5tI3p'></tfoot>

                  <legend id='5tI3p'><style id='5tI3p'><dir id='5tI3p'><q id='5tI3p'></q></dir></style></legend>
                • <small id='5tI3p'></small><noframes id='5tI3p'>

                    <tbody id='5tI3p'></tbody>
                  • <bdo id='5tI3p'></bdo><ul id='5tI3p'></ul>

                      • <i id='5tI3p'><tr id='5tI3p'><dt id='5tI3p'><q id='5tI3p'><span id='5tI3p'><b id='5tI3p'><form id='5tI3p'><ins id='5tI3p'></ins><ul id='5tI3p'></ul><sub id='5tI3p'></sub></form><legend id='5tI3p'></legend><bdo id='5tI3p'><pre id='5tI3p'><center id='5tI3p'></center></pre></bdo></b><th id='5tI3p'></th></span></q></dt></tr></i><div id='5tI3p'><tfoot id='5tI3p'></tfoot><dl id='5tI3p'><fieldset id='5tI3p'></fieldset></dl></div>