Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6664443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:36:40+00:00 2026-05-26T02:36:40+00:00

The following PL/SQL block works: DECLARE r TABLE1%ROWTYPE; BEGIN SELECT * INTO r FROM

  • 0

The following PL/SQL block works:

DECLARE
    r TABLE1%ROWTYPE;
BEGIN
    SELECT * INTO r FROM TABLE1 SAMPLE(1) WHERE ROWNUM = 1;
END;

However, when I try to replace the literal with a variable within the SAMPLE clause, Oracle returns a syntax error:

DECLARE
    s NUMBER;
    r TABLE1%ROWTYPE;
BEGIN
    s := 1;
    SELECT * INTO r FROM TABLE1 SAMPLE(s) WHERE ROWNUM = 1;
END;

ORA-06550: line 6, column 39:
PL/SQL: ORA-00933: SQL command not properly ended

What am I doing wrong?

I’m using Oracle 10 and SQL Developer.

(These are simplified examples. What I’m actually trying to do in practice is to optimize the selection of random row, where SAMPLE percentage would be calculated dynamically, based on the current number of rows in the table. So I can’t use literal, I need a variable to assign the result of the calculation.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:36:41+00:00Added an answer on May 26, 2026 at 2:36 am

    The SAMPLE synthax requires a numeral. You could use dynamic SQL to build a dynamic query, for example with a ref cursor:

    SQL> CREATE TABLE table1 AS
      2  SELECT ROWNUM ID, rpad(ROWNUM, 10, 'x') DATA 
      3    FROM dual CONNECT BY LEVEL <= 1000;
    
    Table created
    
    SQL> DECLARE
      2     l_cur SYS_REFCURSOR;
      3     l_row table1%ROWTYPE;
      4     l_pct NUMBER := 50;
      5  BEGIN
      6     OPEN l_cur
      7        FOR 'SELECT * FROM table1 SAMPLE('||l_pct||') WHERE rownum = 1';
      8     LOOP
      9        FETCH l_cur INTO l_row;
     10        EXIT WHEN l_cur%NOTFOUND;
     11        dbms_output.put_line(l_row.id);
     12     END LOOP;
     13  END;
     14  /
    
    3
    
    PL/SQL procedure successfully completed
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following SQL: SELECT notes + 'SomeText' FROM NotesTable a Give the error: The
The following SQL SELECT * FROM customers converted to this in LINQ var customers
I've got the following SQL: select * from transaction_log where stoptime like '%2008%' How
I have the following SQL-statement: SELECT DISTINCT name FROM log WHERE NOT name =
I have the following SQL query: select expr1, operator, expr2, count(*) as c from
I have a following SQL QUERY: SELECT articles.name, articles.price, users.zipcode FROM articles INNER JOIN
If I have the following SQL block (in SQL SERVER 2008 R2): BEGIN BEGIN
Hi How can I write the following sql query by linq Select * From
Consider the following SQL: BEGIN TRAN SET TRANSACTION ISOLATION LEVEL READ COMMITTED INSERT Bands
Would the following SQL statement automatically create an index on Table1.Table1Column, or must one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.