Create table in PL/SQL proc not working

Hello,
Here is a procedure I have tried to create & run in SQL Developer:
create or replace procedure transpose as
begin
create table lines as (select level line from dual connect by level <= 5),
create table cols as (select level col from dual connect by level <= 5),
select max(decode(col, 1,
decode(line, 1, line_id,
2, description,
3, statetax,
4, freight,
5, weightedAvg))) col1,
max(decode(col, 2,
decode(line, 1, line_id,
2, description,
3, statetax,
4, freight,
5, weightedAvg))) col2,
max(decode(col, 3,
decode(line, 1, line_id,
2, description,
3, statetax,
4, freight,
5, weightedAvg))) col3,
max(decode(col, 4,
decode(line, 1, line_id,
2, description,
3, statetax,
4, freight,
5, weightedAvg))) col4,
max(decode(col, 5,
decode(line, 1, line_id,
2, description,
3, statetax,
4, freight,
5, weightedAvg))) col5
from lines, cols,
(select rownum rn, tfe_line_info.* from tfe_line_info)
where rn = col
group by line
order by line;
end transpose;
I however get the error:
Error(3,7): PLS-00103: Encountered the symbol "CREATE" 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
I cannot understand what is wrong with my Create statement at line 3?

It looks like you have no PL/SQL experience. I suggest reading PL/SQL manual. Yes, single row select requires INTO clause. Multi-rows select requires cursor. But this is least of your problems. Your SPp will not complile even if you fix select. Why? SP creates tables dynamically at run time, so tables do not exist at SP compile time. Therefore select from these yet non-existent tables will not compile. By creating tables via dynamic SQL you forced yourself into querying them via dynamic SQL. Now you are trying to transpose (pivot) table. What Oracle version do you have? Oracle 11g provides PIVOT/UNPIVOT operators. Check them out before writing code.
SY.

Similar Messages

  • Error creating table on MS SQL Server with OC4J standalone

    Hi there,
    I'm trying to deploy an EJB application to OC4J standalone using a MS SQL Server 2000 database, MS SQL Server JDBC Drivers and OC4J 9.0.3 standalone but i keep getting this error:
    Auto-creating table: create table Functieprofiel_competentieNiveau_CompetentieNiveau_functieprofiel_LBOS_Ear_LBOS_Ejb (Functieprofiel_FUNCTIE_ID bigint identity not null, COMP_ID bigint identity null, NIVEAU_ID sql_variant(255) null)
    Error creating table: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Could not create IDENTITY attribute on nullable column 'COMP_ID', table 'Functieprofiel_competentieNiveau_CompetentieNiveau_functieprofiel_LBOS_Ear_LBOS_Ejb'.
    Deployment succeeds after this but the application does not run properly. Can anyone help me with this? I have no idea what to do.
    Rob Heikoop

    Rb -
    if you want to stop the auto-creation of tables, try going to the j2ee/home/config directory of your OC4J installation. Open the application.xml file and modify the attribute autocreate-tables to be set to false.
    That should stop the default table creation as a global property, unless you specifically override it at the specific deployed application level.
    You can then manually create the tables on the sql-server database instance. If you keep the column names the same as the field names in the bean, then you shouldn't need to do any manual mapping. To be sure of the column names to use, take a look in the orion-ejb-jar.xml which gets generated in the j2ee/home/application-deployments/<app-name>/<ejb-module-name> to see what table/column names the generator defaulted to
    -steve-
    -steve-

  • Sql is not working after changing from MsAccess into sql server

    Following Sql  is not working after changing from MsAccess into sql server. 
    sum(trn.sales) as sales,
    sum(trn.cost) as cost,
    sales - cost as profit // Here is not working . can we not use sales a column. Please advise
    from trn
    Kind Regards
    pol
    polachan

    It will not work if use two different column from the table or column  from two  different table
    Example
    sum(trn.sales * trn.rate) as salesAmount,
    sum(trn.cost) as cost,
    sum(trn.salesAmount)-sum(trn.cost) as profit ----- Here is not working . can we not use sales a column. Please advise
    from trn
    Regards
    polachan

  • What will you do if any SQL is not working.in oracle 10g...apps 11.5.10.2

    What will you do if any SQL is not working. in oracle 10g....apps 11.5.10.2

    928714 wrote:
    yes sir.If you help me in answering my questions i wll be very thankful to you sir.
    tnx,I haven't a clue.
    As you have been advised in many of your posts, go study the documentation for whichever specific topic you are interested in.
    For me to answer your questions, I would need to go get that documentation.
    Then I would need to read that documentation.
    Then I would need to write a forum post that interprets what I think I learned from that documentation.
    It is so very much faster if YOU go do that instead of posting to a forum and expecting others to do it. You will remember what you study for a lot longer time if you teach yourself.

  • Force encryption on SQL Server not working?

    Hello Everyone,
    I'm running SQL Server 2008 64-bit. I've installed a self-signed cert on the box and set  "Force Encryption"  and restarted SQL server. 
    I setup a client machine to trust the authority of the cert installed on the server. When I connect to that SQL server from SSMS from a client machine and select the "encrypt connection" option in the client Connection properties, SSMS correctly complains
    that the cert on the server does not match the computer name I asked to log into . This is because, although the cert is trusted, the dns name dos not match the CN in the cert <- Perfect, exactly what I am expecting.
    When I connect to the same SQL server from the same client but  UNCHECK "encrypt connection" on the client, I'm able to login. Considering I've checked the "Force Encryption" on the server, the server should have rejected the connection. Why not?
    Ameer Deen

    Hi all,
    We are implementing a Merge Synchronization solution which involves three SQL Servers located on three Azure locations worldwide and one on-premises location. We need to secure communications between all servers. We are evaluating the encryption of all server
    communications through SSL:
    http://technet.microsoft.com/en-us/library/ms191192.aspx
    When we configure one server (let’s call it server A) to accept only encrypted connections (with Force Encryption=Yes) we still can connect from other server (let’s call it server B) that do not have the certificate installed. We would expect the server
    B to fail in the attempt of connect as server A should only accept encrypted communications and those should need the certificated to encrypt/decrypt everything (commands and data).
    We have also review the following forum post that is very similar to this one:
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/bde679d9-ff83-4fa7-b402-42e336a97106/force-encryption-on-sql-server-not-working
    In all cases the Microsoft answer is:
    “When the
    Force Encryption option for the Database Engine is set to YES, all communications between client and server is encrypted no matter whether the “Encrypt
    connection” option (such as from SSMS) is checked or not. You can check it using the following DMV statement”
    When we run the provided DMV statement to check if encryption is enabled:
    -- To check whether connections are encrypted between server and clients
    SELECT encrypt_option
    FROM sys.dm_exec_connections
    We get “TRUE”. So theoretically encryption is enabled.
    Then:
    Why can we run SQL statements against server A from server B (with SSMS) without any certificate?
    Are we wrong when we expect server A to refuse any client that do not have the right certificate?
    How can server B, without any certificate, decrypt the data encrypted by server A?
    Our intention is to encrypt all server in the same way so all of them will accept only encrypted communications. We are assuming that the Merge Agent will be able to communicate with the Publisher and the Subscriber through this encrypted environment. May
    anyone please confirm ti?
    Thanks for your help.
    Best Regards
    Benjamin Moles

  • [svn] 4226: Bug: LCDS-517 - Reliable messaging destinations created using runtime configuration (bootstrap service) not working.

    Revision: 4226<br />Author:   [email protected]<br />Date:     2008-12-03 15:25:17 -0800 (Wed, 03 Dec 2008)<br /><br />Log Message:<br />-----------<br />Bug: LCDS-517 - Reliable messaging destinations created using runtime configuration (bootstrap service) not working. <br />QA: Yes<br />Doc: No<br />Checkintests Pass: Yes<br /><br />Details:<br />* Make sure the <reliable/> option is treated as a nested element rather than an attribute of its parent <network> element.<br /><br />Ticket Links:<br />------------<br />    http://bugs.adobe.com/jira/browse/LCDS-517<br /><br />Modified Paths:<br />--------------<br />    blazeds/trunk/modules/core/src/flex/messaging/Destination.java

    Revision: 4226<br />Author:   [email protected]<br />Date:     2008-12-03 15:25:17 -0800 (Wed, 03 Dec 2008)<br /><br />Log Message:<br />-----------<br />Bug: LCDS-517 - Reliable messaging destinations created using runtime configuration (bootstrap service) not working. <br />QA: Yes<br />Doc: No<br />Checkintests Pass: Yes<br /><br />Details:<br />* Make sure the <reliable/> option is treated as a nested element rather than an attribute of its parent <network> element.<br /><br />Ticket Links:<br />------------<br />    http://bugs.adobe.com/jira/browse/LCDS-517<br /><br />Modified Paths:<br />--------------<br />    blazeds/trunk/modules/core/src/flex/messaging/Destination.java

  • [svn] 4195: Bug: LCDS-517 - Reliable messaging destinations created using runtime configuration (bootstrap service) not working.

    Revision: 4195
    Author: [email protected]
    Date: 2008-11-26 13:08:23 -0800 (Wed, 26 Nov 2008)
    Log Message:
    Bug: LCDS-517 - Reliable messaging destinations created using runtime configuration (bootstrap service) not working.
    QA: Yes
    Doc: No
    Checkintests Pass: Yes
    Ticket Links:
    http://bugs.adobe.com/jira/browse/LCDS-517
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/rpc/src/mx/messaging/config/ServerConfig.as

    Revision: 4195
    Author: [email protected]
    Date: 2008-11-26 13:08:23 -0800 (Wed, 26 Nov 2008)
    Log Message:
    Bug: LCDS-517 - Reliable messaging destinations created using runtime configuration (bootstrap service) not working.
    QA: Yes
    Doc: No
    Checkintests Pass: Yes
    Ticket Links:
    http://bugs.adobe.com/jira/browse/LCDS-517
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/rpc/src/mx/messaging/config/ServerConfig.as

  • [svn] 4193: Bug: LCDS-517 - Reliable messaging destinations created using runtime configuration (bootstrap service) not working.

    Revision: 4193
    Author: [email protected]
    Date: 2008-11-26 11:40:05 -0800 (Wed, 26 Nov 2008)
    Log Message:
    Bug: LCDS-517 - Reliable messaging destinations created using runtime configuration (bootstrap service) not working.
    QA: Yes
    Doc: No
    Checkintests Pass: Yes
    Details:
    * Foundational update to include destination config in what we collect for runtime config exchange with new clients for destinations with network/reliable=true (LCDS only).
    * Also typo in comment in AbstractConnectionAwareSession fixed.
    Ticket Links:
    http://bugs.adobe.com/jira/browse/LCDS-517
    Modified Paths:
    blazeds/trunk/modules/core/src/flex/messaging/AbstractConnectionAwareSession.java
    blazeds/trunk/modules/core/src/flex/messaging/Destination.java
    blazeds/trunk/modules/core/src/flex/messaging/services/AbstractService.java

    Revision: 4193
    Author: [email protected]
    Date: 2008-11-26 11:40:05 -0800 (Wed, 26 Nov 2008)
    Log Message:
    Bug: LCDS-517 - Reliable messaging destinations created using runtime configuration (bootstrap service) not working.
    QA: Yes
    Doc: No
    Checkintests Pass: Yes
    Details:
    * Foundational update to include destination config in what we collect for runtime config exchange with new clients for destinations with network/reliable=true (LCDS only).
    * Also typo in comment in AbstractConnectionAwareSession fixed.
    Ticket Links:
    http://bugs.adobe.com/jira/browse/LCDS-517
    Modified Paths:
    blazeds/trunk/modules/core/src/flex/messaging/AbstractConnectionAwareSession.java
    blazeds/trunk/modules/core/src/flex/messaging/Destination.java
    blazeds/trunk/modules/core/src/flex/messaging/services/AbstractService.java

  • Using EXECUTE IMMEDIATE with Create Table SQL Statement not working

    Hi ,
    I am all the privileges given from the SYSTEM user , but still i am not able to create a table under procedure . Please see these and advice.
    create or replace procedure sp_dummy as
    begin
    Execute Immediate 'Create table Dummy99_99 (Dummy_Field number)';
    end;
    even i tried this way also
    create or replace PROCEDURE clearing_Practise(p_file_id in varchar2, p_country in VARCHAR2,p_mapId in VARCHAR2)
    AUTHID CURRENT_USER AS
    strStatusCode VARCHAR2(6);
    BEGIN
    EXECUTE IMMEDIATE 'create table bonus(name varchar2(50))';
    commit;
    EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line('ERROR Creating Table');
    END ;

    William Robertson wrote:
    Since the syntax is correct, my guess is you do not have CREATE TABLE system privilege granted directly to your account. A common scenario is that you have this privilege granted indirectly via a role, allowing you to create tables on the command line, but stored PL/SQL is stricter and requires a direct grant and therefore the procedure fails with 'insufficient privileges'.A bit like he's already been told on his first thread...
    Using of Execute Immediate in Oracle PLSQL
    Generally you would not create tables from stored PL/SQL. Also as you have found out, it's best not to hide exceptions with 'WHEN OTHERS THEN [some message which gives less detail than the one generated by Oracle]'.Again like he was told on the other thread.
    There's just no telling some people eh! :)

  • SQL Logging not working in SSIS 2008

    Hello,
    I have packages created in SSIS 2008 and I am trying to enable logging in them. I specified a SQL Server provider and gave it a working SQL Server DB connection as the configuration. I chose to log all the events from the Details tab, then I executed the package. It ran without errors, but no logging occured. Actually neither the logging table, nor the stored procedure that should perform the loggign were created. These exact steps used to work with SSIS 2005 and they'd generate the table, stored proc and start storing logging information. For testing, I also added to the same package logging options a text logging and a SQL Profiler log providers. These were created successfully and have logs entered in them. I tried different DB connections on different servers, but still the table and sp are not even getting created. Any ideas?
    Best Regards,
    Ketara

    Had the same problem. When I read the documentation Microsoft explicitly states that you must use an OLEDB provider for SQL Server logging. I checked, and mine was the "SQL Server Native Client" rather than the "Microsoft OLE DB Provider for
    SQL Server". When I switched out the driver, it worked. 
    The log table is under System Tables called: dbo.sysssislog
    The stored procedure that populates the table is under System Stored Procedures called: dbo.sp_ssis_addlogentry

  • Temporary Table In SAP Query - Does not Work?

    DECLARE @date DATE
    DECLARE @delrows INT
    DECLARE @delquan INT
    DECLARE @a INT
    DECLARE @recrows INT
    DECLARE @recquan INT
    SET @a=0
    IF OBJECT_ID('tempdb..##tab) IS NOT NULL DROP TABLE ##tab
    CREATE TABLE ##tab
    [Date] date,
    [Delivery Rows] varchar(40),
    [Delivery Total Units] varchar(40),
    [Receipts Rows] varchar(40),
    [Receipts Total Units] varchar(40),
    WHILE @a!=7
         BEGIN
         SET @date=DATEADD(day,-@a, getdate())
         SELECT @delrows=ISNULL(COUNT(DLN1.[LineNum]),0), @delquan=ISNULL(SUM(DLN1.[Quantity]),0)
         FROM ODLN
         INNER JOIN DLN1 ON ODLN.[DocEntry]=DLN1.[DocEntry]
         WHERE ODLN.[CreateDate] = @date
         SELECT @recrows=ISNULL(COUNT(PCH1.[LineNum]),0) , @recquan=ISNULL(SUM(PCH1.[Quantity]),0)
         FROM OPCH
         INNER JOIN PCH1 ON OPCH.[DocEntry]=PCH1.[DocEntry]
         WHERE OPCH.[DocDate]=@date
         SET @a=@a+1
              INSERT INTO ##tab VALUES(@date,@delrows,@delquan,@recrows,@recquan)
    END
    SELECT * FROM ##tab
    {/code}
    Can anyone explain why this query does not work in SAP? It works fine on SQL but gives me this message in SAP:
    1). [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near ')'.
    2). [Microsoft][SQL Server Native Client 10.0][SQL Server]Statement 'Service Contracts' (OCTR) (s) could not be prepared.
    Edited by: Chris Candido on Feb 2, 2011 8:38 PM

    Chris,
    There are several areas in your code which needed changes. 
    1. On the field name for your temp table you had spaces.
    2. The SAP table name ODLN, OPCH, PCH1 had to be fully referenced like
    [dbo].[ODLN]
    3. You really need not have ## in front of your temp table, it could just be #
    The select at the end is actually what causes the most problem as for some reason from within SAP it does not produce the result.  I would suggest you put the whole code into a Stored Procedure and call the SP from SAP.  Corrected SQL below.  If you remove the Select line at the end the query would work with in SAP, but keep it give give you an error. SP is the best option for this.
    DECLARE @date DATE
    DECLARE @delrows INT
    DECLARE @delquan INT
    DECLARE @a INT
    DECLARE @recrows INT
    DECLARE @recquan INT
    SET @a=0
    IF object_id('tempdb..#tab') IS NOT NULL
    BEGIN
       DROP TABLE #tab
    END
    CREATE TABLE #tab
    [Date] date,
    DeliveryRows varchar(40),
    DeliveryTotalUnits varchar(40),
    ReceiptsRows varchar(40),
    ReceiptsTotalUnits varchar(40),
    WHILE @a!=7
    BEGIN
    SET @date=DATEADD(day,-@a, getdate())
    SELECT @delrows=ISNULL(COUNT(DLN1.LineNum),0), @delquan=ISNULL(SUM(DLN1.Quantity),0)
    FROM [dbo].[ODLN]
    INNER JOIN DLN1 ON [dbo].[ODLN].DocEntry=DLN1.DocEntry
    WHERE [dbo].[ODLN].CreateDate = @date
    SELECT @recrows=ISNULL(COUNT([dbo].[PCH1].LineNum),0) , @recquan=ISNULL(SUM([dbo].[PCH1].Quantity),0)
    FROM [dbo].[OPCH]
    INNER JOIN [dbo].[PCH1] ON [dbo].[OPCH].DocEntry=[dbo].[PCH1].DocEntry
    WHERE [dbo].[OPCH].DocDate=@date
    SET @a=@a+1
    INSERT INTO #tab VALUES(@date,@delrows,@delquan,@recrows,@recquan)
    END
    SELECT * FROM #tab
    Suda Sampath

  • Sql  functions in Pl/Sql region not working

    Hi all,
    I have created a pl/sql region like this
    This is the example taken from denes kubicek
    DECLARE
       v_counter     INTEGER         := 0;
       v_line        VARCHAR2 (4000);
       v_rec_in_row  INTEGER         := 6;
    BEGIN
       HTP.prn ('<table>');
       HTP.prn ('<tr>');
       HTP.prn ('<td>');
       FOR c IN
          (SELECT CASE
                     WHEN LOWER(SUBSTR(SUBSTR(NAME,INSTR(NAME,'/')+1), -3, 3)) = 'doc'
                        THEN    '<table>'
                             || '<tr><td><img src="#WORKSPACE_IMAGES#user_green_locked.gif"/></td></tr>'
                             || '<tr><td style="text-align:center">'
                             || SUBSTR(NAME,INSTR(NAME,'/')+1)  name
                             || '</td></tr></table>'
                     WHEN LOWER(SUBSTR(SUBSTR(NAME,INSTR(NAME,'/')+1), -3, 3)) = 'xls'
                        THEN    '<table>'
                             || '<tr><td><img src="#WORKSPACE_IMAGES#user_yellow.gif"/></td></tr>'
                             || '<tr><td style="text-align:center">'
                             || SUBSTR(NAME,INSTR(NAME,'/')+1) name
                             || '</td></tr></table>'
                    WHEN LOWER(SUBSTR(SUBSTR(NAME,INSTR(NAME,'/')+1), -3, 3)) = 'ppt'
                        THEN    '<table>'
                             || '<tr><td><img src="#WORKSPACE_IMAGES#user_yellow.gif"/></td></tr>'
                             || '<tr><td style="text-align:center">'
                             || SUBSTR(NAME,INSTR(NAME,'/')+1) name
                             || '</td></tr></table>'
                   WHEN LOWER(SUBSTR(SUBSTR(NAME,INSTR(NAME,'/')+1), -3, 3)) = 'txt'
                        THEN    '<table>'
                             || '<tr><td><img src="#WORKSPACE_IMAGES#user_yellow.gif"/></td></tr>'
                             || '<tr><td style="text-align:center">'
                             || SUBSTR(NAME,INSTR(NAME,'/')+1) name
                             || '</td></tr></table>'
                   WHEN LOWER(SUBSTR(SUBSTR(NAME,INSTR(NAME,'/')+1), -3, 3)) = 'gif'
                        THEN    '<table>'
                             || '<tr><td><img src="#WORKSPACE_IMAGES#user_yellow.gif"/></td></tr>'
                             || '<tr><td style="text-align:center">'
                             || SUBSTR(NAME,INSTR(NAME,'/')+1) name
                             || '</td></tr></table>'
                     ELSE    '<table>'
                          || '<tr><td><img src="#WORKSPACE_IMAGES#user_red.gif"/></td></tr>'
                          || '<tr><td style="text-align:center">'
                          || SUBSTR(NAME,INSTR(NAME,'/')+1) name
                          || '</td></tr></table>'
                  END doc
             FROM con_doc_info)
       LOOP
          v_line := v_line || c.doc || '</td><td>';
          v_counter := v_counter + 1;
          IF v_counter = v_rec_in_row
          THEN
             HTP.prn (v_line);
             HTP.prn ('</td></tr><tr><td>');
             v_line := NULL;
             v_counter := 0;
          END IF;
       END LOOP;
       HTP.prn (v_line);
       HTP.prn ('</td></tr></table>');
    END;but the functions are not working?
    Any idea ? Please help me

    Hi fac
    Database version is 10g
    This sample code is working
    DECLARE
       v_counter     INTEGER         := 0;
       v_line        VARCHAR2 (4000);
       v_rec_in_row  INTEGER         := 6;
    BEGIN
       HTP.prn ('<table>');
       HTP.prn ('<tr>');
       HTP.prn ('<td>');
       FOR c IN
          (SELECT CASE
                     WHEN deptno = 20
                        THEN    '<table>'
                             || '<tr><td><img src="#WORKSPACE_IMAGES#user_green_locked.gif"/></td></tr>'
                             || '<tr><td style="text-align:center">'
                             || ename
                             || '</td></tr></table>'
                     WHEN deptno = 30
                        THEN    '<table>'
                             || '<tr><td><img src="#WORKSPACE_IMAGES#user_yellow.gif"/></td></tr>'
                             || '<tr><td style="text-align:center">'
                             || ename
                             || '</td></tr></table>'
                     ELSE    '<table>'
                          || '<tr><td><img src="#WORKSPACE_IMAGES#user_red.gif"/></td></tr>'
                          || '<tr><td style="text-align:center">'
                          || ename
                          || '</td></tr></table>'
                  END emp
             FROM emp)
       LOOP
          v_line := v_line || c.emp || '</td><td>';
          v_counter := v_counter + 1;
          IF v_counter = v_rec_in_row
          THEN
             HTP.prn (v_line);
             HTP.prn ('</td></tr><tr><td>');
             v_line := NULL;
             v_counter := 0;
          END IF;
       END LOOP;
       HTP.prn (v_line);
       HTP.prn ('</td></tr></table>');
    END;This code is working good images are displayed as per the deptno.
    I need to display images for the documents which i have uploaded and stored in a file
    I am taking the name and in that last three letters alone and according to that pictures should appear
    My previous code while running no output is there.
    Hope I am more clear now
    bye
    Srikavi

  • ERROR creating table with dynamic SQL :-(

    Hi friends,
    I have a problem when I try to create a table using dynamic SQL.
    (Env.: Forms 6i, WinXP, Oracle 9i)
    I only want to create a table, insert data and drop the table.
    I have a user with the correct privileges (At least ....I think so), because I can to make the three actions in SQL*PLUS (CREATE TABLE, INSERT .. and DROP TABLE).
    I want to do the same in Forms using dynamic SQL...
    I've made a package with 3 procedures:
    1st to create the table, 2nd to insert data , 3rd to drop the table.
    Only the 1st fails with the error ORA-01031 (insufficient privileges).
    Here it is:
    PROCEDURE PRO_DM_CreaTabla(pe_nombre_tabla VARCHAR2) IS
    id_cursor INTEGER;
    ls_sentencia VARCHAR2(500);
    v_dummy integer;
    BEGIN
    id_cursor := DBMS_SQL.OPEN_CURSOR;
    ls_sentencia := 'CREATE TABLE '||pe_nombre_tabla||' ( campo1 VARCHAR2(100), campo2 VARCHAR2(100), campo3 VARCHAR2(100),campo4 VARCHAR2(100))';
    DBMS_SQL.PARSE(id_cursor, ls_sentencia, dbms_sql.NATIVE);
    v_dummy := dbms_sql.execute(id_cursor);
    DBMS_SQL.CLOSE_CURSOR(id_cursor);
    END;
    The DROP_table procedure is exactly the same as this (with the difference of the 'CREATE' sentence, where I have a DROP sentence)... then.. why the DROP procedure works?... and.. why this CREATE procedure doesn't work?
    Any ideas?
    Thanks a lot.
    Jose.

    From a different thread, Jose wrote:
    V_INSERT:='INSERT INTO TMP_TABLE(field1,field3,field3,field4) VALUES (1,2,3,4)';
    Forms_DDL(V_INSERT);
    commit;First, try your statement in SQL Plus:
    INSERT INTO TMP_TABLE(field1,field3,field3,field4) VALUES (1,2,3,4);
    Then if that works, try doing this right after the Forms_DDL(V_INSERT);
    If not form_success then
      Message('   Insert has failed');
      Raise form_trigger_failure;
    Else
      Forms_DDL('COMMIT');
    End if;

  • SQL Statement not works using functions or subqueries-MAXDB

    Hello All,
    I created an ABAP program to select information about country(table: T005) with the country names (Table: T005T). I tried to create a sql query with a sql subquery to select everything but for some reason that I don't know it doesn't work. Please find the query below.
    DATA:
    resu        TYPE REF TO cl_sql_result_set ,
    stmt         TYPE REF TO cl_sql_statement ,
    qury        TYPE string .
               qury  = `SELECT land1, spras, `
               &&       `(SELECT landx `
               &&         `FROM SAPNSP.T005T `
               &&         `WHERE mandt = '` && sy-mandt && `' `
               &&           `AND spras = 'EN' `
               &&           `AND land1 = ? ), `
               &&       `(SELECT natio `
               &&         `FROM SAPNSP.T005T `
               &&         `WHERE mandt = '` && sy-mandt && `' `
               &&           `AND spras = 'EN' `
               &&           `AND land1 = ? ) `
               &&        `FROM SAPNSP.T005 `
               &&        `WHERE mandt = '` && sy-mandt && `' `
               &&          `AND land1 = ? `
               &&        `GROUP BY land1, spras` .
    resu = stmt->execute_query( qury ) .
    Well, the query above works but the fields LANDX and NATIO are in blank in ALL THE CASES, even with information registred in table T005T.
    So, exploring the SDN forum and after read some documents regarding ADBC, I create a function to handle this sql select and get the correctly the missing informations, but, still don't work. Please find the function below:
    CREATE FUNCTION select_landx (land1 CHAR(3)) RETURNS CHAR(15)
    AS
      VAR landx CHAR(15);
      DECLARE functionresult CURSOR FOR
      SELECT spras, land1, landx
         FROM SAPNSP.t005t
         WHERE spras = 'EN'
             AND land1 = :land1;
         IF $count IS NULL THEN <- | $count is always 0, my SELECT
           BEGIN                                 it's not work but I don't know why
             CLOSE functionresult;
             RETURN NULL;
           END
         ELSE
           SET $rc = 0;
           WHILE $rc = 0 DO
           BEGIN
             FETCH functionresult INTO :landx;
           END;
         CLOSE functionresult;
         RETURN landx;
    Calling the function in a SQL statement:
    DATA:
    resu        TYPE REF TO cl_sql_result_set ,
    stmt         TYPE REF TO cl_sql_statement ,
    qury        TYPE string .
               qury  = `SELECT land1, spras, select_landx(?) landx `
               &&        `FROM SAPNSP.T005 `
               &&        `WHERE mandt = '` && sy-mandt && `' `
               &&          `AND land1 = ? `
               &&        `GROUP BY land1, spras` .
    resu = stmt->execute_query( qury ) .
    Any comments ?
    Best regards,
    Arthur Silva

    Hello,
    Thank's a lot, it works. It's funny because the given solution works using only abap codes.
    It may be happens because the abap interpretor send the sql statement to the db interface that handle the code in the another way.
    Thanks again, it was driving me crazy.
    Best regards,
    Arthur Silva

  • Insert SQL does not work properly when called using CALL

    I have a stored procedure (TEST_SP) which is used to insert a record in this perticular case. The SQL statement is 2526 characters long. I'm using
    dim Params : Params=chr(1) & "Insert query" & Chr(1) & "=300"
    runsql=&"{call TEST_SP(?,?)}"&Params 
    dim db : db=dbSelect("",0,"","")
    dbExecSQL db,runsqlto execute the stored procedure. I'm facing an issue when the 2000th character on the insert SQL (pUPDSQL) is a single quote, where the SQL is not getting executed (i.e. record is not getting created).
    The same stored procedure and the same SQL when run as below
    runsql=runsql&"DECLARE "
    runsql=runsql&"PUPDSQL VARCHAR2(4000); "
    runsql=runsql&"PRES VARCHAR2(300); "
    runsql=runsql&"BEGIN "
    runsql=runsql&"PUPDSQL := 'INSERT query..."
    runsql=runsql&"PRES:=300; "
    runsql=runsql&"MRT_LKIDFULUP(PUPDSQL => PUPDSQL,PRES => PRES); "
    runsql=runsql&"END; "
    dim db : db=dbSelect("",0,"","")
    dbExecSQL db,runsqlis working fine. Does anyone know if there is a limitaion in ODBC Call function or any explanation to above behaviour? I'm connecting to a Oracle 11g database using Microsoft ODBC for Oracle driver on Window 7
    The stored procedures:
    create or replace procedure TEST_SP(pUPDSQL IN VARCHAR2,pRES OUT VARCHAR2)
    AS
    BEGIN
    DECLARE
      emsg VARCHAR2(100);
    BEGIN
    if pUPDSQL&lt;&gt;'-1' then
      emsg:='Cant exec UPDATE';
      EXECUTE IMMEDIATE pUPDSQL;
        if SQL%RowCount=0 then
        pRES:='ERR:No row updated';
        return;
      end if;
    end if;
    pRES:='OK:';
    EXCEPTION
      WHEN OTHERS THEN
       pRES:='ERR:' || emsg;
    END;
    END;Edited by: BluShadow on 11-Dec-2012 15:47
    added {noformat}{noformat} tags for readability.  Please read {message:id=9360002} and learn to do this yourself in future.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    ... I'm facing an issue when the 2000th character on the insert SQL (pUPDSQL) is a single quote, ...Perhaps you need two single quotes? like:
    runsql=runsql&"PUPDSQL := 'INSERT query...Values(..,..,,,''This value in two single quotes'',..,...)' "
    ... I'm connecting to a Oracle 11g database using Microsoft ODBC ...Dump windoze ODBC and better use the Oracle client ODBC.
    :p

Maybe you are looking for

  • Can remove agentless managed sql instances from machines that no longer exist

    We have a couple of clustered sql servers that are no longer powered on. They had several sql instances on them. We are not able to remove the sql servers from SCOM 2012 SP1 because they have agent less managed devices (the sql instances) We can remo

  • Macbook air stream on tv via apple tv

    Hello, I have an apple macbook air and apple tv. Does anybody know how to stream the view of the macbook to my tv via apple tv. With ipad and iphone this is possible. Thanks a lot in advance

  • Synchronize Clips not working anymore

    This seemed to be working a few months ago, but no more. Recently I have been forwarding the files to the editor because I haven't been able to get my own FCPX to work (they use FCP 7). I have this new project that rather important but I need to get

  • Display full-screen controls NOT visible

    I exported my keynote presentation as a QuickTime full-screen movie. In Preferences, I have the controls checked to display full-screen controls and to never hide them. They do not show up anywhere. I also set the presentation as a slideshow to contr

  • I have runtime error  6034 message

    My Itunes has completely stopped working on both of my computers. I am running windows 7 with the latest updates. This happened over a week ago and I have not been able to back up my phone. I have tried to uninstall as instructed on other sections of