inserting rows using pl sql

Hi all

I created a tabale to insert a number

create the table loc_number (c1 number);

now, I want to insert 10 lines in this table using pl sql.

How can I do so using pl sql?

Hello

Yes it is possible.

Why use loops here?

(I guess, you need to practice this goal)

begin

 for i in 1..10
 loop

   insert into loc_number
       values (i);

 end loop;

 commit;

end;

Tags: Database

Similar Questions

  • RESTful service cannot insert data using PL/SQL.

    Hi all
    Spin: stand-alone 2.01 AL on OEL 4.8 in box a. VM
    Database Oracle 10.2.0.4 with Apex 4.2.0.00.27 on OEL4.8 in the VM B box.

    Measure of oracle.example.hr performed without problem Restful services.

    Cannot insert data using AL 2.0.1 but works on 1.1.4 AL.
    who uses the following table (under scheme: scott):
     
    create table json_demo ( title varchar2(20), description varchar2(1000) ); 
    grant all on json_demo to apex_public_user; 
    and procedure (scott diagram) below:
    CREATE OR REPLACE
    PROCEDURE post(
        p_url     IN VARCHAR2,
        p_message IN VARCHAR2,
        p_response OUT VARCHAR2)
    IS
      l_end_loop BOOLEAN := false;
      l_http_req utl_http.req;
      l_http_resp utl_http.resp;
      l_buffer CLOB;
      l_data       VARCHAR2(20000);  
      C_USER_AGENT CONSTANT VARCHAR2(4000) := 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)';
    BEGIN
      -- source: http://awads.net/wp/2005/11/30/http-post-from-inside-oracle/
      -- Ask UTL_HTTP not to raise an exception for 4xx and 5xx status codes,
      -- rather than just returning the text of the error page.
      utl_http.set_response_error_check(false);
      -- Begin the post request
      l_http_req := utl_http.begin_request (p_url, 'POST', utl_http.HTTP_VERSION_1_1);
      -- Set the HTTP request headers
      utl_http.set_header(l_http_req, 'User-Agent', C_USER_AGENT);
      utl_http.set_header(l_http_req, 'content-type', 'application/json;charset=UTF-8');
      utl_http.set_header(l_http_req, 'content-length', LENGTH(p_message));
      -- Write the data to the body of the HTTP request
      utl_http.write_text(l_http_req, p_message);
      -- Process the request and get the response.
      l_http_resp := utl_http.get_response (l_http_req);
      dbms_output.put_line ('status code: ' || l_http_resp.status_code);
      dbms_output.put_line ('reason phrase: ' || l_http_resp.reason_phrase);
      LOOP
        EXIT
      WHEN l_end_loop;
        BEGIN
          utl_http.read_line(l_http_resp, l_buffer, true);
          IF(l_buffer IS NOT NULL AND (LENGTH(l_buffer)>0)) THEN
            l_data    := l_data||l_buffer;
          END IF;
        EXCEPTION
        WHEN utl_http.end_of_body THEN
          l_end_loop := true;
        END;
      END LOOP;
      dbms_output.put_line(l_data);
      p_response:= l_data;
      -- Look for client-side error and report it.
      IF (l_http_resp.status_code >= 400) AND (l_http_resp.status_code <= 499) THEN
        dbms_output.put_line('Check the URL.');
        utl_http.end_response(l_http_resp);
        -- Look for server-side error and report it.
      elsif (l_http_resp.status_code >= 500) AND (l_http_resp.status_code <= 599) THEN
        dbms_output.put_line('Check if the Web site is up.');
        utl_http.end_response(l_http_resp);
        RETURN;
      END IF;
      utl_http.end_response (l_http_resp);
    EXCEPTION
    WHEN OTHERS THEN
      dbms_output.put_line (sqlerrm);
      raise;
    END;
    and execution in sqldeveloper 3.2.20.09 when it connects directly to box B as scott:
     
    SET serveroutput ON
    DECLARE
      l_url      VARCHAR2(200)   :='http://MY_IP:8585/apex/demo';
      l_json     VARCHAR2(20000) := '{"title":"thetitle","description":"thedescription"}';
      l_response VARCHAR2(30000);
    BEGIN
      post( p_url => l_url, p_message =>l_json, p_response => l_response);
    END;
    leading to:
     
    anonymous block completed 
    status code: 200
    reason phrase: OK 
    with data inserted. 
    Installation using 2.0.1
       Workspace : wsdemo
     RESTful Service Module:  demo/
              URI Template:      test
                    Method:  POST
               Source Type:  PL/SQL
    and execution in sqldeveloper 3.2.20.09 when it connects directly to box B as scott:
     
    SET serveroutput ON
    DECLARE
      l_url      VARCHAR2(200)   :='http://MY_IP:8585//apex/wsdemo/demo/test';
      l_json     VARCHAR2(20000) := '{"title":"thetitle","description":"thedescription"}';
      l_response VARCHAR2(30000);
    BEGIN
      post( p_url => l_url, p_message =>l_json, p_response => l_response);
    END;
    leading to:
     
    status code: 500 
    reason phrase: Internal Server Error 
    
    Listener's log: 
    Request Path passes syntax validation
    Mapping request to database pool: PoolMap [_poolName=apex, _regex=null, _workspaceIdentifier=WSDEMO, _failed=false, _lastUpdate=1364313600000, _template=/wsdemo/, _type=BASE_PATH]
    Applied database connection info
    Attempting to process with PL/SQL Gateway
    Not processed as PL/SQL Gateway request
    Attempting to process as a RESTful Service
    demo/test matches: demo/test score: 0
    Choosing: oracle.dbtools.rt.resource.templates.jdbc.JDBCResourceTemplateDispatcher as current candidate with score: Score [handle=JDBCURITemplate [scopeId=null, templateId=2648625079503782|2797815111031405, uriTemplate=demo/test], score=0, scope=SecurityConfig [constraint=none, realm=NONE, logonConfig=LogonConfig [logonForm=null, logonFailed=null]], originsAllowed=[], corsEnabled=true]
    Determining if request can be dispatched as a Tenanted RESTful Service
    Request path has one path segment, continuing processing
    Tenant Principal already established, cannot dispatch
    Chose oracle.dbtools.rt.resource.templates.jdbc.JDBCResourceTemplateDispatcher as the final candidate with score: Score [handle=JDBCURITemplate [scopeId=null, templateId=2648625079503782|2797815111031405, uriTemplate=demo/test], score=0, scope=SecurityConfig [constraint=none, realm=NONE, logonConfig=LogonConfig [logonForm=null, logonFailed=null]], originsAllowed=[], corsEnabled=true] for: POST demo/test
    demo/test is a public resource
    Using generator: oracle.dbtools.rt.plsql.AnonymousBlockGenerator
    Performing JDBC request as: SCOTT
    Mar 28, 2013 1:29:28 PM oracle.dbtools.common.jdbc.JDBCCallImpl execute
    INFO: Error occurred during execution of: [CALL, begin
     insert into scott.json_demo values(/*in:title*/?,/*in:description*/?);
    end;, [title, in, class oracle.dbtools.common.stmt.UnknownParameterType], [description, in, class oracle.dbtools.common.stmt.UnknownParameterType]]with values: [thetitle, thedescription]
    Mar 28, 2013 1:29:28 PM oracle.dbtools.common.jdbc.JDBCCallImpl execute
    INFO: ORA-06550: line 1, column 6:
    PLS-00103: Encountered the symbol "" when expecting one of the following:
    
       begin case declare exit for goto if loop mod null pragma
       raise return select update while with <an identifier>
       <a double-quoted delimited-identifier> <a bind variable> <<
       close current delete fetch lock insert open rollback
       savepoint set sql execute commit forall merge pipe
    The symbol "" was ignored.
    ORA-06550: line 2, column 74:
    PLS-00103: Encountered the symbol "" when expecting one of the following:
    
       begin case declare end exception exit for goto if loop mod
       null pragma raise return select update while with
       <an identifier> <a double-quoted delimited-id
    
    java.sql.SQLException: ORA-06550: line 1, column 6:
    PLS-00103: Encountered the symbol "" when expecting one of the following:
    
       begin case declare exit for goto if loop mod null pragma
       raise return select update while with <an identifier>
       <a double-quoted delimited-identifier> <a bind variable> <<
       close current delete fetch lock insert open rollback
       savepoint set sql execute commit forall merge pipe
    The symbol "" was ignored.
    ORA-06550: line 2, column 74:
    PLS-00103: Encountered the symbol "" when expecting one of the following:
    
       begin case declare end exception exit for goto if loop mod
       null pragma raise return select update while with
       <an identifier> <a double-quoted delimited-id
    
            at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:447)
            at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
            at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879)
            at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:505)
            at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:223)
            at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
            at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:205)
            at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:1043)
            at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1336)
            at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3612)
            at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3713)
            at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4755)
            at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1378)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at oracle.ucp.jdbc.proxy.StatementProxyFactory.invoke(StatementProxyFactory.java:242)
            at oracle.ucp.jdbc.proxy.PreparedStatementProxyFactory.invoke(PreparedStatementProxyFactory.java:124)
            at oracle.ucp.jdbc.proxy.CallableStatementProxyFactory.invoke(CallableStatementProxyFactory.java:101)
            at $Proxy46.execute(Unknown Source)
            at oracle.dbtools.common.jdbc.JDBCCallImpl.execute(JDBCCallImpl.java:44)
            at oracle.dbtools.rt.plsql.AnonymousBlockGenerator.generate(AnonymousBlockGenerator.java:176)
            at oracle.dbtools.rt.resource.templates.v2.ResourceTemplatesDispatcher$HttpResourceGenerator.response(ResourceTemplatesDispatcher.java:309)
            at oracle.dbtools.rt.web.RequestDispatchers.dispatch(RequestDispatchers.java:88)
            at oracle.dbtools.rt.web.HttpEndpointBase.restfulServices(HttpEndpointBase.java:412)
            at oracle.dbtools.rt.web.HttpEndpointBase.service(HttpEndpointBase.java:162)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
            at com.sun.grizzly.http.servlet.ServletAdapter$FilterChainImpl.doFilter(ServletAdapter.java:1059)
            at com.sun.grizzly.http.servlet.ServletAdapter$FilterChainImpl.invokeFilterChain(ServletAdapter.java:999)
            at com.sun.grizzly.http.servlet.ServletAdapter.doService(ServletAdapter.java:434)
            at oracle.dbtools.standalone.SecureServletAdapter.doService(SecureServletAdapter.java:65)
            at com.sun.grizzly.http.servlet.ServletAdapter.service(ServletAdapter.java:379)
            at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
            at com.sun.grizzly.tcp.http11.GrizzlyAdapterChain.service(GrizzlyAdapterChain.java:196)
            at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
            at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
            at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
            at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
            at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
            at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
            at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
            at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
            at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
            at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
            at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
            at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
            at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
            at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
            at java.lang.Thread.run(Thread.java:662)
    Error during evaluation of resource template: ORA-06550: line 1, column 6:
    PLS-00103: Encountered the symbol "" when expecting one of the following:
    
       begin case declare exit for goto if loop mod null pragma
       raise return select update while with <an identifier>
       <a double-quoted delimited-identifier> <a bind variable> <<
       close current delete fetch lock insert open rollback
       savepoint set sql execute commit forall merge pipe
    The symbol "" was ignored.
    ORA-06550: line 2, column 74:
    PLS-00103: Encountered the symbol "" when expecting one of the following:
    
       begin case declare end exception exit for goto if loop mod
       null pragma raise return select update while with
       <an identifier> <a double-quoted delimited-id
    Please notify.
    Concerning
    Zack

    Zack.L wrote:
    Hi Andy,.

    Sorry, I forgot to post the Source that is used by the AL1.1.4 and the AL2.0.1.

    Source

    begin
    insert into scott.json_demo values(:title,:description);
    end;
    

    It is a failure during insertion?
    Yes, he failed in the insert using AL2.0.1.

    If the above statement produces the following error message:

    The symbol "" was ignored.
    ORA-06550: line 2, column 74:
    PLS-00103: Encountered the symbol "" when expecting one of the following:
    
    begin case declare end exception exit for goto if loop mod
    null pragma raise return select update while with
     
    

    That gives me to think that a character is not printable (notice how there is anything between the quotation marks - "") worked his way in your PL/SQL Manager. Note how the error is reported to correspond to a column 74 on line 2, line 2 of the block above has 58 characters, so a pure assumption somehow, there is extra space on line 2, which confuses the PL/SQL compiler, I suggest retype PL/SQL Manager manually and see if that solves the problem.

  • Insert twice using unique sql

    Hello
    I want to reach
    1 insert into t1 select col1, 'a', col2 from t2;
    2. Insert in 'b', t1 select col1, col2 from t2;

    using a single sql.

    Thank you...

    One may wonder, "why?"

    insert into t1
    select col1, 'a', col2 from t2
    union
    select col1, 'b', col2 from t2;
    

    or even

    insert into t1
    select col1, foo, col2
    from t2, (select 'a' foo from dual union select 'b' foo from dual)
    

    or (insert other ways here)

  • Columns to rows using PL/SQL?

    Hello


    With the help of Oracle 11 g R2. I have the following table:

    1 1 value11

    1 2 value12

    1 3 value13

    1 4 value14

    2 1 value21

    2 2 value22

    2 3 value23

    2 4 value24

    ... etc... several hundred lines

    What I would like, is to transform this table to:

    1 value11, value12, value13 value14

    2 value21 value22 value23 value24

    .. etc...

    Please notify.

    Kind regards

    M.R.

    Hello

    M.R. says:

    Sorry, here are the instructions to create the table and insert values:

    using Oracle 11 g R2

    CREATE TABLE MyTable

    (

    row_nr INTEGER,

    col_nr INTEGER,

    string_val VARCHAR2 (500)

    );

    INSERT INTO myTable (row_nr, col_nr, string_val)

    VALUES (1, 1, value11);

    ...

    Do one of these specifications INSERT when judge you them?  Looks like you need single quotes around all string_vals, like this:

    INSERT INTO myTable (row_nr, col_nr, string_val)

    VALUES (1, 1, "value11");

    Since you're uisng Oracle 11.2, you can use SELECT... PIVOT, like this:

    SELECT *.

    FROM MyTable

    PIVOT (MIN (string_val)

    FOR col_nr IN (1 AS col_1

    2 UNDER col_2

    3 AS col_3

    4 AS col_4

    )

    )

    ORDER BY row_nr

    ;

  • Problems with Insert by using dynamic Sql

    Hello
    I use the following procedure to read a BLOB after download tab-delimited text files and insert the data in a table called TBL_TMP. The columns of the table are the following: T1, T2, T3, T4, T5, T6, T7, T8, T9. I have different text files.

    Some files could fill the table until the column T8 (v_data_array (8)) and others could fill the columns up to T9 (v_data_array (9)). So I try to change this procedure in order to take account of the text file that will fill in column T9 (v_data_array (9)) but the only thing is fails for text files that fill will alone up to T8.

    The error was: ORA-01403: no data found. I tried using NVL (v_data_array (9), 'NULL'), but it does not work. How the procedure can be modified to accept two text files containing data up to columns T8 and T9.

    Thanks in advance.
    CREATE OR REPLACE PROCEDURE pr_file_upload
      (name_in IN varchar2)
    IS
    v_blob_data       BLOB; --will hold the binary structure
    v_blob_len        NUMBER; --The length of the BLOB in bytes
    v_position        NUMBER; --Will store the current position of the pointer in the blob
    v_raw_chunk       RAW(10000); --Incremental raw chunks of the BLOB will be read in the loop
    v_char            CHAR(1); --Stores the current character of the BLOB
    c_chunk_len       NUMBER := 1; --Stores the current length of the raw chunks in bytes.
    v_line            VARCHAR2 (32767) := NULL;  --Stores the value of the current line in the loop
    v_data_array      wwv_flow_global.vc_arr2;  --apex array size of 32,000
    v_name_in         VARCHAR2 (50);
    BEGIN
    
    
    -- Read data from APEX_APPLICATION_FILES view in APEX
    SELECT blob_content INTO v_blob_data
    FROM APEX_APPLICATION_FILES WHERE filename = name_in;
    
    
    v_blob_len := dbms_lob.getlength(v_blob_data);
    v_position := 1;
    
    -- Read and convert binary to char
    WHILE ( v_position <= v_blob_len ) LOOP
     v_raw_chunk := dbms_lob.substr(v_blob_data,c_chunk_len,v_position);
     v_char :=  chr(fn_hex_to_decimal(rawtohex(v_raw_chunk)));
     v_line := v_line || v_char;
     v_position := v_position + c_chunk_len;
    -- When a whole line is retrieved
     IF v_char = CHR(10) THEN
    -- Convert tab CHR(9) to : to use wwv_flow_utilities
       v_line := REPLACE (v_line, CHR(9), ':');
    -- Convert each column separated by : into array of data
       v_data_array := wwv_flow_utilities.string_to_table (v_line);
    -- Insert data into target table
       EXECUTE IMMEDIATE 'insert into TBL_TMP (t1, t2, t3, t4, t5, t6, t7, t8, t9)
        values (:1,:2,:3,:4,:5,:6,:7,:8,:9)'
        USING
          v_data_array(1),
          v_data_array(2),
          v_data_array(3),
          v_data_array(4),
          v_data_array(5),
          v_data_array(6),
          v_data_array(7),
          v_data_array(8),
          NVL(v_data_array(9),'NULL');   -- Need help here.  This is empty when reading text files that fills up to column T8.
    
    
    -- Clear out
       v_line := NULL;
      END IF;
     END LOOP;
    END;
    /

    NVL (v_data_array (9), 'NULL') will not work. Use:

    CASE WHEN v_data_array.EXISTS(9) THEN v_data_array(9) END
    

    SY.

  • Inserting rows using MERGE?

    Hello

    I have a table with 3 columns
    ID SYSSKONTO SYSLS
    1 268 1
    2 270 1
    3 270 2

    I want to insert a new line every time I found a record where SYSLS = 1. I thought a MERGE statement would do but the insert can be done only if the match does not. What I tried

    Fusion
    in skontom t
    a_l'_aide_de)
    Select sysskonto,
    sysls
    of skontom
    where sysls = 1
    + 7
    on)
    u.sysskonto = t.sysskonto
    and
    u.sysls = t.sysls
    )
    when matched
    then insert (sysskontom, sysskonto, sysls)
    values (cic.skontom_seq.nextval, u.sysskonto, 11)

    is not working, but I have no idea to change it to "no match."

    Probably, I think to complicated, so any ideas to solve the task are appreciated.

    Thank you
    Carsten

    Hello

    Is this fair?

    INSERT INTO skontom (sysskontom, sysskonto, sysls)
    SELECT cic.skontom_seq.nextval, sysskonto, 11
    FROM skontom
    WHERE sysls = 1
    ;
    
  • Insert by using question FORALL

    Hi all, I'm trying to insert many rows using batch - FORALL mode... But when I run the following:

    declare 
    cursor C1 is select
               GL_CODE_COMBINATIONS_S.NEXTVAL
              ,ACCOUNT_TYPE
              ,s1,s2,s3,s4,s5,s6,s7 from XX_CC_SEGMENTS;
    type T_C1 is table of C1%ROWTYPE;
    rec1 t_c1;
    
    begin
    open C1;
    LOOP
      FETCH C1 bulk collect into REC1;
        FORALL I in REC1.first..REC1.last
          insert into XX_GL_CC  values(REC1(I));
    exit when c1%notfound;
    end LOOP;
    close c1;
    end;
    I received the error message:
    ORA-06550: line 14, column 19:
    PL/SQL: ORA-00947: not enough values
    As I am new with BULK COLLECT & FORALL, I guess I can't refer to "REC1" like that. Any ideas what to change?

    Thanks in advance,
    Bahchevanov.

    1. you don't need the LOOP. COLLECTION in BULK retrieves all THE rows in one shot.
    2. because REC1 (I) is a record, you MUST NOT use parenthesis in the VALUES clause:

    SQL> declare
      2  cursor C1 is select
      3             * from emp;
      4  type T_C1 is table of C1%ROWTYPE;
      5  rec1 t_c1;
      6
      7  begin
      8  open C1;
      9    FETCH C1 bulk collect into REC1;
     10  close c1;
     11      FORALL I in REC1.first..REC1.last
     12        insert into emp1 values(REC1(I));
     13  end;
     14  /
          insert into emp1 values(REC1(I));
                      *
    ERROR at line 12:
    ORA-06550: line 12, column 19:
    PL/SQL: ORA-00947: not enough values
    ORA-06550: line 12, column 7:
    PL/SQL: SQL Statement ignored
    
    SQL> declare
      2  cursor C1 is select
      3             * from emp;
      4  type T_C1 is table of C1%ROWTYPE;
      5  rec1 t_c1;
      6
      7  begin
      8  open C1;
      9    FETCH C1 bulk collect into REC1;
     10  close c1;
     11      FORALL I in REC1.first..REC1.last
     12        insert into emp1 values REC1(I);
     13  end;
     14  /
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

  • Inserting rows through the procedure of database

    Hello!
    I have a small dilemma. I have to insert rows in the database through pl/sql procedure table. I can't use entity objects, because the insertion is very specific, so it must be done through the procedure of database.
    What is the workflow for my case? Use view object with transient attributes the right way? I have to show form insertion (with entries for the database parameters), and then call my procedure to fill the db table. Where can I find more information on that? Everyone had similar cases? Any info?
    Best regards, Marko

    [Url http://download.oracle.com/docs/cd/E21764_01/web.1111/b31974/bcadveo.htm#sm0328] does help?

    John

  • How to create insert statements in the SQL Developer client

    Hi all

    A toad, we can create instructions for insertion of data in the table by clicking with the right button on the table and selecting create insert Stmts. But I am new customer SQL Developer. Could you please let me know how to do that in SQL Developer. I would be grateful if someone posts a link to the manual of the SQL Developer (how to use SQL Developer).

    Thank you.
    SQL> create table staging(x int, y varchar2(3));
    
    Table created.
    
    SQL> create table base(x int, y varchar2(3));
    
    Table created.
    
    SQL>
    SQL> insert into staging values(1,'ABC');
    
    1 row created.
    
    SQL> insert into staging values (2,'DEF');
    
    1 row created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> select * from staging;
    
             X Y
    ---------- ---
             1 ABC
             2 DEF
    
    SQL> select * from base;
    
    no rows selected
    
    SQL>
    SQL> insert into base
      2  select * from staging;
    
    2 rows created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> truncate table staging;
    
    Table truncated.
    
    SQL>
    SQL> select * from staging;
    
    no rows selected
    
    SQL> select * from base;
    
             X Y
    ---------- ---
             1 ABC
             2 DEF
    
    SQL>
    SQL> exit
    
  • Load the data from a text file into a table using pl/sql

    Hi Experts,

    I want to load the data from a text file (sample1.txt) to a table using pl/sql

    I used the pl/sql code below

    ***********************************
    declare
    f utl_file.file_type;
    s varchar2 (200);
    c number: = 0;
    Start
    f: = utl_file.fopen('TRY','sample1.txt','R');
    loop
    UTL_FILE.get_line (f, s);
    insert into sampletable (a, b, c) values (s, s, s);
    c: = c + 1;
    end loop;
    exception
    When NO_DATA_FOUND then
    UTL_FILE.fclose (f);
    dbms_output.put_line('No. deles de lignes insérées: ' || c);
    end;

    ***************************************

    and my sample1.txt file looks like

    ***************************************
    1
    2
    3
    ***************************************

    Gets the data inserted, with way below

    Select * from sampletable;

    A, B AND C

    1-1-1
    2-2-2
    3 3 3

    I want that data to get inserted as

    A, B AND C

    1 2 3

    The text file I have is to have three lines, and the first value of each line should go to each column

    Help, please...

    Thank you
    declare
    f utl_file.file_type;
    s1 varchar2(200);
    s2 varchar2(200);
    s3 varchar2(200);
    c number := 0;
    begin
    f := utl_file.fopen('TRY','sample1.txt','R');
    utl_file.get_line(f,s1);
    utl_file.get_line(f,s2);
    utl_file.get_line(f,s3);
    insert into sampletable (a,b,c) values (s1,s2,s3);
    c := c + 1;
    utl_file.fclose(f);
    exception
    when NO_DATA_FOUND then
    if utl_file.is_open(f) then utl_file.fclose(f); ens if;
    dbms_output.put_line('No. of rows inserted : ' || c);
    end;
    

    SY.

  • Generate the insert statement using columns in view all_tab_cols

    I am trying to generate a dynamic insert statement using the columns of a table in the all_tab_cols view. If I do a select, I get the result as lines. How to convert the row of the columns so that I get something like this:
     INSERT INTO TABLE_NAME (COL1, COL2, COL3,COL4.....) 
    .

    Any help will be appreciated!

    This can give you a tip.

    SQL> ed
    Wrote file afiedt.buf
    
      1  with tab_col
      2  as
      3  (
      4  select i.table_name,
      5         column_name,
      6         row_number() over(partition by i.table_name order by table_name) rno
      7    from user_tab_cols i
      8  )
      9  select 'INSERT INTO '||table_name||' ('||ltrim(sys_connect_by_path(column_name, ','), ',')||')
     10    from tab_col
     11   where connect_by_isleaf = 1
     12   start with rno = 1
     13  connect by rno = prior rno+1
     14     and table_name = prior table_name
     15* and rownum<4
    SQL> /
    
    SQL_STATEMENT
    --------------------------------------------------------------------------------
    INSERT INTO A (MAKER,TYPE)
    INSERT INTO ADAM_TEST (ACCT,CODE)
    INSERT INTO AREA_TBL (AREA_ID,ORG_ID,CLUSTER_ID)
    INSERT INTO B (MAKER)
    INSERT INTO BONUS (ENAME)
    INSERT INTO CLUSTER_TBL (CLUSTER_ID)
    INSERT INTO COMPANY (MANUFACTURER)
    INSERT INTO COUNTRIES (COUNTRY_ID)
    
  • Add more than 2 lines for a select statement without inserting rows in the base table

    Hi all

    I have a below a simple select statement that is querying a table.

    Select * from STUDY_SCHED_INTERVAL_TEMP
    where STUDY_KEY = 1063;

    but here's the situation. As you can see its return 7 ranks. But I must add
    2 rows more... with everything else, default or what exist... except the adding more than 2 lines.
    I can't insert in the base table. I want my results to end incrementing by 2 days in
    measurement_date_Taken on 01-APR-09... so big measurement_date_taken expected to
    end at study_end_Date...



    IS IT STILL POSSIBLE WITHOUT INSERT ROWS IN THE TABLE AND PLAYIHY ALL AROUND WITH
    THE SELECT STATEMENT?

    Sorry if this is confusing... I'm on 10.2.0.3

    Published by: S2K on August 13, 2009 14:19

    Well, I don't know if this request is as beautiful as my lawn, but seems to work even when ;)
    I used the "simplified" version, but the principle should work for your table, S2K.
    As Frank has already pointed out (and I fell on it while clunging): simply select your already existing lines and union them with the 'missing documents', you calculate the number of days that you are "missing" based on the study_end_date:

    MHO%xe> alter session set nls_date_language='AMERICAN';
    
    Sessie is gewijzigd.
    
    Verstreken: 00:00:00.01
    MHO%xe> with t as ( -- generating your data here, simplified by me due to cat and lawn
      2  select 1063 study_key
      3  ,      to_date('01-MAR-09', 'dd-mon-rr') phase_start_date
      4  ,      to_date('02-MAR-09', 'dd-mon-rr') measurement_date_taken
      5  ,      to_date('01-APR-09', 'dd-mon-rr') study_end_date
      6  from dual union all
      7  select 1063, to_date('03-MAR-09', 'dd-mon-rr') , to_date('04-MAR-09', 'dd-mon-rr') , to_date('01-APR-09', 'dd-mon-rr') from dual union all
      8  select 1063, to_date('03-MAR-09', 'dd-mon-rr') , to_date('09-MAR-09', 'dd-mon-rr') , to_date('01-APR-09', 'dd-mon-rr') from dual union all
      9  select 1063, to_date('03-MAR-09', 'dd-mon-rr') , to_date('14-MAR-09', 'dd-mon-rr') , to_date('01-APR-09', 'dd-mon-rr') from dual union all
     10  select 1063, to_date('03-MAR-09', 'dd-mon-rr') , to_date('19-MAR-09', 'dd-mon-rr') , to_date('01-APR-09', 'dd-mon-rr') from dual union all
     11  select 1063, to_date('22-MAR-09', 'dd-mon-rr') , to_date('23-MAR-09', 'dd-mon-rr') , to_date('01-APR-09', 'dd-mon-rr') from dual union all
     12  select 1063, to_date('22-MAR-09', 'dd-mon-rr') , to_date('30-MAR-09', 'dd-mon-rr') , to_date('01-APR-09', 'dd-mon-rr') from dual
     13  ) -- actual query:
     14  select study_key
     15  ,      phase_start_date
     16  ,      measurement_date_taken
     17  ,      study_end_date
     18  from   t
     19  union all
     20  select study_key
     21  ,      phase_start_date
     22  ,      measurement_date_taken + level -- or rownum
     23  ,      study_end_date
     24  from ( select study_key
     25         ,      phase_start_date
     26         ,      measurement_date_taken
     27         ,      study_end_date
     28         ,      add_up
     29         from (
     30                select study_key
     31                ,      phase_start_date
     32                ,      measurement_date_taken
     33                ,      study_end_date
     34                ,      study_end_date - max(measurement_date_taken) over (partition by study_key
     35                                                                          order by measurement_date_taken ) add_up
     36                ,      lead(measurement_date_taken) over (partition by study_key
     37                                                          order by measurement_date_taken ) last_rec
     38                from   t
     39              )
     40         where last_rec is null
     41       )
     42  where rownum <= add_up
     43  connect by level <= add_up;
    
     STUDY_KEY PHASE_START_DATE    MEASUREMENT_DATE_TA STUDY_END_DATE
    ---------- ------------------- ------------------- -------------------
          1063 01-03-2009 00:00:00 02-03-2009 00:00:00 01-04-2009 00:00:00
          1063 03-03-2009 00:00:00 04-03-2009 00:00:00 01-04-2009 00:00:00
          1063 03-03-2009 00:00:00 09-03-2009 00:00:00 01-04-2009 00:00:00
          1063 03-03-2009 00:00:00 14-03-2009 00:00:00 01-04-2009 00:00:00
          1063 03-03-2009 00:00:00 19-03-2009 00:00:00 01-04-2009 00:00:00
          1063 22-03-2009 00:00:00 23-03-2009 00:00:00 01-04-2009 00:00:00
          1063 22-03-2009 00:00:00 30-03-2009 00:00:00 01-04-2009 00:00:00
          1063 22-03-2009 00:00:00 31-03-2009 00:00:00 01-04-2009 00:00:00
          1063 22-03-2009 00:00:00 01-04-2009 00:00:00 01-04-2009 00:00:00
    
    9 rijen zijn geselecteerd.
    

    Is there a simpler way (in SQL), I hope that others join, and share their ideas/example/thoughts.
    I feel that it is using more resources there.
    But I have to cut the daisies before now, they interfere my 'grass-green-ess";)

  • Skip a page and print on the back using PL/SQL?

    Morning people,
    Greetings from Toronto. I have a report that was written in PL/SQL (not Oracle or SQL reports * most) and its job very well. The totals are correct and I have two sets of totals. A total for the Department in particular and, finally, a total of the entire company. The user of course wish the two totals for each same Department if he or she chooses to print only service (using a setting). So, it's not a problem.

    I just want to be the total final (company-wide) on the last page. Now, it is relatively simple in the reports of the Oracle, as well as SQL * more reports where I could probably use Skip. Y at - it a simple way to do or what I must count lines based on pagesize? So, for example, if the size of my page is 53 and my last record Department stops at line 35, I have to insert empty rows using UTF_FILE. Put_line in a FOR loop. This method would probably work ut I wonder if there's ways more interesting or easier to do?

    This issue does not have to decide at this moment and I know its Monday. :-) Any help would be appreciated.

    Concerning
    REDA

    Published by: Raj404261 on June 8, 2009 10:22

    Try:

        -- etc --
        UTL_FILE.FFLUSH (id);
        UTL_FILE.PUT_LINE(id,CHR(12));
        -- Write totals:
        -- etc --
    

    : p

  • How to insert rows in Board signout to recurring weekly entires

    I need help for create a simple procedure for lines inserted in the Council Signout database for entries "recurring weekly.
    The schema is SIGNOUT in the DEV10G database.
    There are three main tables: UKIMR, the REASONand SIGNOUT
    My first thought is that the procedure takes as arguments:
    -name, surname
    -first name
    -start date
    -number of weeks
    -the type of entry (for example, "telecommuting")
    -Comment
    Note: I use the name as args because that's how columns are configured in the UKIMR table.
    So all it would do is create entries on the same day-of-the-week as the * 'start date' * for as many weeks as you indicate in the * 'number of weeks' * argument.
    So this would be an example of calling script:_
    * exec STP_InsertWeekly ("Lastname", "firstname", October 3, 2008 ', 5, 'Teleworking', null);
    Which would insert 5 rows SIGNOUT for 5 Friday October.

    Published by: user4653174 on October 3, 2008 10:28

    Published by: user4653174 on October 3, 2008 10:29

    Published by: user4653174 on October 3, 2008 10:31

    user4653174 wrote:
    I want to see my procedure to insert rows in the table SIGNOUT. When I run that it is has the below error. The purpose of this procedure is for the employee to enter their name, the date they want to be turned off or work from home, or anything else, until they start, number of weeks (which will determine the number of rows will be inserted each week is a line), and comments that's what they do.

    Interaction with the customer as request for input values, is done in a client tool such as SQL * Plus or web applications. Not in PL/SQL. This just PL/SQL procedure accepts input parameters and can be called from a client application.

    The no data found error is due to a select... IN the statement, which fails to extract a single line. You must decide what you want your procedure to be done in this case. Ignore, not, one other message ease of use or...?

    And please paste formatted code using code tags. You have been told several times now, please the Act itself.

    Kind regards
    Rob.

  • find the most recent record inserted by using rowid

    Yes, I suspect that it is a bad idea!

    I work with an application that has been modelled incorrectly. a historical table of the status had been modeled with a primary key on a key of the company and the entry into force instead of the date of the end of the recording of the State. There is one status as possible at the same time.

    logic has been developed to insert new records of status with the dates of null terminator and then a trigger was provided that populated end dates except the one with the MAX (ROWID). so the hope is that ROWID will always get bigger.

    now, the database has been moved in environments of promotion using data pump. in our development environments, it always seems to work. but not in promotional customers environments.

    My question is: is there a setting associated with data pump that the client has used that does not respect the ROWID as it has in our development environment?

    I'm trying to determine if there is a way to continue to use the old code without immediately re-development.

    Thanks in advance for your comments.

    so the hope is that ROWID will always get bigger.

    It is an expectation that has no guarantee of being correct. He has a very good chance that a new line will have a lower value of the ROWID.

    My question is: is there a setting associated with data pump that the client has used that does not respect the ROWID as it has in our development environment?

    There is not this setting. Data pump just inserts rows into a table. Because we cannot guarantee that the next row will have a higher ROWID, then what you are looking for there is no.

    It is time to rethink this misguided approach.

    See you soon,.
    Brian

Maybe you are looking for

  • Using the function in Numbers ' 09

    I am trying to create a calendar in Numbers ' 09. My schedule has a number of steps that need to occur at specific intervals. For example, if the project starts at 09:00, the step 2a occur about 8 hours later. Step 3 should arrive 30 minutes after st

  • Satellite P105 - GPU overheating as fan does not work

    I brought a Satellite P105 - S9337 laptop computer around a year ago and it's been great, but I had a problem that began a few months ago. The GPU fan does not run under windows or any OS. It works correctly in the BIOS, but when I hit the operating

  • I have 2 different synchronization data

    OK, I have 2 different synchronization data, one on my mac on my pc they are totally different, they have different 2 story etc... I was wondering if I sync two devices on one account will be the second unsynchronized data mmain be changed to main? o

  • Satellite A215 no sound after upgrade to Vista o Win XP Pro

    Hi all I bought Toshiba notebook A215 series with Vista for 2 months. I have upgraded to Windows XP pro yesterday, everyhing looks ok but no sound. I checked the management of the material for the sound card, it seems normal. Someone knows this probl

  • To report a local name and the value to test.

    Hello! I have a local variable in MainSequence what name and value I want to include for the test report. How is that possible? ARO Jick