Equivalent of pl/sql for a tsql

Can somebody post me the the equivalent of pl/sql for the below Tsql (Microsoft SQl Server)
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
SET ANSI_PADDING OFF
GO
CREATE TABLE [Localizations] (
[pk] int NOT NULL IDENTITY(1, 1),
[ResourceId] nvarchar(512) NOT NULL,
[Value] ntext NOT NULL,
[LocaleId] varchar(5) NOT NULL,
[ResourceSet] nvarchar(512) NOT NULL,
[Type] nvarchar(255) NOT NULL,
[BinFile] image NULL,
[TextFile] ntext NULL,
[Filename] nvarchar(128) NOT NULL
ON [PRIMARY]
GO
ALTER TABLE [Localizations]
ADD
CONSTRAINT [PK_Localizations]
PRIMARY KEY
([pk])
ON [PRIMARY]
GO
ALTER TABLE [Localizations]
ADD
CONSTRAINT [DF_Localizations_ControlId]
DEFAULT ('') FOR [ResourceId]
GO
ALTER TABLE [Localizations]
ADD
CONSTRAINT [DF_Localizations_Filename]
DEFAULT ('') FOR [Filename]
GO
ALTER TABLE [Localizations]
ADD
CONSTRAINT [DF_Localizations_LocaleId]
DEFAULT ('') FOR [LocaleId]
GO
ALTER TABLE [Localizations]
ADD
CONSTRAINT [DF_Localizations_PageId]
DEFAULT ('') FOR [ResourceSet]
GO
ALTER TABLE [Localizations]
ADD
CONSTRAINT [DF_Localizations_Text]
DEFAULT ('') FOR [Value]
GO
ALTER TABLE [Localizations]
ADD
CONSTRAINT [DF_Localizations_Type]
DEFAULT ('') FOR [Type]
GO
Edited by: user7722364 on Oct 19, 2009 8:18 AM

The "default '' "(or null) constraints are not required.
You need
- a sequence instead of the identity column
- a trigger to populate the sequence if it's not in the code
then it's pretty similar
- create table statement
- create pk (which you could do as part of the create table statement if you wish)
Whether you need NVARCHAR2 depends on your character set.

Similar Messages

  • Equivalent of MS Access First Function in SQL for Group By

    We previously had an Access database performing operations. We are now converting it over to SQL. There are queries in Access that use the "First" function to insert data, which I have not been able to find the equivalent to in SQL. Below is an
    example showing the data used, the SQL syntax and the results that it would produce.
    tbl_Data
    FirstN LastN CustNum TDate SalesPer
    Jim Smith 11111 5/10/2014 Jim Johnson
    Sally Jones 22222 5/12/2014 Alan Brown
    Sally Jones 22222 5/10/2014 Ben Doers
    Jim Smith 11111 5/12/2014 Jim Johnson
    Frank Oliver 33333 5/15/2014 Jim Johnson
    Results to be inserted into tbl_Main
    FName LName CustID TransDate SalesPerson
    Jim Smith 11111 5/10/2014 Jim Johnson
    Sally Jones 22222 5/10/2014 Ben Doers
    Frank Oliver 33333 5/15/2014 Jim Johnson
    Below is the SQL that will produce this
    INSERT INTO tbl_Main ( FName, LName, CustID, TransDate, SalesPerson)
    SELECT td.FirstN, td.LastN, td.CustNum, First(td.TDate) As SellDate, First(td.SalesPer) As SP
    FROM tbl_Data td
    GROUP BY td.FirstN, td.LastN, td.Cust;
    If anyone could assist me in an alternative that I could use in SQL to yield the same results, I'd appreciate it.

    tbl_Data
    FirstN LastN CustNum TDate SalesPer
    Jim Smith 11111 5/10/2014 Jim Johnson
    Sally Jones 22222 5/12/2014 Alan Brown
    Sally Jones 22222 5/10/2014 Ben Doers
    Jim Smith 11111 5/12/2014 Jim Johnson
    Frank Oliver 33333 5/15/2014 Jim Johnson
    Results to be inserted into tbl_Main
    FName LName CustID TransDate SalesPerson
    Jim Smith 11111 5/10/2014 Jim Johnson
    Sally Jones 22222 5/10/2014 Ben Doers
    Frank Oliver 33333 5/15/2014 Jim Johnson
    Below is the SQL that will produce this
    INSERT INTO tbl_Main ( FName, LName, CustID, TransDate, SalesPerson)
    SELECT td.FirstN, td.LastN, td.CustNum, First(td.TDate) As SellDate, First(td.SalesPer) As SP
    FROM tbl_Data td
    GROUP BY td.FirstN, td.LastN, td.Cust;
    As an aside that query is not correct in Access -  because you did not specify an ORDER BY the resultset has no particular order so you could get either row for Jim or Sally.
    It's a bit of a tricky one as it may on the surface appear that the resultset is always returned in a consistent order but this is not guaranteed (not in Access and certainly not in SQL server)

  • Is there an equivalent statement in Java for this PL/SQL stmt?

    Hi,
    I want to know if there is an equivalent statement
    in java for this PL/SQL statement:
    IF strTok IN('COM-1','COM-2','COM-3') Then
    /* Do Something */
    End If;
    I tried using : // This is giving me errors..
    if (strTok.equals(("COM-1") || ("COM-2") || ("COM-3") ) )
    /* Do Something */
    The above Java code is giving me errors.
    Any Help to reduce the number of steps for comparison
    is appreciated.
    thanks in adv
    Sharath

    Something like
    if (strTok.equals("COM-1") ||
        strTok.equals("COM-2") ||
        strTok.equals("COM-3") )Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Equivalent datatype in Oracle for datetime of SQL Server

    Hello Everyone,
    I'm very much new to Oracle. I have been working with SQL Server since 3yrs. Currently I'm working with Oracle 11g.
    What is the equivalent datatype in oracle for datetime in sql server with which has the format YYYY-MM-DD HH:MM:SS?
    I tried with timestamp and date which didnt solve my prob.... Please help me in using the equivalent datatype for the format provided above...
    Regards,
    Bhanu Yalamanchi.

    Oracle date format can be anything you want, either by default at the session level or preferably explicitly using to_char and a format mask.
    Format masks are documented here.
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/sql_elements004.htm#CDEHIFJA
    SQL> create table t (d date);
    Table created.
    SQL> insert into t values (sysdate);
    1 row created.
    SQL> select * from t;
    D
    19-JUL-11
    SQL> alter session set nls_date_format = 'YYYY-MM-DD HH:MI:SS';
    Session altered.
    SQL> select * from t;
    D
    2011-07-19 08:27:59
    SQL> select d, to_char(d, 'YYYY-MM-DD'), to_char(d,'Day') from t;
    D                   TO_CHAR(D, TO_CHAR(D
    2011-07-19 08:27:59 2011-07-19 Tuesday
    SQL> alter session set nls_date_format = 'DD-MON-YY';
    Session altered.
    SQL> select d, to_char(d, 'YYYY-MM-DD HH24:MI:SS') from t;
    D         TO_CHAR(D,'YYYY-MM-
    19-JUL-11 2011-07-19 08:27:59

  • Looking for the oracle equivalent of T-SQL 'SELECT TOP n'

    Hi,
    I'm looking for the Oracle equivalent of T-SQL 'SELECT TOP n'
    and can't find any. There is SAMPLE(n) function but it supposed
    to pick up random values and I'm not sure if it's possible to
    make it select top values. Please help 8-)
    Thanx

    Hi Marina.
    Oracle does not have a functionality like SQL Server for TOP
    selection. The ROWNUM option should be used with great care and
    you may get unreliable results.
    Try looking at Metalink
    Doc ID: 291065.999
    Doc ID: 267329.999
    - They discuss this issue, and solutions.

  • Equivalent of java.sql.ResultSetMetaData

    Hi,
    I'm looking for something which is equivalent to java.sql.ResultSetMetaData in Toplink. Does anyone know how this can be done ?
    Thanks,
    -Prashant

    Hi,
    I have a similar problem. I want to find out the column names when i fire raw-sql. I use SQLCall to do this.
    Then I get a Vector<DatabaseRow>.
    Vector vDR = session.executeQuery( new SQLCall( "select * from table_name" ) )
    Now Is there a way to find out the column names dynamically. In the javadocs i see that objDatabaseRow.keys() returns an Enum<DatabaseField>... but i cant see javadocs on how to use DatabaseField.
    So is there any other way ?
    Thanks,
    Krishna

  • ORA-01489 Received Generating SQL for Report Region

    I am new to Apex and I am running into an issue with an report region I am puzzled by. Just a foreword, I'm sure this hack solution will get a good share of facepalms and chuckles from those with far more experience. I welcome suggestions and criticism that are helpful and edifying!
    I am on Apex 4.0.2.00.07 running on 10g, I believe R2.
    A little background, my customer has asked an Excel spreadsheet be converted into a database application. As part of the transition they would like an export from the database that is in the same format as the current spreadsheet. Because the column count in this export is dynmic based on the number of records in a specific table, I decided to create a temporary table for the export. The column names in this temp table are based on a "name" column from the same data table so I end up with columns named 'REC_NAME A', 'REC_NAME B', etc. (e.g. Alpha Record, Papa Record, Echo Record, X-Ray Record). The column count is currently ~350 for the spreadsheet version.
    Because the column count is so large and the column names are dynamic I've run into a host of challenges and errors creating this export. I am a contractor in a corporate environmentm, so making changes to the apex environment or installation is beyond my influence and really beyond what could be justified by this single requirement for this project. I have tried procedures and apex plug-ins for generating the file however the UTL_FILE package is not available to me. I am currently generating the SQL for the query in a function and returning it to the report region in a single column (the user will be doing a text-to-column conversion later). The data is successfully being generated, however, the sql for the headers is where I am stumped.
    At first I thought it was because I returned both queries as one and they were joined with a 'union all'. However, after looking closer, the SQL being returned for the headers is about +10K+ characters long. The SQL being returned for the data is about +14k+. As mentioned above, the data is being generated and exported, however when I generate the SQL for the headers I am receiving a report error with "ORA-01489: result of string concatenation is too long" in the file. I am puzzled why a shorter string is generating this message. I took the function from both pages and ran them in a SQL command prompt and both return their string values without errors.
    I'm hopeful that it's something obvious and noobish that I'm overlooking.
    here is the code:
    data SQL function:
    declare
      l_tbl varchar2(20);
      l_ret varchar2(32767);
      l_c number := 0;
      l_dlim varchar2(3) := '''|''';
    begin
      l_tbl := 'EXPORT_STEP';
      l_ret := 'select ';
      for rec in (select column_name from user_tab_columns where table_name = l_tbl order by column_id)
      loop
        if l_c = 1 then
            l_ret := l_ret || '||' || l_dlim || '|| to_char("'||rec.column_name||'")';
        else
            l_c := 1;
            l_ret := l_ret || ' to_char("' || rec.column_name || '")';
        end if;
      end loop;
        l_ret := l_ret || ' from ' || l_tbl;
      dbms_output.put_line(l_ret);
    end;header sql function:
    declare
      l_tbl varchar2(20);
      l_ret varchar2(32767);
      l_c number := 0;
      l_dlim varchar2(3) := '''|''';
    begin
      l_tbl := 'EXPORT_STEP';
      for rec in (select column_name from user_tab_columns where table_name = l_tbl order by column_id)
      loop
        if l_c = 1 then
            l_ret := l_ret || '||' || l_dlim || '||'''||rec.column_name||'''';
        else
            l_c := 1;
            l_ret := l_ret || '''' || rec.column_name || '''';
        end if;
      end loop;
        l_ret := l_ret || ' from dual';
      dbms_output.put_line(l_ret);
    end;-------
    EDIT: just a comment on the complexity of this export, each record in the back-end table adds 12 columns to my export table. Those 12 columns are coming from 5 different tables and are the product of a set of functions calculating or looking up their values. This is export is really a pivot table based on the records in another table.
    Edited by: nimda xinu on Mar 8, 2013 1:28 PM

    Thank you, Denes, for looking into my issue. I appreciate your time!
    It is unfortunately a business requirement. My customer has required that the data we are migrating to this app from a spreadsheet be exported in the same format, albeit temporarily. I still must meet the requirement. I'm working around the 350 columns by dumping everything into a single column, which is working for the data, however, the headers export is throwing the 01489 error. I did run into the error you posted in your reply. I attempted to work around it with the clob type but eneded up running into my string concatentation error again.
    I'm open to any suggestions at this point given that I have the data. I'm so close because the data is exporting, but because the columns are dynamic, the export does me little good without the headers to go along with it.

  • Looking For Free Good Tutorial To Learn SQL For 8i

    Hello all,
    I am looking for a free good tutorial to learn SQL for Oracle 8i.
    If anyone got any links or resources, kindly suggest.
    Thanks in advance.

    I am looking for a free good tutorial to learn SQL for Oracle 8i.8i has been unsupported for years. If you're just starting out, you might as well learn the latest.

  • What is a efficient SQL for this query ?

    Hi,
    I am using 9.2 database. Suppose I am having following 2 tables
    Table p having only one column i.e. 'a'. Values in this column are
    a1
    b1
    c1
    d1
    Table Q having three columns a, b, c
    a1, 1, 100
    a1, 2, 50
    b1, 1, 30
    b1, 2, 40
    d1, 2, 90
    Table Q can be joined only using column a.
    Table Q can have multiple or no records for column a in table p. Based on above sample data, I want following output
    a1, 100, 50
    b1, 30, 40
    c1
    d1, 90
    Kindly tell be how can I achive this in most efiicient way !!!
    thanks & regards
    PJP

    I only have you two tracks about how do it.
    If you want all the columns from p with or wihout q you have to do:
    11:35:58 SQL> l
    1 select p.*, q.*
    2 from p,q
    3* where p.a = q.a (+)
    11:37:27 SQL> /
    For change the order of the colums for rows you can see the url, the are more examples like that only need to search "columns for rows" in this forums.
    Anyway:
    with rt as
    select 'a1' a, 1 b, 100 c from dual union
    select 'a1', 2, 50 from dual union
    select 'b1', 1, 30 from dual union
    select 'b1', 2, 40 from dual union
    select 'd1', 2, 90 from dual)
    --select * from rt
    select a, decode('1','0','0',rtrim(xmlagg(xmlelement(b, b || ',')).extract('//text()'),',')) b
    , decode('1','0','0',rtrim(xmlagg(xmlelement(c, c || ',')).extract('//text()'),','))
    from rt
    group by a
    Message was edited by:
    cth
    Other way:
    select a, ltrim(b,',') as b, ltrim(c,',') as c
    from (
    select row_number() over (partition by a order by length(b) desc) as rn, a, b,c
    from (select a, sys_connect_by_path(b, ',') as b,
              sys_connect_by_path(c, ',') as c
    from (
    select row_number() over (partition by a order by b) as rn, a, b,c
    from rt) y
    connect by rn = prior rn + 1 and prior a = a
    start with rn = 1
    where rn = 1
    Message was edited by:
    cth

  • BREAK not working in SQL+ for windows. Works in SQL+ in DOS

    I'm writing a simple query in SQL+
    SELECT table_name, column_name
    FROM user_tab_columns
    WHERE table_name like 'MYTAB%'I first set BREAK ON table_name
    then I run my query.
    I expect the table name to be shown once, per table, not once per column.
    If I run this query in SQL+ in a DOS window, that's exactly what happens.
    If I run the same thing in SQL+ for Windows (version 10 on an 11g db) the break command appears to be ignored.
    Any ideas ??
    Thanks folks.

    Not sure but maybe try the NODUPLICATES option.
    break on table_name noduplicates

  • Need help with SQL for Pie Chart

    I am trying to create a pie charge which would have 3 slices.
    Following sql gives me the expected values when I run the sql command:
    select
    round(avg(CATEGORY_1 + CATEGORY_2 + CATEGORY_3 + CATEGORY_4 + CATEGORY_5),0) "OD Engagements",
    round(avg(CATEGORY_6 + CATEGORY_7 + CATEGORY_13),0) "Talent Engagements",
    round(avg(CATEGORY_8 + CATEGORY_9 + CATEGORY_10 + CATEGORY_11 + CATEGORY_12),0) "Other Engagements"
    from OTD_PROJECT
    where STATUS in ('Open','Hold')
    I get 3 columns labeled: OD Engagements, Talent Engagements and Other Engagements with the correct averages based on the the data.
    I have tried several ways to try to get this to work in the SQL for a pie chart, but keep getting the invalid sql message and it won't save. I also tried saving without validation, but no data is shown on the chart at all.
    I want to have a pie, with 3 slices, one labeled OD Engagements with a value of 27, one labeled Talent Engagements with a value of 43 and one labeled Other Engagements with a value of 30. Then I want to be able to click on each pie slice to drill down to a secondary pie chart that shows the breakdown based on the categories included in that type.
    Since I am not grouping based on an existing field I an unsure what the link and label values should be in the chart sql.

    You'll need something like the below. I have no idea what the URL for the drilldown needs to be. It should create an appropriate link in your app for the particular slice. Mainly the code below breaks the SQL results into three rows rather than three columns. It may well have a syntax error since I can't test.
    select linkval  AS LINK,
           title    AS LABEL,
           calc_val AS VALUE
    FROM   (SELECT 'OD Engagements' AS title,
                   round(avg(CATEGORY_1 + CATEGORY_2 + CATEGORY_3 + CATEGORY_4 + CATEGORY_5),0) AS calc_val,
                   'f?p=???:???:' || v('APP_SESSION') || '::NO:?' AS LINKVAL
            from   OTD_PROJECT
            where  STATUS in ('Open','Hold')
            UNION ALL
            SELECT 'Talent Engagements' AS title,
                   round(avg(CATEGORY_6 + CATEGORY_7 + CATEGORY_13),0) AS calc_val,
                   'f?p=???:???:' || v('APP_SESSION') || '::NO:?' AS LINKVAL
            from   OTD_PROJECT
            where  STATUS in ('Open','Hold')
            UNION ALL
            SELECT 'Other Engagements' AS title,
                   round(avg(CATEGORY_8 + CATEGORY_9 + CATEGORY_10 + CATEGORY_11 + CATEGORY_12),0) AS calc_val,
                   'f?p=???:???:' || v('APP_SESSION') || '::NO:?' AS LINKVAL
            from   OTD_PROJECT
            where  STATUS in ('Open','Hold')
           );

  • Could we use embedded SQL for XML in .pc ?

    Hi,
    Can we use embedded SQL for XML in .pc ?
    <1> assume we have run SQL statements in Oracle9i:
    SQL>create table MY_XML_TABLE
    (Key1 NUMBER,
    Xml_Column SYS.XMLTYPE);
    SQL>insert into MY_XML_TABLE(key1, Xml_Column) values
    (1, SYS.XMLTYPE.CREATEXML
    ('<book>
    <chapter num="1">
    <text>This is the my text</text>
    </chapter>
    <book>')
    <2> Could we directly translate it in .pc as usually:
    <outlined, not exactly)
    int emp_number = 1;
    XML_Data emprec; /* ?????? */
    EXEC SQL SELECT M.Xml_Column.GETCLOBVAL() as XML_Data
    INTO :emprec INDICATOR :emprec_ind
    FROM MY_XML_TABLE M
    WHERE Key1 = :emp_number;
    Thanks
    MJ

    reply by myself.
    No problem!!
    ===============================
    int emp_number = 1;
    struct emprec{
    char feature[1280]
    EXEC SQL SELECT M.Xml_Column.GETCLOBVAL() as XML_Data
    INTO :emprec INDICATOR :emprec_ind
    FROM MY_XML_TABLE M
    WHERE Key1 = :emp_number;

  • Trying to find out the sql for the below 3 values

    HI Experts,
    I am trying to find the sql that can give me the values for the below three values. can some one Help me out getting these ?
    Free buffer waits (%)
    Local write wait (%)
    Latch: cache buffer chains (%)
    Actually these are the metrics which are available in OEM for the DB releases up to 9i. Post 9i releases , these metrics are obsoleted.
    So, trying to find the sql for these and use them as an UDM for the 10g and 11g DB's
    Thanks in Advance.
    Thanks,
    Naveen kumar.

    And is there any why to find using what sql the metrci is formed ?

  • Dynamic PL/SQL for Deletion of Records

    Dear all,
    I am using Dynamic PL/SQL for Deletion of Records,In that PL/SQL, i have to get the no.of records deleted and send a report with the no.of rows deleted.
    Please help me on this..
    Thanks,
    Murugesan

    Hi,
    Try this:
    SQL> SELECT * FROM T;
    DT              CODE
    14-FEB-07          1
    14-FEB-07          1
    14-FEB-07          1
    14-FEB-07          2
    14-FEB-07          2
    SQL>
    SQL> ed
    Wrote file afiedt.buf
      1  BEGIN
      2    EXECUTE IMMEDIATE  ' DELETE FROM T WHERE CODE = 1';
      3    DBMS_OUTPUT.PUT_LINE(' Total Deleted Rows :'||SQL%ROWCOUNT);
      4* END;
    SQL> /
    Total Deleted Rows :3
    PL/SQL procedure successfully completed.
    SQL> Regards
    Avinash

  • How to start checking the bottle necks in PL/SQL for benchmarking?

    How to start checking the bottle necks in PL/SQL for benchmarking? Can anbody post me the instructions to start tuning the Oracle PL/SQL code..
    Thanks & Regards,
    VJ

    you can use DBMS_PROFILER to do this. This built in package is very well documented:
    http://www.oracle.com/pls/db102/ranked?word=dbms_profiler&remark=federated_search
    Depending on your IDE, you could get a visual representation of the profile. Something like:
    http://technology.amis.nl/blog/2327/dbms_profiler-report-for-sql-developer

Maybe you are looking for